import {z} from 'zod' export type SamplingParams = {max_tokens?: (number | null) | undefined, seed?: (number | null) | undefined, stop?: (string | Array | Array | null) | undefined, temperature?: number | undefined, top_k?: number | undefined, top_p?: number | undefined}; export type SampleBody = {checkpoint: string, num_samples?: number | undefined, prompt_logprobs?: boolean | undefined, prompt_tokens: Array, sampling_params?: SamplingParams | undefined, topk_prompt_logprobs?: number | undefined, topk_sample_logprobs?: number | undefined}; export type CreateApiV1TrainingJobsJobIdSampleArgs = {job_id: string, 'Idempotency-Key'?: (string | null) | undefined, body: SampleBody}; export type CreateApiV1TrainingJobsJobIdSampleOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const futureAccepted = z.object({future_id: z.string(), job_id: z.string(), type: z.string()}); 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 }; /** * Sample from an interactive training job * * POST /v1/training/jobs/{job_id}/sample * * Also accepts auth: BearerAuth */ export const createApiV1TrainingJobsJobIdSample = async (args: CreateApiV1TrainingJobsJobIdSampleArgs, options?: CreateApiV1TrainingJobsJobIdSampleOptions) => { const {baseUrl = "https://api.fastino.ai", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/training/jobs/${encodeURIComponent(String(args.job_id))}/sample${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(futureAccepted, await res.json()) };