import {z} from 'zod' export type LLMSettingsUpdate = {llm_catalog_id?: (number | null) | undefined, provider?: (string | null) | undefined, library?: (string | null) | undefined, max_tokens?: (number | null) | undefined, cost_prompt_tokens?: (number | string | null) | undefined, cost_completion_tokens?: (number | string | null) | undefined, region?: (string | null) | undefined, args?: ({[key: string]: unknown} | null) | undefined, openai_resource?: (string | null) | undefined, api_version?: (string | null) | undefined, deployment_name?: (string | null) | undefined, endpoint?: (string | null) | undefined, api_key?: (string | null) | undefined}; export type PatchApiLlmSettingsSettingsIdArgs = {settings_id: number, cookie_name?: (string | null) | undefined, body: LLMSettingsUpdate}; export type PatchApiLlmSettingsSettingsIdOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiLlmSettingsSettingsIdResponse = z.unknown(); 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 LLM settings * * PATCH /llm/settings/{settings_id} */ export const patchApiLlmSettingsSettingsId = async (args: PatchApiLlmSettingsSettingsIdArgs, options?: PatchApiLlmSettingsSettingsIdOptions) => { const {baseUrl = "https://api.your-domain.com", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.cookie_name != null) query.append("cookie_name", String(args.cookie_name)) if (APIKeyHeader !== undefined) headers.set("X-API-KEY", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/llm/settings/${encodeURIComponent(String(args.settings_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiLlmSettingsSettingsIdResponse, await res.json()) };