Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/api/models/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from starlette.concurrency import run_in_threadpool

from api.models.base import BaseChatModel, BaseEmbeddingsModel
from api.models.model_manager import ModelManager
from api.schema import (
AssistantMessage,
ChatRequest,
Expand Down Expand Up @@ -173,22 +174,21 @@ def list_bedrock_models() -> dict:
return model_list


# Initialize the model list.
bedrock_model_list = list_bedrock_models()


class BedrockModel(BaseChatModel):
def __init__(self):
"""Instantiate with initial model grouping."""
self._model_manager = ModelManager()
[self._model_manager.add_model({k: v}) for k,v in list_bedrock_models().items()]

def list_models(self) -> list[str]:
"""Always refresh the latest model list"""
global bedrock_model_list
bedrock_model_list = list_bedrock_models()
return list(bedrock_model_list.keys())
return self._model_manager.model_keys

def validate(self, chat_request: ChatRequest):
"""Perform basic validation on requests"""
error = ""
# check if model is supported
if chat_request.model not in bedrock_model_list.keys():
if chat_request.model not in self._model_manager.model_keys:
error = f"Unsupported model {chat_request.model}, please use models API to get a list of supported models"
logger.error("Unsupported model: %s", chat_request.model)

Expand Down Expand Up @@ -575,6 +575,10 @@ def _parse_request(self, chat_request: ChatRequest) -> dict:
if chat_request.extra_body:
# reasoning_config will not be used
args["additionalModelRequestFields"] = chat_request.extra_body

# Add user
args["session_id"] = chat_request.session_id

return args

def _create_response(
Expand Down
Loading