export type GenerateMessageAnswerOptions = {responseSize?: ('XS' | 'SM' | 'MD' | 'LG' | 'XL' | 'AUTO') | undefined, autoUseFallback?: boolean | undefined, gptModel?: ('GPT_3_5_TURBO' | 'GPT_4') | undefined, useInlineReferences?: boolean | undefined, customInstructionId?: string | undefined, inlineReferenceType?: ('ID' | 'URL') | undefined}; export type GenerateExistingMessageAnswerRequest = {messageId: string, options?: GenerateMessageAnswerOptions | undefined}; export type CreateApiChatMessageStreamArgs = {body: GenerateExistingMessageAnswerRequest}; export type CreateApiChatMessageStreamOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Get a streaming answer * * POST /chat/message/stream */ export const createApiChatMessageStream = async (args: CreateApiChatMessageStreamArgs, options?: CreateApiChatMessageStreamOptions) => { const {baseUrl = "https://api.sentiyen.com/api/v3", fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/octet-stream") if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/chat/message/stream${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.blob() };