Skip to content

Commit

Permalink
refactor: Move LLM functionality to cloai (#160)
Browse files Browse the repository at this point in the history
* 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
ReinderVosDeWael authored Dec 27, 2024
1 parent 4d5b0b7 commit 82f73f9
Show file tree
Hide file tree
Showing 27 changed files with 98 additions and 621 deletions.
6 changes: 0 additions & 6 deletions .funcignore

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
qodana.yaml
.idea
~*
.ruff_cache
Expand Down
7 changes: 0 additions & 7 deletions function_app.py

This file was deleted.

20 changes: 0 additions & 20 deletions host.json

This file was deleted.

7 changes: 0 additions & 7 deletions local.settings.json

This file was deleted.

8 changes: 2 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,19 @@ requires-python = ">=3.11, <3.12"
dependencies = [
"aiofiles>=24.1.0",
"aiohttp>=3.11.11",
"azure-functions>=1.21.3",
"cmi-docx>=0.3.7",
"fastapi[standard]>=0.115.6",
"jsonpickle>=4.0.1",
"language-tool-python>=2.8.1",
"openai>=0.27.10",
"pycap>=2.6.0",
"pydantic>=2.10.4",
"pydantic-settings>=2.7.0",
"pypandoc-binary>=1.14",
"python-dateutil>=2.9.0.post0",
"pytz>=2024.2",
"instructor[anthropic]>1.6",
"anthropic[bedrock]>=0.37.1",
"spacy>=3.8.3",
"en-core-web-sm",
"httpx==0.27"
"cloai>=1.0.0",
"jsonpickle>=4.0.1"
]

[tool.uv]
Expand Down
34 changes: 0 additions & 34 deletions qodana.yaml

This file was deleted.

1 change: 1 addition & 0 deletions src/ctk_functions/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Settings(pydantic_settings.BaseSettings):

AWS_ACCESS_KEY_ID: pydantic.SecretStr
AWS_SECRET_ACCESS_KEY: pydantic.SecretStr
AWS_REGION: str = "us-west-2"

AZURE_OPENAI_API_KEY: pydantic.SecretStr
AZURE_OPENAI_LLM_DEPLOYMENT: pydantic.SecretStr
Expand Down
70 changes: 0 additions & 70 deletions src/ctk_functions/microservices/aws.py

This file was deleted.

70 changes: 0 additions & 70 deletions src/ctk_functions/microservices/azure.py

This file was deleted.

49 changes: 49 additions & 0 deletions src/ctk_functions/microservices/language_models.py
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)
Loading

0 comments on commit 82f73f9

Please sign in to comment.