/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { IntegrationObject, IntegrationObject$inboundSchema, IntegrationObject$Outbound, IntegrationObject$outboundSchema, } from "./integrationobject.js"; import { Method, Method$inboundSchema, Method$Outbound, Method$outboundSchema, } from "./method.js"; export type HyperparametersBatchSize = string | number; export type HyperparametersLearningRateMultiplier = string | number; export type HyperparametersNEpochs = string | number; export type Hyperparameters = { batchSize?: string | number | null | undefined; learningRateMultiplier?: string | number | null | undefined; nEpochs?: string | number | null | undefined; }; export type CreateFineTuningJobRequest = { /** * The base model to fine-tune */ model: string; /** * File ID of the training data JSONL file */ trainingFile: string; /** * File ID of the validation data JSONL file */ validationFile?: string | null | undefined; /** * Suffix appended to the fine-tuned model name */ suffix?: string | null | undefined; /** * Seed for reproducibility */ seed?: number | null | undefined; /** * Deprecated: use method instead */ hyperparameters?: Hyperparameters | null | undefined; /** * Fine-tuning method configuration */ method?: Method | null | undefined; /** * External integrations */ integrations?: Array | null | undefined; /** * Up to 16 key-value pairs */ metadata?: { [k: string]: string } | null | undefined; }; /** @internal */ export const HyperparametersBatchSize$inboundSchema: z.ZodType< HyperparametersBatchSize, z.ZodTypeDef, unknown > = z.union([z.string(), z.number().int()]); /** @internal */ export type HyperparametersBatchSize$Outbound = string | number; /** @internal */ export const HyperparametersBatchSize$outboundSchema: z.ZodType< HyperparametersBatchSize$Outbound, z.ZodTypeDef, HyperparametersBatchSize > = z.union([z.string(), z.number().int()]); export function hyperparametersBatchSizeToJSON( hyperparametersBatchSize: HyperparametersBatchSize, ): string { return JSON.stringify( HyperparametersBatchSize$outboundSchema.parse(hyperparametersBatchSize), ); } export function hyperparametersBatchSizeFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => HyperparametersBatchSize$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'HyperparametersBatchSize' from JSON`, ); } /** @internal */ export const HyperparametersLearningRateMultiplier$inboundSchema: z.ZodType< HyperparametersLearningRateMultiplier, z.ZodTypeDef, unknown > = z.union([z.string(), z.number()]); /** @internal */ export type HyperparametersLearningRateMultiplier$Outbound = string | number; /** @internal */ export const HyperparametersLearningRateMultiplier$outboundSchema: z.ZodType< HyperparametersLearningRateMultiplier$Outbound, z.ZodTypeDef, HyperparametersLearningRateMultiplier > = z.union([z.string(), z.number()]); export function hyperparametersLearningRateMultiplierToJSON( hyperparametersLearningRateMultiplier: HyperparametersLearningRateMultiplier, ): string { return JSON.stringify( HyperparametersLearningRateMultiplier$outboundSchema.parse( hyperparametersLearningRateMultiplier, ), ); } export function hyperparametersLearningRateMultiplierFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => HyperparametersLearningRateMultiplier$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'HyperparametersLearningRateMultiplier' from JSON`, ); } /** @internal */ export const HyperparametersNEpochs$inboundSchema: z.ZodType< HyperparametersNEpochs, z.ZodTypeDef, unknown > = z.union([z.string(), z.number().int()]); /** @internal */ export type HyperparametersNEpochs$Outbound = string | number; /** @internal */ export const HyperparametersNEpochs$outboundSchema: z.ZodType< HyperparametersNEpochs$Outbound, z.ZodTypeDef, HyperparametersNEpochs > = z.union([z.string(), z.number().int()]); export function hyperparametersNEpochsToJSON( hyperparametersNEpochs: HyperparametersNEpochs, ): string { return JSON.stringify( HyperparametersNEpochs$outboundSchema.parse(hyperparametersNEpochs), ); } export function hyperparametersNEpochsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => HyperparametersNEpochs$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'HyperparametersNEpochs' from JSON`, ); } /** @internal */ export const Hyperparameters$inboundSchema: z.ZodType< Hyperparameters, z.ZodTypeDef, unknown > = z.object({ batch_size: z.nullable(z.union([z.string(), z.number().int()])).optional(), learning_rate_multiplier: z.nullable(z.union([z.string(), z.number()])) .optional(), n_epochs: z.nullable(z.union([z.string(), z.number().int()])).optional(), }).transform((v) => { return remap$(v, { "batch_size": "batchSize", "learning_rate_multiplier": "learningRateMultiplier", "n_epochs": "nEpochs", }); }); /** @internal */ export type Hyperparameters$Outbound = { batch_size?: string | number | null | undefined; learning_rate_multiplier?: string | number | null | undefined; n_epochs?: string | number | null | undefined; }; /** @internal */ export const Hyperparameters$outboundSchema: z.ZodType< Hyperparameters$Outbound, z.ZodTypeDef, Hyperparameters > = z.object({ batchSize: z.nullable(z.union([z.string(), z.number().int()])).optional(), learningRateMultiplier: z.nullable(z.union([z.string(), z.number()])) .optional(), nEpochs: z.nullable(z.union([z.string(), z.number().int()])).optional(), }).transform((v) => { return remap$(v, { batchSize: "batch_size", learningRateMultiplier: "learning_rate_multiplier", nEpochs: "n_epochs", }); }); export function hyperparametersToJSON( hyperparameters: Hyperparameters, ): string { return JSON.stringify(Hyperparameters$outboundSchema.parse(hyperparameters)); } export function hyperparametersFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Hyperparameters$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Hyperparameters' from JSON`, ); } /** @internal */ export const CreateFineTuningJobRequest$inboundSchema: z.ZodType< CreateFineTuningJobRequest, z.ZodTypeDef, unknown > = z.object({ model: z.string(), training_file: z.string(), validation_file: z.nullable(z.string()).optional(), suffix: z.nullable(z.string()).optional(), seed: z.nullable(z.number().int()).optional(), hyperparameters: z.nullable(z.lazy(() => Hyperparameters$inboundSchema)) .optional(), method: z.nullable(Method$inboundSchema).optional(), integrations: z.nullable(z.array(IntegrationObject$inboundSchema)).optional(), metadata: z.nullable(z.record(z.string())).optional(), }).transform((v) => { return remap$(v, { "training_file": "trainingFile", "validation_file": "validationFile", }); }); /** @internal */ export type CreateFineTuningJobRequest$Outbound = { model: string; training_file: string; validation_file?: string | null | undefined; suffix?: string | null | undefined; seed?: number | null | undefined; hyperparameters?: Hyperparameters$Outbound | null | undefined; method?: Method$Outbound | null | undefined; integrations?: Array | null | undefined; metadata?: { [k: string]: string } | null | undefined; }; /** @internal */ export const CreateFineTuningJobRequest$outboundSchema: z.ZodType< CreateFineTuningJobRequest$Outbound, z.ZodTypeDef, CreateFineTuningJobRequest > = z.object({ model: z.string(), trainingFile: z.string(), validationFile: z.nullable(z.string()).optional(), suffix: z.nullable(z.string()).optional(), seed: z.nullable(z.number().int()).optional(), hyperparameters: z.nullable(z.lazy(() => Hyperparameters$outboundSchema)) .optional(), method: z.nullable(Method$outboundSchema).optional(), integrations: z.nullable(z.array(IntegrationObject$outboundSchema)) .optional(), metadata: z.nullable(z.record(z.string())).optional(), }).transform((v) => { return remap$(v, { trainingFile: "training_file", validationFile: "validation_file", }); }); export function createFineTuningJobRequestToJSON( createFineTuningJobRequest: CreateFineTuningJobRequest, ): string { return JSON.stringify( CreateFineTuningJobRequest$outboundSchema.parse(createFineTuningJobRequest), ); } export function createFineTuningJobRequestFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CreateFineTuningJobRequest$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateFineTuningJobRequest' from JSON`, ); }