Merge pull request #15961 from Budibase/feat/llm-configuration
Typing of AI Configuration files
This commit is contained in:
commit
a408ba7863
|
@ -1,4 +1,4 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import { Body, Label, Icon } from "@budibase/bbui"
|
import { Body, Label, Icon } from "@budibase/bbui"
|
||||||
import BudibaseLogo from "./logos/Budibase.svelte"
|
import BudibaseLogo from "./logos/Budibase.svelte"
|
||||||
import OpenAILogo from "./logos/OpenAI.svelte"
|
import OpenAILogo from "./logos/OpenAI.svelte"
|
||||||
|
@ -6,7 +6,7 @@
|
||||||
import TogetherAILogo from "./logos/TogetherAI.svelte"
|
import TogetherAILogo from "./logos/TogetherAI.svelte"
|
||||||
import AzureOpenAILogo from "./logos/AzureOpenAI.svelte"
|
import AzureOpenAILogo from "./logos/AzureOpenAI.svelte"
|
||||||
import { Providers } from "./constants"
|
import { Providers } from "./constants"
|
||||||
|
import type { ProviderConfig } from "@budibase/types"
|
||||||
const logos = {
|
const logos = {
|
||||||
["Budibase AI"]: BudibaseLogo,
|
["Budibase AI"]: BudibaseLogo,
|
||||||
[Providers.OpenAI.name]: OpenAILogo,
|
[Providers.OpenAI.name]: OpenAILogo,
|
||||||
|
@ -15,11 +15,11 @@
|
||||||
[Providers.AzureOpenAI.name]: AzureOpenAILogo,
|
[Providers.AzureOpenAI.name]: AzureOpenAILogo,
|
||||||
}
|
}
|
||||||
|
|
||||||
export let config
|
export let config: ProviderConfig
|
||||||
export let disabled
|
export let disabled: boolean | null = null
|
||||||
|
|
||||||
export let editHandler
|
export let editHandler: (() => void) | null
|
||||||
export let deleteHandler
|
export let deleteHandler: (() => void) | null
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
|
@ -16,22 +16,23 @@
|
||||||
import { API } from "@/api"
|
import { API } from "@/api"
|
||||||
import AIConfigModal from "./ConfigModal.svelte"
|
import AIConfigModal from "./ConfigModal.svelte"
|
||||||
import AIConfigTile from "./AIConfigTile.svelte"
|
import AIConfigTile from "./AIConfigTile.svelte"
|
||||||
|
import {
|
||||||
|
type AIConfig,
|
||||||
|
ConfigType,
|
||||||
|
type ProviderConfig,
|
||||||
|
} from "@budibase/types"
|
||||||
|
|
||||||
const ConfigTypes = {
|
let modal: Modal
|
||||||
AI: "ai",
|
let fullAIConfig: AIConfig
|
||||||
}
|
let editingAIConfig: ProviderConfig | undefined
|
||||||
|
let editingUuid: string | undefined
|
||||||
let modal
|
|
||||||
let fullAIConfig
|
|
||||||
let editingAIConfig = {}
|
|
||||||
let editingUuid
|
|
||||||
|
|
||||||
$: isCloud = $admin.cloud
|
$: isCloud = $admin.cloud
|
||||||
$: customAIConfigsEnabled = $licensing.customAIConfigsEnabled
|
$: customAIConfigsEnabled = $licensing.customAIConfigsEnabled
|
||||||
|
|
||||||
async function fetchAIConfig() {
|
async function fetchAIConfig() {
|
||||||
try {
|
try {
|
||||||
fullAIConfig = await API.getConfig(ConfigTypes.AI)
|
fullAIConfig = (await API.getConfig(ConfigType.AI)) as AIConfig
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
notifications.error("Error fetching AI config")
|
notifications.error("Error fetching AI config")
|
||||||
}
|
}
|
||||||
|
@ -42,9 +43,9 @@
|
||||||
const id = editingUuid || Helpers.uuid()
|
const id = editingUuid || Helpers.uuid()
|
||||||
|
|
||||||
// Creating first custom AI Config
|
// Creating first custom AI Config
|
||||||
if (!fullAIConfig) {
|
if (!fullAIConfig && editingAIConfig) {
|
||||||
fullAIConfig = {
|
fullAIConfig = {
|
||||||
type: ConfigTypes.AI,
|
type: ConfigType.AI,
|
||||||
config: {
|
config: {
|
||||||
[id]: editingAIConfig,
|
[id]: editingAIConfig,
|
||||||
},
|
},
|
||||||
|
@ -54,7 +55,7 @@
|
||||||
delete fullAIConfig.config.budibase_ai
|
delete fullAIConfig.config.budibase_ai
|
||||||
|
|
||||||
// unset the default value from other configs if default is set
|
// unset the default value from other configs if default is set
|
||||||
if (editingAIConfig.isDefault) {
|
if (editingAIConfig?.isDefault) {
|
||||||
for (let key in fullAIConfig.config) {
|
for (let key in fullAIConfig.config) {
|
||||||
if (key !== id) {
|
if (key !== id) {
|
||||||
fullAIConfig.config[key].isDefault = false
|
fullAIConfig.config[key].isDefault = false
|
||||||
|
@ -62,8 +63,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Add new or update existing custom AI Config
|
// Add new or update existing custom AI Config
|
||||||
fullAIConfig.config[id] = editingAIConfig
|
if (editingAIConfig) {
|
||||||
fullAIConfig.type = ConfigTypes.AI
|
fullAIConfig.config[id] = editingAIConfig
|
||||||
|
}
|
||||||
|
fullAIConfig.type = ConfigType.AI
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -72,7 +75,7 @@
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
notifications.error(
|
notifications.error(
|
||||||
`Failed to save AI Configuration, reason: ${
|
`Failed to save AI Configuration, reason: ${
|
||||||
error?.message || "Unknown"
|
error instanceof Error ? error.message : "Unknown"
|
||||||
}`
|
}`
|
||||||
)
|
)
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -80,7 +83,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteConfig(key) {
|
async function deleteConfig(key: string) {
|
||||||
// We don't store the default BB AI config in the DB
|
// We don't store the default BB AI config in the DB
|
||||||
delete fullAIConfig.config.budibase_ai
|
delete fullAIConfig.config.budibase_ai
|
||||||
// Delete the configuration
|
// Delete the configuration
|
||||||
|
@ -91,14 +94,16 @@
|
||||||
notifications.success(`Deleted config`)
|
notifications.success(`Deleted config`)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
notifications.error(
|
notifications.error(
|
||||||
`Failed to delete config, reason: ${error?.message || "Unknown"}`
|
`Failed to delete config, reason: ${
|
||||||
|
error instanceof Error ? error.message : "Unknown"
|
||||||
|
}`
|
||||||
)
|
)
|
||||||
} finally {
|
} finally {
|
||||||
await fetchAIConfig()
|
await fetchAIConfig()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function editConfig(uuid) {
|
function editConfig(uuid: string) {
|
||||||
editingUuid = uuid
|
editingUuid = uuid
|
||||||
editingAIConfig = fullAIConfig?.config[editingUuid]
|
editingAIConfig = fullAIConfig?.config[editingUuid]
|
||||||
modal.show()
|
modal.show()
|
||||||
|
@ -136,7 +141,10 @@
|
||||||
</Tags>
|
</Tags>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<Body>Configure your AI settings within this section:</Body>
|
<Body
|
||||||
|
>Connect an LLM to enable AI features. You can only enable one LLM at a
|
||||||
|
time.</Body
|
||||||
|
>
|
||||||
</Layout>
|
</Layout>
|
||||||
<Divider />
|
<Divider />
|
||||||
<div style={`opacity: ${customAIConfigsEnabled ? 1 : 0.5}`}>
|
<div style={`opacity: ${customAIConfigsEnabled ? 1 : 0.5}`}>
|
||||||
|
|
Loading…
Reference in New Issue