import {z} from 'zod' export type ModelDataUpdatePayloadForInternal = {is_public?: (boolean | null) | undefined, default_active?: (boolean | null) | undefined, context_window?: (number | null) | undefined, url?: (string | null) | undefined, description?: (string | null) | undefined, until?: (string | null) | undefined, owner?: (string | null) | undefined, model?: (string | null) | undefined, at?: (string | null) | undefined, provider?: (string | null) | undefined, prompt_token_cost?: (string | null) | undefined, completion_token_cost?: (string | null) | undefined, base_cost?: (string | null) | undefined, deprecated_on?: (string | 'NONE' | null) | undefined, app_id?: (string | null) | undefined, org_id?: (string | null) | undefined}; export type UpdateApiV1InternalModelsModelIdArgs = {model_id: string, body: ModelDataUpdatePayloadForInternal}; export type UpdateApiV1InternalModelsModelIdOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const modelData: z.ZodType = z.object({supports_functions: z.boolean(), supports_json: z.boolean(), supports_n: z.boolean(), supports_penalties: z.boolean(), supports_stream: z.boolean(), supports_vision: z.boolean(), completion_token_cost: z.number(), prompt_token_cost: z.number(), base_cost: z.number(), price_unit: z.enum(["tokens", "characters"]), model: z.string(), provider: z.string().nullable().optional(), owner: z.string().nullable().optional(), namespace: z.string(), at: z.string().nullable().optional(), context_window: z.number().int(), until: z.string().nullable(), description: z.string(), url: z.string(), api_target: z.string().optional(), deprecated_on: z.string().nullable().optional(), parent_id: z.string().nullable().optional(), parent: z.lazy(() => modelData.nullable().optional()), prompt_id: z.string().nullable().optional(), is_rag: z.boolean(), is_ft: z.boolean(), is_open_source: z.boolean(), is_gdpr: z.boolean(), is_chat: z.boolean(), id: z.string().nullable(), app_id: z.string().nullable(), org_id: z.string().nullable(), added_by: z.string().nullable(), added_on: z.string().nullable(), modified_on: z.string().nullable(), is_public: z.boolean(), is_test_model: z.boolean(), is_pulze_owner: z.boolean(), default_active: z.boolean()}); 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 }; /** * Update Model In Pulze App * * PUT /v1/internal/models/{model_id} */ export const updateApiV1InternalModelsModelId = async (args: UpdateApiV1InternalModelsModelIdArgs, options: UpdateApiV1InternalModelsModelIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/internal/models/${encodeURIComponent(String(args.model_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(modelData, await res.json()) };