diff --git a/packages/pro b/packages/pro index 1bce308278..9348817b6f 160000 --- a/packages/pro +++ b/packages/pro @@ -1 +1 @@ -Subproject commit 1bce30827813e135ee414141fdf51e45236b8f3c +Subproject commit 9348817b6f6b3fae87547d9eee7ca533da10f13c diff --git a/packages/server/src/utilities/rowProcessor/tests/utils.spec.ts b/packages/server/src/utilities/rowProcessor/tests/utils.spec.ts index 49dd05910d..41f9befc1a 100644 --- a/packages/server/src/utilities/rowProcessor/tests/utils.spec.ts +++ b/packages/server/src/utilities/rowProcessor/tests/utils.spec.ts @@ -1,11 +1,29 @@ -import { fixAutoColumnSubType } from "../utils" +import { fixAutoColumnSubType, processAIColumns } from "../utils" import { AutoFieldDefaultNames } from "../../../constants" import { + AIOperationEnum, AutoFieldSubType, FieldSchema, FieldType, + INTERNAL_TABLE_SOURCE_ID, RelationshipType, + Table, + TableSourceType, } from "@budibase/types" +import { generator } from "@budibase/backend-core/tests" + +const buildPromptMock = jest.fn() + +jest.mock("@budibase/pro", () => ({ + ai: { + LargeLanguageModel: { + forCurrentTenant: async () => ({ + run: jest.fn(() => "response from LLM"), + buildPromptFromAIOperation: buildPromptMock, + }), + }, + }, +})) describe("rowProcessor utility", () => { describe("fixAutoColumnSubType", () => { @@ -60,4 +78,59 @@ describe("rowProcessor utility", () => { expect(fixAutoColumnSubType(schema)).toEqual(schema) }) }) + + describe("processAIColumns", () => { + it("ensures that bindable inputs are mapped and passed to to LLM prompt generation", async () => { + const table: Table = { + _id: generator.guid(), + name: "AITestTable", + type: "table", + sourceId: INTERNAL_TABLE_SOURCE_ID, + sourceType: TableSourceType.INTERNAL, + schema: { + product: { + type: FieldType.STRING, + name: "product", + constraints: { + presence: true, + type: "string", + }, + }, + aicol: { + type: FieldType.AI, + name: "aicol", + operation: AIOperationEnum.PROMPT, + prompt: "Translate '{{ product }}' into German", + }, + }, + } + + const inputRows = [ + { + product: "Car Battery", + }, + ] + + const result = await processAIColumns(table, inputRows, { + contextRows: inputRows, + }) + expect(buildPromptMock).toHaveBeenCalledWith({ + row: { + product: "Car Battery", + }, + schema: { + name: "aicol", + operation: "PROMPT", + prompt: "Translate 'Car Battery' into German", + type: "ai", + }, + }) + expect(result).toEqual([ + { + aicol: "response from LLM", + product: "Car Battery", + }, + ]) + }) + }) }) diff --git a/packages/types/src/documents/app/table/schema.ts b/packages/types/src/documents/app/table/schema.ts index c62921a3ea..bb3da3f844 100644 --- a/packages/types/src/documents/app/table/schema.ts +++ b/packages/types/src/documents/app/table/schema.ts @@ -119,7 +119,7 @@ export interface FormulaFieldMetadata extends BaseFieldSchema { export interface AIFieldMetadata extends BaseFieldSchema { type: FieldType.AI - formula: string + // formula: string operation: AIOperationEnum columns?: string[] column?: string