import {z} from 'zod' export type ConstraintRequest = {description: string, choices?: (Array | null) | undefined, weights?: (Array | null) | undefined, probability?: (number | null) | undefined}; export type LabelExistingNERRequest = {user_id?: (string | null) | undefined, labels: Array, inputs: Array, domain_description?: (string | null) | undefined, seed?: (number | null) | undefined, session_id?: (string | null) | undefined, config_num_examples?: number | undefined, temperature?: number | undefined, constraints?: (Array | null) | undefined, save_dataset?: boolean | undefined, dataset_name?: (string | null) | undefined, project_id?: (string | null) | undefined}; export type CreateApiV1GenerateNerLabelExistingArgs = {body: LabelExistingNERRequest}; export type CreateApiV1GenerateNerLabelExistingOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const generateResponse = z.object({success: z.boolean(), data: z.array(z.record(z.string(), z.unknown())), count: z.number().int(), task_type: z.string(), token_usage: z.number().int().nullable().optional(), dataset: z.record(z.string(), z.unknown()).nullable().optional()}); 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 }; /** * Label Existing Ner * * POST /v1/generate/ner/label-existing * * Also accepts auth: BearerAuth */ export const createApiV1GenerateNerLabelExisting = async (args: CreateApiV1GenerateNerLabelExistingArgs, options: CreateApiV1GenerateNerLabelExistingOptions) => { 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/generate/ner/label-existing${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(generateResponse, await res.json()) };