lint and test
This commit is contained in:
parent
7b683cfc50
commit
02f8233a74
|
@ -1 +1 @@
|
||||||
Subproject commit 1bce30827813e135ee414141fdf51e45236b8f3c
|
Subproject commit 9348817b6f6b3fae87547d9eee7ca533da10f13c
|
|
@ -1,11 +1,29 @@
|
||||||
import { fixAutoColumnSubType } from "../utils"
|
import { fixAutoColumnSubType, processAIColumns } from "../utils"
|
||||||
import { AutoFieldDefaultNames } from "../../../constants"
|
import { AutoFieldDefaultNames } from "../../../constants"
|
||||||
import {
|
import {
|
||||||
|
AIOperationEnum,
|
||||||
AutoFieldSubType,
|
AutoFieldSubType,
|
||||||
FieldSchema,
|
FieldSchema,
|
||||||
FieldType,
|
FieldType,
|
||||||
|
INTERNAL_TABLE_SOURCE_ID,
|
||||||
RelationshipType,
|
RelationshipType,
|
||||||
|
Table,
|
||||||
|
TableSourceType,
|
||||||
} from "@budibase/types"
|
} 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("rowProcessor utility", () => {
|
||||||
describe("fixAutoColumnSubType", () => {
|
describe("fixAutoColumnSubType", () => {
|
||||||
|
@ -60,4 +78,59 @@ describe("rowProcessor utility", () => {
|
||||||
expect(fixAutoColumnSubType(schema)).toEqual(schema)
|
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",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -119,7 +119,7 @@ export interface FormulaFieldMetadata extends BaseFieldSchema {
|
||||||
|
|
||||||
export interface AIFieldMetadata extends BaseFieldSchema {
|
export interface AIFieldMetadata extends BaseFieldSchema {
|
||||||
type: FieldType.AI
|
type: FieldType.AI
|
||||||
formula: string
|
// formula: string
|
||||||
operation: AIOperationEnum
|
operation: AIOperationEnum
|
||||||
columns?: string[]
|
columns?: string[]
|
||||||
column?: string
|
column?: string
|
||||||
|
|
Loading…
Reference in New Issue