import {z} from 'zod' export type GetApiApiProjectIdTransferLearningModelsArgs = {projectId: number}; export type GetApiApiProjectIdTransferLearningModelsOptions = {baseUrl?: string | undefined, ApiKeyAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const kerasVisualLayerType = z.enum(["dense", "conv1d", "conv2d", "reshape", "flatten", "dropout", "batchNormalization", "transfer_mobilenetv2_a35", "transfer_mobilenetv2_a1", "transfer_mobilenetv2_a05", "transfer_mobilenetv2_160_a1", "transfer_mobilenetv2_160_a75", "transfer_mobilenetv2_160_a5", "transfer_mobilenetv2_160_a35", "transfer_mobilenetv1_a25_d100", "transfer_mobilenetv1_a2_d100", "transfer_mobilenetv1_a1_d100", "transfer_kws_mobilenetv1_a1_d100", "transfer_kws_mobilenetv2_a35_d100", "transfer_kws_syntiant_ndp10x", "transfer_kws_conv2d_tiny", "object_ssd_mobilenet_v2_fpnlite_320x320", "fomo_mobilenet_v2_a01", "fomo_mobilenet_v2_a35", "transfer_organization", "transfer_akidanet_imagenet_160_a100", "transfer_akidanet_imagenet_160_a50", "transfer_akidanet_imagenet_160_a25", "transfer_akidanet_imagenet_224_a100", "transfer_akidanet_imagenet_224_a50", "transfer_akidanet_imagenet_224_a25", "fomo_akidanet_a50", "fomo_ad_gmm", "fomo_ad_patchcore"]); export const learnBlockType = z.enum(["anomaly", "anomaly-gmm", "keras", "keras-transfer-image", "keras-transfer-kws", "keras-object-detection", "keras-regression", "keras-akida", "keras-akida-transfer-image", "keras-akida-object-detection", "keras-visual-anomaly", "keras-freeform", "keras-self-contained-freeform", "keras-anomaly", "vlm"]); export const blockType = z.enum(["official", "personal", "enterprise", "community"]); export const dSPGroupItem = z.object({name: z.string(), value: z.string().optional(), defaultValue: z.string(), type: z.string(), help: z.string().optional(), param: z.string(), selectOptions: z.array(z.object({value: z.string().optional(), selected: z.boolean().optional(), optionLabel: z.string().optional(), priority: z.number().optional(), romEstimate: z.number().optional(), needsOps: z.array(z.string()).optional(), needsFeatures: z.array(z.string()).optional()})).optional(), readonly: z.boolean(), shouldShow: z.boolean(), showIf: z.object({parameter: z.string(), operator: z.enum(["eq", "neq"]), value: z.string()}).optional(), invalidText: z.string().optional(), section: z.enum(["advanced", "augmentation", "modelProfiling"]).optional(), multiline: z.boolean().optional(), required: z.boolean(), hint: z.string().optional(), placeholder: z.string().optional(), showClickToSet: z.boolean(), valid: z.array(z.object({})).optional(), items: z.object({}).optional(), properties: z.object({}).optional(), minVal: z.number().optional(), maxVal: z.number().optional()}); export const blockDisplayCategory = z.enum(["classical", "tao", "developer-preview"]); export const transferLearningModel = z.object({name: z.string(), shortName: z.string(), abbreviatedName: z.string().optional(), description: z.string(), hasNeurons: z.boolean(), hasDropout: z.boolean(), defaultNeurons: z.number().int().optional(), defaultDropout: z.number().optional(), defaultLearningRate: z.number().optional(), defaultTrainingCycles: z.number().optional(), hasImageAugmentation: z.boolean().optional(), type: kerasVisualLayerType, learnBlockType: learnBlockType, organizationModelId: z.number().int().optional(), implementationVersion: z.number().int().optional(), repositoryUrl: z.string().optional(), customBlockRef: z.string().optional(), author: z.string(), blockType: blockType, customParameters: z.array(dSPGroupItem).optional(), displayCategory: blockDisplayCategory.optional(), blockNoLongerAvailable: z.object({reasonMarkdown: z.string(), reasonHtml: z.string()}).optional(), hasExpertMode: z.boolean()}); export const getAllTransferLearningModelsResponse = z.object({success: z.boolean(), error: z.string().optional(), transferLearningModels: z.array(transferLearningModel)}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get all transfer learning models * * GET /api/{projectId}/transfer-learning-models * * Also accepts auth: JWTAuthentication, JWTHttpHeaderAuthentication, OAuth2 */ export const getApiApiProjectIdTransferLearningModels = async (args: GetApiApiProjectIdTransferLearningModelsArgs, options?: GetApiApiProjectIdTransferLearningModelsOptions) => { const {baseUrl = "https://studio.edgeimpulse.com/v1", fetch: fetchFn = fetch, ApiKeyAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuthentication !== undefined) headers.set("x-api-key", ApiKeyAuthentication) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.projectId))}/transfer-learning-models${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getAllTransferLearningModelsResponse, await res.json()) };