Skip to content

Commit

Permalink
added aws bedrock
Browse files Browse the repository at this point in the history
  • Loading branch information
George Burton committed Sep 3, 2024
1 parent e0d9bc6 commit 8af8c3e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
4 changes: 3 additions & 1 deletion django_app/redbox_app/redbox_core/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,12 @@ def file_save(file):
@staticmethod
@database_sync_to_async
def get_ai_settings(user: User) -> AISettings:
return model_to_dict(
ai_settings = model_to_dict(
user.ai_settings,
fields=[field.name for field in user.ai_settings._meta.fields if field.name != "label"], # noqa: SLF001
)
ai_settings["chat_backend"] = "anthropic.claude-3-sonnet-20240229-v1:0"
return ai_settings


class CoreError(Exception):
Expand Down
39 changes: 20 additions & 19 deletions redbox-core/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions redbox-core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ langchain-elasticsearch = "^0.2.2"
pytest-dotenv = "^0.5.2"
kneed = "^0.8.5"
langgraph = "^0.2.3"
langchain-aws = "^0.1.17"


[tool.poetry.group.dev.dependencies]
Expand Down
5 changes: 5 additions & 0 deletions redbox-core/redbox/chains/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from langchain_openai.embeddings import AzureOpenAIEmbeddings, OpenAIEmbeddings
from langchain_core.utils import convert_to_secret_str
import tiktoken
from langchain_aws import ChatBedrock

from redbox.models.chain import AISettings
from redbox.models.settings import Settings
Expand Down Expand Up @@ -71,6 +72,10 @@ def get_chat_llm(env: Settings, ai_settings: AISettings):
)
]
)
elif ai_settings.chat_backend == "anthropic.claude-3-sonnet-20240229-v1:0":
chat_model = ChatBedrock(
model_id="anthropic.claude-3-sonnet-20240229-v1:0",
)
if chat_model is None:
raise Exception("%s not recognised", ai_settings.chat_backend)
else:
Expand Down
5 changes: 3 additions & 2 deletions redbox-core/redbox/models/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ class AISettings(BaseModel):
knn_boost: int = 1
similarity_threshold: int = 0

# this is also the azure_openai_model
chat_backend: Literal["gpt-35-turbo-16k", "gpt-4-turbo-2024-04-09", "gpt-4o"] = "gpt-4o"
chat_backend: Literal[
"gpt-35-turbo-16k", "gpt-4-turbo-2024-04-09", "gpt-4o", "anthropic.claude-3-sonnet-20240229-v1:0"
] = "gpt-4o"


class DocumentState(TypedDict):
Expand Down

0 comments on commit 8af8c3e

Please sign in to comment.