import {z} from 'zod' export type GetApiApiPromptsPromptIdVersionsVersionIdFewShotExamplesArgs = {ordering?: string | undefined, prompt_id: number, version_id: number}; export type GetApiApiPromptsPromptIdVersionsVersionIdFewShotExamplesOptions = {baseUrl?: string | undefined, Token?: string | undefined, fetch?: typeof fetch | undefined}; export const fewShotExample = z.object({annotation: z.number().int(), annotation_result: z.array(z.record(z.string(), z.unknown())), created_at: z.string(), id: z.number().int(), order: z.number().int().gte(0).lte(2147483647).optional(), task: z.number().int(), task_data: z.record(z.string(), z.unknown())}); export const getApiApiPromptsPromptIdVersionsVersionIdFewShotExamplesResponse = z.array(fewShotExample); 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 }; /** * ✨ List few-shot examples * * GET /api/prompts/{prompt_id}/versions/{version_id}/few-shot-examples */ export const getApiApiPromptsPromptIdVersionsVersionIdFewShotExamples = async (args: GetApiApiPromptsPromptIdVersionsVersionIdFewShotExamplesArgs, options?: GetApiApiPromptsPromptIdVersionsVersionIdFewShotExamplesOptions) => { const {baseUrl = "http://localhost:8000", fetch: fetchFn = fetch, Token} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.ordering != null) query.append("ordering", String(args.ordering)) if (Token !== undefined) headers.set("Authorization", Token) const url = `${baseUrl.replace(/\/+$/, '')}/api/prompts/${encodeURIComponent(String(args.prompt_id))}/versions/${encodeURIComponent(String(args.version_id))}/few-shot-examples${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(getApiApiPromptsPromptIdVersionsVersionIdFewShotExamplesResponse, await res.json()) };