export type CreateApiCasesChatCompletionArgs = {body: {messages: Array<{content: string, role: 'user' | 'assistant'}>, model?: string | undefined, notebook: {[key: string]: unknown}, parameters?: (Array<{choices?: Array | undefined, default_value: string, description?: string | undefined, label: string, max?: number | undefined, min?: number | undefined, unit?: string | undefined, value_type: 'number' | 'smiles' | 'string' | 'tuple' | 'array' | 'enum' | 'file', variable_name: string}>) | undefined, provider?: ('anthropic' | 'bedrock') | undefined}}; export type CreateApiCasesChatCompletionOptions = {baseUrl: string, backendAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Stream a plain-text cases chat completion as SSE * * POST /cases/chat/completion */ export const createApiCasesChatCompletion = async (args: CreateApiCasesChatCompletionArgs, options: CreateApiCasesChatCompletionOptions) => { const {baseUrl, fetch: fetchFn = fetch, backendAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "text/event-stream") if (backendAuth !== undefined) cookies.push("mtls-prd=" + encodeURIComponent(backendAuth)) const url = `${baseUrl.replace(/\/+$/, '')}/cases/chat/completion${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 res.text() };