Make access key and secret optional for AWS Bedrock

This commit is contained in:
Weves
2024-05-07 01:08:19 -07:00
committed by Chris Weaver
parent 45d5d7af4a
commit d6522426c9
3 changed files with 47 additions and 12 deletions

View File

@@ -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",

View File

@@ -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) => (
<div key={key}>
<TextFormField name={`custom_config.${key}`} label={key} />
{llmProviderDescriptor.custom_config_keys?.map((customConfigKey) => (
<div key={customConfigKey.name}>
<TextFormField
name={`custom_config.${customConfigKey.name}`}
label={
customConfigKey.is_required
? customConfigKey.name
: `[Optional] ${customConfigKey.name}`
}
subtext={customConfigKey.description || undefined}
/>
</div>
))}

View File

@@ -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;