import {z} from 'zod' export type GetApiApiV1DatasetsDatasetIdFinetuneBestLaunchConfigArgs = {dataset_id: string}; export type GetApiApiV1DatasetsDatasetIdFinetuneBestLaunchConfigOptions = {baseUrl: string, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const datasetBestJobConfigDto = z.object({finetune_job_id: z.string(), training_experiment_id: z.string().nullable(), original_model_name: z.string().nullable(), trained_model_name: z.string().nullable(), training_method: z.enum(["sft", "dpo"]).nullable(), training_type: z.enum(["lora", "full"]).nullable(), data_format: z.enum(["chat", "instruction", "preference"]).nullable(), hyperparams: z.record(z.string(), z.unknown()).nullable()}); export const bestFinetuneLaunchConfigResponseDto = z.object({best_job_config: datasetBestJobConfigDto.nullable()}); 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 }; /** * Best fine-tune launch config for re-launch parity * * GET /api/v1/datasets/{dataset_id}/finetune/best-launch-config */ export const getApiApiV1DatasetsDatasetIdFinetuneBestLaunchConfig = async (args: GetApiApiV1DatasetsDatasetIdFinetuneBestLaunchConfigArgs, options: GetApiApiV1DatasetsDatasetIdFinetuneBestLaunchConfigOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/datasets/${encodeURIComponent(String(args.dataset_id))}/finetune/best-launch-config${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(bestFinetuneLaunchConfigResponseDto, await res.json()) };