generated from childmindresearch/template-python-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Move LLM functionality to cloai (#160)
* refactor: Move LLM functionality to cloai * refactor: Move LLM functionality to cloai # Conflicts: # src/ctk_functions/microservices/aws.py # src/ctk_functions/microservices/azure.py # src/ctk_functions/microservices/llm.py * remove qodana.yaml * various fixes for cloai * fix: mypy issues * chore: Cleanup
- Loading branch information
1 parent
4d5b0b7
commit 82f73f9
Showing
27 changed files
with
98 additions
and
621 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
qodana.yaml | ||
.idea | ||
~* | ||
.ruff_cache | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"""Large Language Model client creation.""" | ||
|
||
from typing import Literal, TypeGuard, get_args | ||
|
||
import cloai | ||
from cloai.llm import bedrock | ||
|
||
from ctk_functions.core import config | ||
|
||
settings = config.get_settings() | ||
|
||
VALID_MODELS = Literal[ | ||
"anthropic.claude-3-opus-20240229-v1:0", | ||
"anthropic.claude-3-5-sonnet-20240620-v1:0", | ||
"anthropic.claude-3-5-sonnet-20241022-v2:0", | ||
"gpt-4o", | ||
] | ||
|
||
|
||
def get_llm(model: str) -> cloai.LargeLanguageModel: | ||
"""Gets the LLM client. | ||
Args: | ||
model: Model name to use. | ||
Returns: | ||
The client for the large language model. | ||
""" | ||
if _is_anthropic_bedrock_model(model): | ||
client = cloai.AnthropicBedrockLlm( | ||
model=model, | ||
aws_access_key=settings.AWS_ACCESS_KEY_ID.get_secret_value(), | ||
aws_secret_key=settings.AWS_SECRET_ACCESS_KEY.get_secret_value(), | ||
region=settings.AWS_REGION, | ||
) | ||
else: | ||
client = cloai.AzureLlm( | ||
deployment=settings.AZURE_OPENAI_LLM_DEPLOYMENT.get_secret_value(), | ||
endpoint=settings.AZURE_OPENAI_ENDPOINT.get_secret_value(), | ||
api_key=settings.AZURE_OPENAI_API_KEY.get_secret_value(), | ||
api_version="2024-02-01", | ||
) | ||
return cloai.LargeLanguageModel(client=client) | ||
|
||
|
||
def _is_anthropic_bedrock_model( | ||
model: str, | ||
) -> TypeGuard[bedrock.ANTHROPIC_BEDROCK_MODELS]: | ||
return model in get_args(bedrock.ANTHROPIC_BEDROCK_MODELS) |
Oops, something went wrong.