import { ChatCompletionRequest, ChatCompletionResponse, GenerateCronRequest, GenerateCronResponse, GenerateJsRequest, GenerateJsResponse, GenerateTablesRequest, GenerateTablesResponse, } from "@budibase/types" import { Expectations, TestAPI } from "./base" import { constants } from "@budibase/backend-core" export class AIAPI extends TestAPI { generateJs = async ( req: GenerateJsRequest, expectations?: Expectations ): Promise => { return await this._post(`/api/ai/js`, { body: req, expectations, }) } generateCron = async ( req: GenerateCronRequest, expectations?: Expectations ): Promise => { return await this._post(`/api/ai/cron`, { body: req, expectations, }) } chat = async ( req: ChatCompletionRequest & { licenseKey: string }, expectations?: Expectations ): Promise => { const headers: Record = {} if (req.licenseKey) { headers[constants.Header.LICENSE_KEY] = req.licenseKey } return await this._post(`/api/ai/chat`, { body: req, headers, expectations, }) } generateTables = async ( req: GenerateTablesRequest, expectations?: Expectations ): Promise => { const headers: Record = {} return await this._post(`/api/ai/tables`, { body: req, headers, expectations, }) } }