further AI config updates for case where there's no configuration
This commit is contained in:
parent
52b48db5eb
commit
7623c0ce07
|
@ -12,7 +12,7 @@
|
|||
Tags,
|
||||
Tag,
|
||||
} from "@budibase/bbui"
|
||||
import { admin, licensing } from "stores/portal"
|
||||
import { admin, licensing, featureFlags } from "stores/portal"
|
||||
import { API } from "api"
|
||||
import AIConfigModal from "./ConfigModal.svelte"
|
||||
import AIConfigTile from "./AIConfigTile.svelte"
|
||||
|
@ -27,7 +27,8 @@
|
|||
let editingUuid
|
||||
|
||||
$: isCloud = $admin.cloud
|
||||
$: customAIConfigsEnabled = $licensing.customAIConfigsEnabled
|
||||
$: customAIConfigsEnabled =
|
||||
$featureFlags.AI_CUSTOM_CONFIGS && $licensing.customAIConfigsEnabled
|
||||
|
||||
async function fetchAIConfig() {
|
||||
try {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<script>
|
||||
import { redirect } from "@roxi/routify"
|
||||
import { licensing } from "stores/portal"
|
||||
import { featureFlags } from "stores/portal"
|
||||
|
||||
if ($licensing.customAIConfigsEnabled) {
|
||||
if ($featureFlags.AI_CUSTOM_CONFIGS) {
|
||||
$redirect("./ai")
|
||||
} else {
|
||||
$redirect("./auth")
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 2ab8536b6005576684810d774f1ac22239218546
|
||||
Subproject commit fd131d3dfa0489e68ddd8a55979f4866f4fd6044
|
|
@ -102,21 +102,15 @@ export async function run({
|
|||
const customConfigsEnabled = await pro.features.isAICustomConfigsEnabled()
|
||||
const budibaseAIEnabled = await pro.features.isBudibaseAIEnabled()
|
||||
|
||||
let llm
|
||||
if (budibaseAIEnabled || customConfigsEnabled) {
|
||||
const llm = await pro.ai.LargeLanguageModel.forCurrentTenant(inputs.model)
|
||||
response = await llm.run(inputs.prompt)
|
||||
} else {
|
||||
// fallback to the default that uses the environment variable for backwards compat
|
||||
if (!env.OPENAI_API_KEY) {
|
||||
return {
|
||||
success: false,
|
||||
response:
|
||||
"OpenAI API Key not configured - please add the OPENAI_API_KEY environment variable.",
|
||||
}
|
||||
}
|
||||
response = await legacyOpenAIPrompt(inputs)
|
||||
llm = await pro.ai.LargeLanguageModel.forCurrentTenant(inputs.model)
|
||||
}
|
||||
|
||||
response = llm?.initialised
|
||||
? await llm.run(inputs.prompt)
|
||||
: await legacyOpenAIPrompt(inputs)
|
||||
|
||||
return {
|
||||
response,
|
||||
success: true,
|
||||
|
|
|
@ -108,7 +108,7 @@ export async function processAIColumns<T extends Row | Row[]>(
|
|||
span?.addTags({ table_id: table._id, numRows })
|
||||
const rows = Array.isArray(inputRows) ? inputRows : [inputRows]
|
||||
const llm = await pro.ai.LargeLanguageModel.forCurrentTenant("gpt-4o-mini")
|
||||
if (rows) {
|
||||
if (rows && llm.initialised) {
|
||||
// Ensure we have snippet context
|
||||
await context.ensureSnippetContext()
|
||||
|
||||
|
|
|
@ -12,27 +12,29 @@ import {
|
|||
} from "@budibase/backend-core"
|
||||
import { checkAnyUserExists } from "../../../utilities/users"
|
||||
import {
|
||||
AIConfig,
|
||||
AIInnerConfig,
|
||||
Config,
|
||||
ConfigType,
|
||||
Ctx,
|
||||
GetPublicOIDCConfigResponse,
|
||||
GetPublicSettingsResponse,
|
||||
GoogleInnerConfig,
|
||||
isAIConfig,
|
||||
isGoogleConfig,
|
||||
isOIDCConfig,
|
||||
isSettingsConfig,
|
||||
isSMTPConfig,
|
||||
OIDCConfigs,
|
||||
OIDCLogosConfig,
|
||||
PASSWORD_REPLACEMENT,
|
||||
QuotaUsageType,
|
||||
SettingsBrandingConfig,
|
||||
SettingsInnerConfig,
|
||||
SSOConfig,
|
||||
SSOConfigType,
|
||||
StaticQuotaName,
|
||||
UserCtx,
|
||||
OIDCLogosConfig,
|
||||
AIConfig,
|
||||
PASSWORD_REPLACEMENT,
|
||||
isAIConfig,
|
||||
AIInnerConfig,
|
||||
} from "@budibase/types"
|
||||
import * as pro from "@budibase/pro"
|
||||
|
||||
|
@ -83,6 +85,12 @@ const getEventFns = async (config: Config, existing?: Config) => {
|
|||
fns.push(events.email.SMTPUpdated)
|
||||
} else if (isAIConfig(config)) {
|
||||
fns.push(() => events.ai.AIConfigUpdated)
|
||||
if (
|
||||
Object.keys(existing.config).length > Object.keys(config.config).length
|
||||
) {
|
||||
fns.push(() => pro.quotas.removeCustomAIConfig())
|
||||
}
|
||||
fns.push(() => pro.quotas.addCustomAIConfig())
|
||||
} else if (isGoogleConfig(config)) {
|
||||
fns.push(() => events.auth.SSOUpdated(ConfigType.GOOGLE))
|
||||
if (!existing.config.activated && config.config.activated) {
|
||||
|
@ -248,7 +256,6 @@ export async function save(ctx: UserCtx<Config>) {
|
|||
if (existingConfig) {
|
||||
await verifyAIConfig(config, existingConfig)
|
||||
}
|
||||
await pro.quotas.addCustomAIConfig()
|
||||
break
|
||||
}
|
||||
} catch (err: any) {
|
||||
|
@ -518,7 +525,11 @@ export async function destroy(ctx: UserCtx) {
|
|||
await db.remove(id, rev)
|
||||
await cache.destroy(cache.CacheKey.CHECKLIST)
|
||||
if (id === configs.generateConfigID(ConfigType.AI)) {
|
||||
await pro.quotas.removeCustomAIConfig()
|
||||
await pro.quotas.set(
|
||||
StaticQuotaName.AI_CUSTOM_CONFIGS,
|
||||
QuotaUsageType.STATIC,
|
||||
0
|
||||
)
|
||||
}
|
||||
ctx.body = { message: "Config deleted successfully" }
|
||||
} catch (err: any) {
|
||||
|
|
Loading…
Reference in New Issue