import {z} from 'zod' export type DatasetLLMAnalysisRequest = {task_type: 'ner' | 'classification' | 'generative', task_description?: (string | null) | undefined, labels?: (Array | null) | undefined, dataset?: (Array<{[key: string]: unknown}> | null) | undefined, dataset_name?: (string | null) | undefined, dataset_version?: (string | null) | undefined}; export type CreateApiV1DatasetAnalyzeLlmArgs = {body: DatasetLLMAnalysisRequest}; export type CreateApiV1DatasetAnalyzeLlmOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const diversityLLMAnalysis = z.object({reasoning_trace: z.string(), summary: z.string(), diversity_rating: z.enum(["low", "moderate", "high", "excellent"]), key_observations: z.array(z.string()).optional(), recommendations: z.array(z.string()).optional(), model_used: z.string()}); 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 }; /** * Analyze Dataset Llm * * POST /v1/dataset/analyze_llm * * Also accepts auth: BearerAuth */ export const createApiV1DatasetAnalyzeLlm = async (args: CreateApiV1DatasetAnalyzeLlmArgs, options: CreateApiV1DatasetAnalyzeLlmOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/dataset/analyze_llm${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(diversityLLMAnalysis, await res.json()) };