import {z} from 'zod' export type TrainingShapeTrainerMode = 'TRAINER_MODE_UNSPECIFIED' | 'POLICY_TRAINER' | 'FORWARD_ONLY' | 'LORA_TRAINER'; export type GatewayTrainerShardingScheme = {tensorParallelism?: number | undefined, pipelineParallelism?: number | undefined, contextParallelism?: number | undefined, expertParallelism?: number | undefined, sequenceParallelism?: boolean | undefined}; export type GatewayAcceleratorType = 'ACCELERATOR_TYPE_UNSPECIFIED' | 'NVIDIA_A100_80GB' | 'NVIDIA_H100_80GB' | 'AMD_MI300X_192GB' | 'NVIDIA_A10G_24GB' | 'NVIDIA_A100_40GB' | 'NVIDIA_L4_24GB' | 'NVIDIA_H200_141GB' | 'NVIDIA_B200_180GB' | 'AMD_MI325X_256GB' | 'AMD_MI350X_288GB' | 'NVIDIA_B300_288GB' | 'NVIDIA_GB200' | 'NVIDIA_GB300'; export type GatewayWeightPrecision = 'WEIGHT_PRECISION_UNSPECIFIED' | 'BFLOAT16' | 'INT8' | 'NF4' | 'FP8' | 'FP4_FP8'; export type GatewayTrainingShape = {name?: string | undefined, displayName?: string | undefined, description?: string | undefined, createTime?: string | undefined, updateTime?: string | undefined, baseModel: string, deploymentShapeVersion?: string | undefined, trainerImageTag: string, trainerMode?: TrainingShapeTrainerMode | undefined, nodeCount?: number | undefined, trainerShardingScheme?: GatewayTrainerShardingScheme | undefined, modelType?: string | undefined, parameterCount?: unknown | undefined, acceleratorType?: GatewayAcceleratorType | undefined, acceleratorCount?: number | undefined, baseModelWeightPrecision?: GatewayWeightPrecision | undefined, maxSupportedContextLength?: number | undefined, minTotalAcceleratorCount?: number | undefined}; export type CreateApiV1AccountsAccountIdTrainingShapesArgs = {trainingShapeId?: string | undefined, account_id: string, body: GatewayTrainingShape}; export type CreateApiV1AccountsAccountIdTrainingShapesOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const trainingShapeTrainerMode = z.enum(["TRAINER_MODE_UNSPECIFIED", "POLICY_TRAINER", "FORWARD_ONLY", "LORA_TRAINER"]); export const gatewayTrainerShardingScheme = z.object({tensorParallelism: z.number().int().optional(), pipelineParallelism: z.number().int().optional(), contextParallelism: z.number().int().optional(), expertParallelism: z.number().int().optional(), sequenceParallelism: z.boolean().optional()}); export const gatewayAcceleratorType = z.enum(["ACCELERATOR_TYPE_UNSPECIFIED", "NVIDIA_A100_80GB", "NVIDIA_H100_80GB", "AMD_MI300X_192GB", "NVIDIA_A10G_24GB", "NVIDIA_A100_40GB", "NVIDIA_L4_24GB", "NVIDIA_H200_141GB", "NVIDIA_B200_180GB", "AMD_MI325X_256GB", "AMD_MI350X_288GB", "NVIDIA_B300_288GB", "NVIDIA_GB200", "NVIDIA_GB300"]); export const gatewayWeightPrecision = z.enum(["WEIGHT_PRECISION_UNSPECIFIED", "BFLOAT16", "INT8", "NF4", "FP8", "FP4_FP8"]); export const gatewayTrainingShape = z.object({name: z.string().optional(), displayName: z.string().optional(), description: z.string().optional(), createTime: z.string().optional(), updateTime: z.string().optional(), baseModel: z.string(), deploymentShapeVersion: z.string().optional(), trainerImageTag: z.string(), trainerMode: trainingShapeTrainerMode.optional(), nodeCount: z.number().int().optional(), trainerShardingScheme: gatewayTrainerShardingScheme.optional(), modelType: z.string().optional(), parameterCount: z.string().optional(), acceleratorType: gatewayAcceleratorType.optional(), acceleratorCount: z.number().int().optional(), baseModelWeightPrecision: gatewayWeightPrecision.optional(), maxSupportedContextLength: z.number().int().optional(), minTotalAcceleratorCount: z.number().int().optional()}); 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 }; /** * CRUD APIs for training shape. * Create Training Shape * * POST /v1/accounts/{account_id}/trainingShapes */ export const createApiV1AccountsAccountIdTrainingShapes = async (args: CreateApiV1AccountsAccountIdTrainingShapesArgs, options: CreateApiV1AccountsAccountIdTrainingShapesOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.trainingShapeId != null) query.append("trainingShapeId", String(args.trainingShapeId)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args.account_id))}/trainingShapes${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(gatewayTrainingShape, await res.json()) };