Merge pull request #15117 from Budibase/openai-fix
rely on llm status rather than initialised variable
This commit is contained in:
commit
963d162a18
|
@ -1 +1 @@
|
||||||
Subproject commit e60f4b1b364fd49d2bb082f298757f83cb2032f0
|
Subproject commit 7b8789efd940d9f8e5be9927243b19f07361c445
|
|
@ -48,7 +48,7 @@ jest.mock("@budibase/pro", () => ({
|
||||||
ai: {
|
ai: {
|
||||||
LargeLanguageModel: {
|
LargeLanguageModel: {
|
||||||
forCurrentTenant: async () => ({
|
forCurrentTenant: async () => ({
|
||||||
initialised: true,
|
llm: {},
|
||||||
run: jest.fn(() => `Mock LLM Response`),
|
run: jest.fn(() => `Mock LLM Response`),
|
||||||
buildPromptFromAIOperation: jest.fn(),
|
buildPromptFromAIOperation: jest.fn(),
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -52,7 +52,7 @@ jest.mock("@budibase/pro", () => ({
|
||||||
ai: {
|
ai: {
|
||||||
LargeLanguageModel: {
|
LargeLanguageModel: {
|
||||||
forCurrentTenant: async () => ({
|
forCurrentTenant: async () => ({
|
||||||
initialised: true,
|
llm: {},
|
||||||
run: jest.fn(() => `Mock LLM Response`),
|
run: jest.fn(() => `Mock LLM Response`),
|
||||||
buildPromptFromAIOperation: jest.fn(),
|
buildPromptFromAIOperation: jest.fn(),
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -106,13 +106,15 @@ export async function run({
|
||||||
(await features.flags.isEnabled(FeatureFlag.BUDIBASE_AI)) &&
|
(await features.flags.isEnabled(FeatureFlag.BUDIBASE_AI)) &&
|
||||||
(await pro.features.isBudibaseAIEnabled())
|
(await pro.features.isBudibaseAIEnabled())
|
||||||
|
|
||||||
let llm
|
let llmWrapper
|
||||||
if (budibaseAIEnabled || customConfigsEnabled) {
|
if (budibaseAIEnabled || customConfigsEnabled) {
|
||||||
llm = await pro.ai.LargeLanguageModel.forCurrentTenant(inputs.model)
|
llmWrapper = await pro.ai.LargeLanguageModel.forCurrentTenant(
|
||||||
|
inputs.model
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
response = llm?.initialised
|
response = llmWrapper?.llm
|
||||||
? await llm.run(inputs.prompt)
|
? await llmWrapper.run(inputs.prompt)
|
||||||
: await legacyOpenAIPrompt(inputs)
|
: await legacyOpenAIPrompt(inputs)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -27,7 +27,7 @@ jest.mock("@budibase/pro", () => ({
|
||||||
ai: {
|
ai: {
|
||||||
LargeLanguageModel: {
|
LargeLanguageModel: {
|
||||||
forCurrentTenant: jest.fn().mockImplementation(() => ({
|
forCurrentTenant: jest.fn().mockImplementation(() => ({
|
||||||
initialised: true,
|
llm: {},
|
||||||
init: jest.fn(),
|
init: jest.fn(),
|
||||||
run: jest.fn(),
|
run: jest.fn(),
|
||||||
})),
|
})),
|
||||||
|
|
|
@ -18,7 +18,7 @@ jest.mock("@budibase/pro", () => ({
|
||||||
ai: {
|
ai: {
|
||||||
LargeLanguageModel: {
|
LargeLanguageModel: {
|
||||||
forCurrentTenant: async () => ({
|
forCurrentTenant: async () => ({
|
||||||
initialised: true,
|
llm: {},
|
||||||
run: jest.fn(() => "response from LLM"),
|
run: jest.fn(() => "response from LLM"),
|
||||||
buildPromptFromAIOperation: buildPromptMock,
|
buildPromptFromAIOperation: buildPromptMock,
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -126,8 +126,10 @@ export async function processAIColumns<T extends Row | Row[]>(
|
||||||
const numRows = Array.isArray(inputRows) ? inputRows.length : 1
|
const numRows = Array.isArray(inputRows) ? inputRows.length : 1
|
||||||
span?.addTags({ table_id: table._id, numRows })
|
span?.addTags({ table_id: table._id, numRows })
|
||||||
const rows = Array.isArray(inputRows) ? inputRows : [inputRows]
|
const rows = Array.isArray(inputRows) ? inputRows : [inputRows]
|
||||||
const llm = await pro.ai.LargeLanguageModel.forCurrentTenant("gpt-4o-mini")
|
const llmWrapper = await pro.ai.LargeLanguageModel.forCurrentTenant(
|
||||||
if (rows && llm.initialised) {
|
"gpt-4o-mini"
|
||||||
|
)
|
||||||
|
if (rows && llmWrapper.llm) {
|
||||||
// Ensure we have snippet context
|
// Ensure we have snippet context
|
||||||
await context.ensureSnippetContext()
|
await context.ensureSnippetContext()
|
||||||
|
|
||||||
|
@ -151,14 +153,14 @@ export async function processAIColumns<T extends Row | Row[]>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const prompt = llm.buildPromptFromAIOperation({
|
const prompt = llmWrapper.buildPromptFromAIOperation({
|
||||||
schema: aiSchema,
|
schema: aiSchema,
|
||||||
row,
|
row,
|
||||||
})
|
})
|
||||||
|
|
||||||
return tracer.trace("processAIColumn", {}, async span => {
|
return tracer.trace("processAIColumn", {}, async span => {
|
||||||
span?.addTags({ table_id: table._id, column })
|
span?.addTags({ table_id: table._id, column })
|
||||||
const llmResponse = await llm.run(prompt!)
|
const llmResponse = await llmWrapper.run(prompt!)
|
||||||
return {
|
return {
|
||||||
...row,
|
...row,
|
||||||
[column]: llmResponse,
|
[column]: llmResponse,
|
||||||
|
|
Loading…
Reference in New Issue