fix: resolve empty API keys to None and add Bedrock model support (#10573)

This commit is contained in:
Joe Axe 2025-09-08 13:45:10 +01:00 committed by GitHub
parent df9320f8ab
commit a25826a5f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 7 deletions

View File

@ -479,11 +479,10 @@ async def modify_llm_settings_basic(
settings = Settings()
settings.llm_model = f'{provider}{organized_models[provider]["separator"]}{model}'
settings.llm_api_key = SecretStr(api_key)
settings.llm_api_key = SecretStr(api_key) if api_key and api_key.strip() else None
settings.llm_base_url = None
settings.agent = OH_DEFAULT_AGENT
settings.enable_default_condenser = True
await settings_store.store(settings)
@ -608,12 +607,11 @@ async def modify_llm_settings_advanced(
settings = Settings()
settings.llm_model = custom_model
settings.llm_api_key = SecretStr(api_key)
settings.llm_api_key = SecretStr(api_key) if api_key and api_key.strip() else None
settings.llm_base_url = base_url
settings.agent = agent
settings.confirmation_mode = enable_confirmation_mode
settings.enable_default_condenser = enable_memory_condensation
await settings_store.store(settings)
@ -685,5 +683,4 @@ async def modify_search_api_settings(
settings = Settings()
settings.search_api_key = SecretStr(search_api_key) if search_api_key else None
await settings_store.store(settings)

View File

@ -105,7 +105,10 @@ async def start_conversation(
session_init_args = {**settings.__dict__, **session_init_args}
# We could use litellm.check_valid_key for a more accurate check,
# but that would run a tiny inference.
if (
model_name = settings.llm_model or ''
is_bedrock_model = model_name.startswith('bedrock/')
if not is_bedrock_model and (
not settings.llm_api_key
or settings.llm_api_key.get_secret_value().isspace()
):
@ -113,6 +116,8 @@ async def start_conversation(
raise LLMAuthenticationError(
'Error authenticating with the LLM provider. Please check your API key'
)
elif is_bedrock_model:
logger.info(f'Bedrock model detected ({model_name}), API key not required')
else:
logger.warning('Settings not present, not starting conversation')

View File

@ -63,9 +63,14 @@ class Settings(BaseModel):
if api_key is None:
return None
# Get the secret value to check if it's empty
secret_value = api_key.get_secret_value()
if not secret_value or not secret_value.strip():
return None
context = info.context
if context and context.get('expose_secrets', False):
return api_key.get_secret_value()
return secret_value
return pydantic_encoder(api_key)