export type CreateApiIngestPlainTextArgs = {collection_id: string, file_name: string, gen_doc_summaries?: boolean | undefined, gen_doc_questions?: boolean | undefined, timeout?: number | undefined, metadata?: string | undefined, body: BodyInit}; export type CreateApiIngestPlainTextOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Adds plain text to a collection. * * POST /ingest/plain_text */ export const createApiIngestPlainText = async (args: CreateApiIngestPlainTextArgs, options?: CreateApiIngestPlainTextOptions) => { const {baseUrl = "https://h2ogpte.genai.h2o.ai/api/v1", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "text/plain") if (args.collection_id != null) query.append("collection_id", String(args.collection_id)) if (args.file_name != null) query.append("file_name", String(args.file_name)) if (args.gen_doc_summaries != null) query.append("gen_doc_summaries", String(args.gen_doc_summaries)) if (args.gen_doc_questions != null) query.append("gen_doc_questions", String(args.gen_doc_questions)) if (args.timeout != null) query.append("timeout", String(args.timeout)) if (args.metadata != null) query.append("metadata", String(args.metadata)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/ingest/plain_text${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };