1
0
Fork 0
mirror of synced 2024-09-20 03:08:18 +12:00

review comments

This commit is contained in:
Martin McKeaveney 2024-09-10 10:54:50 +01:00
parent 8b26ab422f
commit 4fed5787ac
4 changed files with 18 additions and 17 deletions

View file

@ -6,6 +6,13 @@
import TogetherAILogo from "./logos/TogetherAI.svelte"
import { Providers } from "./constants"
const logos = {
["Budibase AI"]: BudibaseLogo,
[Providers.OpenAI.name]: OpenAILogo,
[Providers.Anthropic.name]: AnthropicLogo,
[Providers.TogetherAI.name]: TogetherAILogo,
}
export let config
export let disabled
@ -17,15 +24,7 @@
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div on:click class:disabled class="option">
<div class="icon">
{#if config.name === "Budibase AI"}
<BudibaseLogo height="30" width="30" />
{:else if config.provider === Providers.OpenAI.name}
<OpenAILogo height="30" width="30" />
{:else if config.provider === Providers.Anthropic.name}
<AnthropicLogo height="30" width="30" />
{:else if config.provider === Providers.TogetherAI.name}
<TogetherAILogo height="30" width="30" />
{/if}
<svelte:component this={logos[config.name || config.provider]} height="30" width="30" />
</div>
<div class="header">
<Body>{config.provider}</Body>

View file

@ -69,13 +69,14 @@
try {
await API.saveConfig(fullAIConfig)
notifications.success(`Successfully saved and activated AI Configuration`)
await fetchAIConfig()
} catch (error) {
notifications.error(
`Failed to save AI Configuration, reason: ${
error?.message || "Unknown"
}`
)
} finally {
await fetchAIConfig()
}
}
@ -88,11 +89,12 @@
try {
await API.saveConfig(fullAIConfig)
notifications.success(`Deleted config`)
await fetchAIConfig()
} catch (error) {
notifications.error(
`Failed to delete config, reason: ${error?.message || "Unknown"}`
)
} finally {
await fetchAIConfig()
}
}

View file

@ -211,10 +211,8 @@ async function verifyOIDCConfig(config: OIDCConfigs) {
export async function verifyAIConfig(
config: AIConfig,
existingConfig?: AIConfig
existingConfig: AIConfig
) {
if (!existingConfig) return
// ensure that the redacted API keys are not overwritten in the DB
for (let uuid in existingConfig.config) {
if (config[uuid]?.apiKey === PASSWORD_REPLACEMENT) {
@ -251,7 +249,9 @@ export async function save(ctx: UserCtx<Config>) {
await verifyOIDCConfig(config)
break
case ConfigType.AI:
await verifyAIConfig(config, existingConfig)
if (existingConfig) {
await verifyAIConfig(config, existingConfig)
}
break
}
} catch (err: any) {

View file

@ -45,7 +45,7 @@ describe("Global configs controller", () => {
})
it("Should return the default BB AI config when the feature is turned on", async () => {
pro.features.isBudibaseAIEnabled = jest.fn(() => true)
jest.spyOn(pro.features, "isBudibaseAIEnabled").mockImplementation(() => true)
configs.getConfig.mockResolvedValue({
config: {
ai: {
@ -81,7 +81,7 @@ describe("Global configs controller", () => {
})
it("Should not not return the default Budibase AI config when on self host", async () => {
pro.features.isBudibaseAIEnabled = jest.fn(() => false)
jest.spyOn(pro.features, "isBudibaseAIEnabled").mockImplementation(() => false)
configs.getConfig.mockResolvedValue({
config: {
ai: {