review comments
This commit is contained in:
parent
8b26ab422f
commit
4fed5787ac
|
@ -6,6 +6,13 @@
|
||||||
import TogetherAILogo from "./logos/TogetherAI.svelte"
|
import TogetherAILogo from "./logos/TogetherAI.svelte"
|
||||||
import { Providers } from "./constants"
|
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 config
|
||||||
export let disabled
|
export let disabled
|
||||||
|
|
||||||
|
@ -17,15 +24,7 @@
|
||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
<div on:click class:disabled class="option">
|
<div on:click class:disabled class="option">
|
||||||
<div class="icon">
|
<div class="icon">
|
||||||
{#if config.name === "Budibase AI"}
|
<svelte:component this={logos[config.name || config.provider]} height="30" width="30" />
|
||||||
<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}
|
|
||||||
</div>
|
</div>
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<Body>{config.provider}</Body>
|
<Body>{config.provider}</Body>
|
||||||
|
|
|
@ -69,13 +69,14 @@
|
||||||
try {
|
try {
|
||||||
await API.saveConfig(fullAIConfig)
|
await API.saveConfig(fullAIConfig)
|
||||||
notifications.success(`Successfully saved and activated AI Configuration`)
|
notifications.success(`Successfully saved and activated AI Configuration`)
|
||||||
await fetchAIConfig()
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
notifications.error(
|
notifications.error(
|
||||||
`Failed to save AI Configuration, reason: ${
|
`Failed to save AI Configuration, reason: ${
|
||||||
error?.message || "Unknown"
|
error?.message || "Unknown"
|
||||||
}`
|
}`
|
||||||
)
|
)
|
||||||
|
} finally {
|
||||||
|
await fetchAIConfig()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,11 +89,12 @@
|
||||||
try {
|
try {
|
||||||
await API.saveConfig(fullAIConfig)
|
await API.saveConfig(fullAIConfig)
|
||||||
notifications.success(`Deleted config`)
|
notifications.success(`Deleted config`)
|
||||||
await fetchAIConfig()
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
notifications.error(
|
notifications.error(
|
||||||
`Failed to delete config, reason: ${error?.message || "Unknown"}`
|
`Failed to delete config, reason: ${error?.message || "Unknown"}`
|
||||||
)
|
)
|
||||||
|
} finally {
|
||||||
|
await fetchAIConfig()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -211,10 +211,8 @@ async function verifyOIDCConfig(config: OIDCConfigs) {
|
||||||
|
|
||||||
export async function verifyAIConfig(
|
export async function verifyAIConfig(
|
||||||
config: AIConfig,
|
config: AIConfig,
|
||||||
existingConfig?: AIConfig
|
existingConfig: AIConfig
|
||||||
) {
|
) {
|
||||||
if (!existingConfig) return
|
|
||||||
|
|
||||||
// ensure that the redacted API keys are not overwritten in the DB
|
// ensure that the redacted API keys are not overwritten in the DB
|
||||||
for (let uuid in existingConfig.config) {
|
for (let uuid in existingConfig.config) {
|
||||||
if (config[uuid]?.apiKey === PASSWORD_REPLACEMENT) {
|
if (config[uuid]?.apiKey === PASSWORD_REPLACEMENT) {
|
||||||
|
@ -251,7 +249,9 @@ export async function save(ctx: UserCtx<Config>) {
|
||||||
await verifyOIDCConfig(config)
|
await verifyOIDCConfig(config)
|
||||||
break
|
break
|
||||||
case ConfigType.AI:
|
case ConfigType.AI:
|
||||||
await verifyAIConfig(config, existingConfig)
|
if (existingConfig) {
|
||||||
|
await verifyAIConfig(config, existingConfig)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
|
|
|
@ -45,7 +45,7 @@ describe("Global configs controller", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Should return the default BB AI config when the feature is turned on", async () => {
|
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({
|
configs.getConfig.mockResolvedValue({
|
||||||
config: {
|
config: {
|
||||||
ai: {
|
ai: {
|
||||||
|
@ -81,7 +81,7 @@ describe("Global configs controller", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Should not not return the default Budibase AI config when on self host", async () => {
|
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({
|
configs.getConfig.mockResolvedValue({
|
||||||
config: {
|
config: {
|
||||||
ai: {
|
ai: {
|
||||||
|
|
Loading…
Reference in New Issue