diff --git a/packages/server/specs/openapi.json b/packages/server/specs/openapi.json index b21554505b..f9f5a364ae 100644 --- a/packages/server/specs/openapi.json +++ b/packages/server/specs/openapi.json @@ -833,7 +833,8 @@ "type": "string", "enum": [ "static", - "dynamic" + "dynamic", + "ai" ], "description": "Defines whether this is a static or dynamic formula." } @@ -857,6 +858,7 @@ "link", "formula", "auto", + "ai", "json", "internal", "barcodeqr", @@ -1042,7 +1044,8 @@ "type": "string", "enum": [ "static", - "dynamic" + "dynamic", + "ai" ], "description": "Defines whether this is a static or dynamic formula." } @@ -1066,6 +1069,7 @@ "link", "formula", "auto", + "ai", "json", "internal", "barcodeqr", @@ -1262,7 +1266,8 @@ "type": "string", "enum": [ "static", - "dynamic" + "dynamic", + "ai" ], "description": "Defines whether this is a static or dynamic formula." } @@ -1286,6 +1291,7 @@ "link", "formula", "auto", + "ai", "json", "internal", "barcodeqr", diff --git a/packages/server/specs/openapi.yaml b/packages/server/specs/openapi.yaml index 6a2ae89c61..d4b2df54a5 100644 --- a/packages/server/specs/openapi.yaml +++ b/packages/server/specs/openapi.yaml @@ -761,6 +761,7 @@ components: enum: - static - dynamic + - ai description: Defines whether this is a static or dynamic formula. - type: object properties: @@ -779,6 +780,7 @@ components: - link - formula - auto + - ai - json - internal - barcodeqr @@ -929,6 +931,7 @@ components: enum: - static - dynamic + - ai description: Defines whether this is a static or dynamic formula. - type: object properties: @@ -947,6 +950,7 @@ components: - link - formula - auto + - ai - json - internal - barcodeqr @@ -1104,6 +1108,7 @@ components: enum: - static - dynamic + - ai description: Defines whether this is a static or dynamic formula. - type: object properties: @@ -1122,6 +1127,7 @@ components: - link - formula - auto + - ai - json - internal - barcodeqr diff --git a/packages/server/src/api/controllers/row/staticFormula.ts b/packages/server/src/api/controllers/row/staticFormula.ts index 266d45d270..eb1283cc9e 100644 --- a/packages/server/src/api/controllers/row/staticFormula.ts +++ b/packages/server/src/api/controllers/row/staticFormula.ts @@ -10,6 +10,7 @@ import * as linkRows from "../../../db/linkedRows" import isEqual from "lodash/isEqual" import { cloneDeep } from "lodash/fp" import sdk from "../../../sdk" +import * as pro from "@budibase/pro" /** * This function runs through a list of enriched rows, looks at the rows which @@ -143,9 +144,12 @@ export async function finaliseRow( dynamic: false, contextRows: [enrichedRow], }) - row = await processAIColumns(table, row, { - contextRows: [enrichedRow], - }) + const aiEnabled = await pro.features.isBudibaseAIEnabled() || await pro.features.isAICustomConfigsEnabled() + if (aiEnabled) { + row = await processAIColumns(table, row, { + contextRows: [enrichedRow], + }) + } const response = await db.put(row) // for response, calculate the formulas for the enriched row @@ -153,9 +157,11 @@ export async function finaliseRow( enrichedRow = await processFormulas(table, enrichedRow, { dynamic: false, }) - enrichedRow = await processAIColumns(table, row, { - contextRows: [enrichedRow], - }) + if (aiEnabled) { + enrichedRow = await processAIColumns(table, row, { + contextRows: [enrichedRow], + }) + } // this updates the related formulas in other rows based on the relations to this row if (updateFormula) { diff --git a/packages/server/src/api/routes/tests/datasource.spec.ts b/packages/server/src/api/routes/tests/datasource.spec.ts index 7545253181..768dfb32de 100644 --- a/packages/server/src/api/routes/tests/datasource.spec.ts +++ b/packages/server/src/api/routes/tests/datasource.spec.ts @@ -343,6 +343,12 @@ describe("/datasources", () => { type: FieldType.FORMULA, formula: "any formula", }, + [FieldType.AI]: { + name: "ai", + type: FieldType.AI, + operation: "PROMPT", + prompt: "test prompt", + }, [FieldType.BARCODEQR]: { name: "barcodeqr", type: FieldType.BARCODEQR, diff --git a/packages/server/src/integrations/utils/utils.ts b/packages/server/src/integrations/utils/utils.ts index 43302de36f..73b2f637f8 100644 --- a/packages/server/src/integrations/utils/utils.ts +++ b/packages/server/src/integrations/utils/utils.ts @@ -242,6 +242,7 @@ function copyExistingPropsOver( let shouldKeepSchema = false switch (existingColumnType) { case FieldType.FORMULA: + case FieldType.AI: case FieldType.AUTO: case FieldType.INTERNAL: shouldKeepSchema = true diff --git a/packages/types/src/documents/app/row.ts b/packages/types/src/documents/app/row.ts index cb4b1d560d..6d7e0c754f 100644 --- a/packages/types/src/documents/app/row.ts +++ b/packages/types/src/documents/app/row.ts @@ -77,7 +77,10 @@ export enum FieldType { */ AUTO = "auto", /** - * A complex type, called an AI column within Budibase. This type has a... TODO: fill out + * A complex type, called an AI column within Budibase. This type is only supported against internal tables + * and calculates the output based on a chosen operation (summarise text, translation etc) which passes to + * the configured Budibase Large Language Model to retrieve the output and write it back into the row. + * AI fields function in a similar fashion to static formulas, and possess many of the same characteristics. */ AI = "ai", /**