From d00873c357a6db1990930486255acdfecfbc5894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20G=C3=B3is?= Date: Thu, 10 Oct 2024 09:43:14 +0100 Subject: [PATCH] chore: add OpenAI API key configuration (#8400) https://linear.app/unleash/issue/2-2787/add-openai-api-key-to-our-configuration Adds the OpenAI API key to our configuration and exposes a new `unleashAIAvailable` boolean in our UI config to let our frontend know that we have configured this. This can be used together with our flag to decide whether we should enable our experiment for our users. --- frontend/src/interfaces/uiConfig.ts | 1 + src/lib/__snapshots__/create-config.test.ts.snap | 1 + src/lib/create-config.ts | 3 +++ src/lib/openapi/spec/ui-config-schema.ts | 5 +++++ src/lib/routes/admin-api/config.ts | 1 + src/lib/types/option.ts | 1 + 6 files changed, 12 insertions(+) diff --git a/frontend/src/interfaces/uiConfig.ts b/frontend/src/interfaces/uiConfig.ts index 235908e77d..a627e8895e 100644 --- a/frontend/src/interfaces/uiConfig.ts +++ b/frontend/src/interfaces/uiConfig.ts @@ -32,6 +32,7 @@ export interface IUiConfig { resourceLimits: ResourceLimitsSchema; oidcConfiguredThroughEnv?: boolean; samlConfiguredThroughEnv?: boolean; + unleashAIAvailable?: boolean; } export interface IProclamationToast { diff --git a/src/lib/__snapshots__/create-config.test.ts.snap b/src/lib/__snapshots__/create-config.test.ts.snap index f6d302a676..4abee2e5d4 100644 --- a/src/lib/__snapshots__/create-config.test.ts.snap +++ b/src/lib/__snapshots__/create-config.test.ts.snap @@ -94,6 +94,7 @@ exports[`should create default config 1`] = ` "frontendMetricsMaxPerMinute": 6000, "frontendRegisterMaxPerMinute": 6000, }, + "openAIAPIKey": undefined, "preHook": undefined, "preRouterHook": undefined, "prometheusApi": undefined, diff --git a/src/lib/create-config.ts b/src/lib/create-config.ts index e6d49d5f34..c3550efd9b 100644 --- a/src/lib/create-config.ts +++ b/src/lib/create-config.ts @@ -711,6 +711,8 @@ export function createConfig(options: IUnleashOptions): IUnleashConfig { ), }; + const openAIAPIKey = process.env.OPENAI_API_KEY; + return { db, session, @@ -749,6 +751,7 @@ export function createConfig(options: IUnleashOptions): IUnleashConfig { rateLimiting, feedbackUriPath, dailyMetricsStorageDays, + openAIAPIKey, }; } diff --git a/src/lib/openapi/spec/ui-config-schema.ts b/src/lib/openapi/spec/ui-config-schema.ts index c8f18b0dd2..2f1e519a4a 100644 --- a/src/lib/openapi/spec/ui-config-schema.ts +++ b/src/lib/openapi/spec/ui-config-schema.ts @@ -180,6 +180,11 @@ export const uiConfigSchema = { 'Whether the SAML configuration is set through environment variables or not.', example: false, }, + unleashAIAvailable: { + type: 'boolean', + description: 'Whether Unleash AI is available.', + example: false, + }, }, components: { schemas: { diff --git a/src/lib/routes/admin-api/config.ts b/src/lib/routes/admin-api/config.ts index 4d2f80bfe9..8c9cad80b6 100644 --- a/src/lib/routes/admin-api/config.ts +++ b/src/lib/routes/admin-api/config.ts @@ -152,6 +152,7 @@ class ConfigController extends Controller { disablePasswordAuth, maintenanceMode, feedbackUriPath: this.config.feedbackUriPath, + unleashAIAvailable: this.config.openAIAPIKey !== undefined, }; this.openApiService.respondWithValidation( diff --git a/src/lib/types/option.ts b/src/lib/types/option.ts index 0812756060..2f265eb121 100644 --- a/src/lib/types/option.ts +++ b/src/lib/types/option.ts @@ -273,4 +273,5 @@ export interface IUnleashConfig { isEnterprise: boolean; rateLimiting: IRateLimiting; feedbackUriPath?: string; + openAIAPIKey?: string; }