import {z} from 'zod' export type RefinePromptRequestRequest = {project_id: number, teacher_model_name: string, teacher_model_provider_connection_id: number}; export type CreateApiApiPromptsPromptIdVersionsVersionIdRefineArgs = {async?: boolean | undefined, prompt_id: number, version_id: number, body: RefinePromptRequestRequest}; export type CreateApiApiPromptsPromptIdVersionsVersionIdRefineOptions = {baseUrl?: string | undefined, Token?: string | undefined, fetch?: typeof fetch | undefined}; export const userSimple = z.object({avatar: z.string().nullable(), email: z.string().max(254).optional(), first_name: z.string().max(256).optional(), id: z.number().int(), last_name: z.string().max(256).optional(), username: z.string().max(256)}); export const providerEnum = z.enum(["OpenAI", "AzureOpenAI", "AzureAIFoundry", "VertexAI", "Gemini", "Anthropic", "Custom"]); export const thirdPartyModelVersion = z.object({created_at: z.string(), created_by: userSimple, id: z.number().int(), max_few_shot_examples: z.number().int().gte(0).lte(2147483647).nullable().optional(), model_display_name: z.string(), model_provider_connection: z.number().int().nullable().optional(), organization: z.number().int().nullable(), parent_model: z.number().int().optional(), prompt: z.string(), provider: providerEnum.optional(), provider_model_id: z.string().max(255), score: z.number().nullable(), title: z.string().max(500), updated_at: z.string()}); export const refinedPromptResponse = z.object({previous_version: thirdPartyModelVersion.nullable(), prompt: z.string(), reasoning: z.string().nullable(), refinement_job_id: z.string().nullable(), refinement_status: z.string().nullable(), title: z.string().nullable(), total_cost: z.string().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 }; /** * ✨ Refine a prompt version * * POST /api/prompts/{prompt_id}/versions/{version_id}/refine */ export const createApiApiPromptsPromptIdVersionsVersionIdRefine = async (args: CreateApiApiPromptsPromptIdVersionsVersionIdRefineArgs, options?: CreateApiApiPromptsPromptIdVersionsVersionIdRefineOptions) => { const {baseUrl = "http://localhost:8000", fetch: fetchFn = fetch, Token} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.async != null) query.append("async", String(args.async)) if (Token !== undefined) headers.set("Authorization", Token) const url = `${baseUrl.replace(/\/+$/, '')}/api/prompts/${encodeURIComponent(String(args.prompt_id))}/versions/${encodeURIComponent(String(args.version_id))}/refine${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(refinedPromptResponse, await res.json()) };