Commit ab635c6b authored by Your Name's avatar Your Name

Fix deprecated get_database() call and dict config access errors

parent a5210aaa
...@@ -1004,9 +1004,14 @@ def get_context_config_for_model( ...@@ -1004,9 +1004,14 @@ def get_context_config_for_model(
# Step 1: Get provider-level defaults and model-specific config # Step 1: Get provider-level defaults and model-specific config
model_specific_config = None model_specific_config = None
if provider_config: if provider_config:
# Try to find model-specific config in provider # Handle both dict (user) and object (global) config formats
if hasattr(provider_config, 'models') and provider_config.models: if isinstance(provider_config, dict):
for model in provider_config.models: models = provider_config.get('models', [])
else:
models = provider_config.models if hasattr(provider_config, 'models') else []
if models:
for model in models:
# Handle both Pydantic objects and dictionaries # Handle both Pydantic objects and dictionaries
model_name_value = model.name if hasattr(model, 'name') else model.get('name') model_name_value = model.name if hasattr(model, 'name') else model.get('name')
if model_name_value == model_name: if model_name_value == model_name:
......
...@@ -124,8 +124,8 @@ class KiloProviderHandler(BaseProviderHandler): ...@@ -124,8 +124,8 @@ class KiloProviderHandler(BaseProviderHandler):
# Regular user: ONLY use database credentials, NO file fallback # Regular user: ONLY use database credentials, NO file fallback
try: try:
from ..database import get_database from ..database import DatabaseRegistry
db = get_database() db = DatabaseRegistry.get_config_database()
if db: if db:
db_creds = db.get_user_oauth2_credentials( db_creds = db.get_user_oauth2_credentials(
user_id=self.user_id, user_id=self.user_id,
......
...@@ -168,8 +168,14 @@ def get_max_request_tokens_for_model( ...@@ -168,8 +168,14 @@ def get_max_request_tokens_for_model(
return max_tokens return max_tokens
# Then check provider models config # Then check provider models config
if hasattr(provider_config, 'models') and provider_config.models: # Handle both dict (user) and object (global) config formats
for model in provider_config.models: if isinstance(provider_config, dict):
models = provider_config.get('models', [])
else:
models = provider_config.models if hasattr(provider_config, 'models') else []
if models:
for model in models:
# Handle both Pydantic objects and dictionaries # Handle both Pydantic objects and dictionaries
model_name_value = model.name if hasattr(model, 'name') else model.get('name') model_name_value = model.name if hasattr(model, 'name') else model.get('name')
if model_name_value == model_name: if model_name_value == model_name:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment