diff --git a/backend/danswer/llm/options.py b/backend/danswer/llm/options.py index dd06615fb8de..c9f9779d8e5f 100644 --- a/backend/danswer/llm/options.py +++ b/backend/danswer/llm/options.py @@ -2,13 +2,20 @@ import litellm # type: ignore from pydantic import BaseModel +class CustomConfigKey(BaseModel): + name: str + description: str | None = None + is_required: bool = True + is_secret: bool = False + + class WellKnownLLMProviderDescriptor(BaseModel): name: str display_name: str | None = None api_key_required: bool api_base_required: bool api_version_required: bool - custom_config_keys: list[str] | None = None + custom_config_keys: list[CustomConfigKey] | None = None llm_names: list[str] default_model: str | None = None @@ -96,9 +103,18 @@ def fetch_available_well_known_llms() -> list[WellKnownLLMProviderDescriptor]: api_base_required=False, api_version_required=False, custom_config_keys=[ - "AWS_ACCESS_KEY_ID", - "AWS_SECRET_ACCESS_KEY", - "AWS_REGION_NAME", + CustomConfigKey(name="AWS_REGION_NAME"), + CustomConfigKey( + name="AWS_ACCESS_KEY_ID", + is_required=False, + description="If using AWS IAM roles, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY can be left blank.", + ), + CustomConfigKey( + name="AWS_SECRET_ACCESS_KEY", + is_required=False, + is_secret=True, + description="If using AWS IAM roles, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY can be left blank.", + ), ], llm_names=fetch_models_for_provider(BEDROCK_PROVIDER_NAME), default_model="anthropic.claude-3-sonnet-20240229-v1:0", diff --git a/web/src/app/admin/models/llm/LLMProviderUpdateForm.tsx b/web/src/app/admin/models/llm/LLMProviderUpdateForm.tsx index 9b9b55d01876..6dfa863b427b 100644 --- a/web/src/app/admin/models/llm/LLMProviderUpdateForm.tsx +++ b/web/src/app/admin/models/llm/LLMProviderUpdateForm.tsx @@ -50,8 +50,8 @@ export function LLMProviderUpdateForm({ custom_config: existingLlmProvider?.custom_config ?? llmProviderDescriptor.custom_config_keys?.reduce( - (acc, key) => { - acc[key] = ""; + (acc, customConfigKey) => { + acc[customConfigKey.name] = ""; return acc; }, {} as { [key: string]: string } @@ -77,8 +77,12 @@ export function LLMProviderUpdateForm({ ? { custom_config: Yup.object( llmProviderDescriptor.custom_config_keys.reduce( - (acc, key) => { - acc[key] = Yup.string().required(`${key} is required`); + (acc, customConfigKey) => { + if (customConfigKey.is_required) { + acc[customConfigKey.name] = Yup.string().required( + `${customConfigKey.name} is required` + ); + } return acc; }, {} as { [key: string]: Yup.StringSchema } @@ -205,9 +209,17 @@ export function LLMProviderUpdateForm({ /> )} - {llmProviderDescriptor.custom_config_keys?.map((key) => ( -
- + {llmProviderDescriptor.custom_config_keys?.map((customConfigKey) => ( +
+
))} diff --git a/web/src/app/admin/models/llm/interfaces.ts b/web/src/app/admin/models/llm/interfaces.ts index 1f40bbf5e13d..7b7609826b9f 100644 --- a/web/src/app/admin/models/llm/interfaces.ts +++ b/web/src/app/admin/models/llm/interfaces.ts @@ -1,3 +1,10 @@ +export interface CustomConfigKey { + name: string; + description: string | null; + is_required: boolean; + is_secret: boolean; +} + export interface WellKnownLLMProviderDescriptor { name: string; display_name: string | null; @@ -5,7 +12,7 @@ export interface WellKnownLLMProviderDescriptor { api_key_required: boolean; api_base_required: boolean; api_version_required: boolean; - custom_config_keys: string[] | null; + custom_config_keys: CustomConfigKey[] | null; llm_names: string[]; default_model: string | null;