import {z} from 'zod' export type GetApiV1RlTrainingSessionsSessionIdOperationsWeightsSyncOperationIdArgs = {session_id: string, operation_id: string}; export type GetApiV1RlTrainingSessionsSessionIdOperationsWeightsSyncOperationIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const rLTrainingOperationStatus = z.enum(["TRAINING_OPERATION_STATUS_UNSPECIFIED", "TRAINING_OPERATION_STATUS_PENDING", "TRAINING_OPERATION_STATUS_RUNNING", "TRAINING_OPERATION_STATUS_COMPLETED", "TRAINING_OPERATION_STATUS_FAILED"]); export const rLWeightsSyncResult = z.object({weights_version: z.union([z.string(), z.number().int()])}); export const rLTrainingOperationErrorCode = z.enum(["TRAINING_OPERATION_ERROR_CODE_UNSPECIFIED", "TRAINING_OPERATION_ERROR_CODE_RESOURCE_EXHAUSTED", "TRAINING_OPERATION_ERROR_CODE_TIMEOUT", "TRAINING_OPERATION_ERROR_CODE_INTERNAL_ERROR", "TRAINING_OPERATION_ERROR_CODE_SESSION_NOT_ACTIVE", "TRAINING_OPERATION_ERROR_CODE_INVALID_INPUT", "TRAINING_OPERATION_ERROR_CODE_NON_FINITE_LOSS"]); export const rLTrainingOperationError = z.object({code: rLTrainingOperationErrorCode.optional(), message: z.string().optional()}); export const rLWeightsSyncOperation = z.object({id: z.string(), status: rLTrainingOperationStatus, output: rLWeightsSyncResult.optional(), error: rLTrainingOperationError.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 }; /** * Get weights-sync operation * * GET /v1/rl/training-sessions/{session_id}/operations/weights-sync/{operation_id} */ export const getApiV1RlTrainingSessionsSessionIdOperationsWeightsSyncOperationId = async (args: GetApiV1RlTrainingSessionsSessionIdOperationsWeightsSyncOperationIdArgs, options?: GetApiV1RlTrainingSessionsSessionIdOperationsWeightsSyncOperationIdOptions) => { const {baseUrl = "https://api.together.ai", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/rl/training-sessions/${encodeURIComponent(String(args.session_id))}/operations/weights-sync/${encodeURIComponent(String(args.operation_id))}${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(rLWeightsSyncOperation, await res.json()) };