Skip to content

Commit

Permalink
feat: support python 3.13 (#2176)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahwooders authored Dec 11, 2024
1 parent 470f95a commit d0dbb9d
Show file tree
Hide file tree
Showing 8 changed files with 369 additions and 641 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code_style_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
poetry-version: "1.8.2"
install-args: "-E dev -E postgres -E milvus -E external-tools -E tests" # Adjust as necessary
install-args: "-E dev -E postgres -E external-tools -E tests" # Adjust as necessary

- name: Validate PR Title
if: github.event_name == 'pull_request'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
with:
python-version: "3.12"
poetry-version: "1.8.2"
install-args: "-E dev -E postgres -E milvus -E external-tools -E tests -E cloud-tool-sandbox"
install-args: "-E dev -E postgres -E external-tools -E tests -E cloud-tool-sandbox"
- name: Migrate database
env:
LETTA_PG_PORT: 5432
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-pip-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"] # Adjust Python versions as needed
python-version: ["3.10", "3.11", "3.12", "3.13"] # Adjust Python versions as needed

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_ollama.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
with:
python-version: "3.12"
poetry-version: "1.8.2"
install-args: "-E dev -E ollama"
install-args: "-E dev"

- name: Test LLM Endpoint
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
with:
python-version: "3.12"
poetry-version: "1.8.2"
install-args: "-E dev -E postgres -E milvus -E external-tools -E tests"
install-args: "-E dev -E postgres -E external-tools -E tests"
- name: Migrate database
env:
LETTA_PG_PORT: 5432
Expand Down Expand Up @@ -113,7 +113,7 @@ jobs:
with:
python-version: "3.12"
poetry-version: "1.8.2"
install-args: "-E dev -E postgres -E milvus -E external-tools -E tests -E cloud-tool-sandbox"
install-args: "-E dev -E postgres -E external-tools -E tests -E cloud-tool-sandbox"
- name: Migrate database
env:
LETTA_PG_PORT: 5432
Expand Down
38 changes: 29 additions & 9 deletions letta/embeddings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import uuid
from typing import Any, List, Optional

Expand Down Expand Up @@ -141,14 +140,35 @@ def get_text_embedding(self, text: str):
return embeddings


def default_embedding_model():
# default to hugging face model running local
# warning: this is a terrible model
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
class OllamaEmbeddings:

os.environ["TOKENIZERS_PARALLELISM"] = "False"
model = "BAAI/bge-small-en-v1.5"
return HuggingFaceEmbedding(model_name=model)
# Format:
# curl http://localhost:11434/api/embeddings -d '{
# "model": "mxbai-embed-large",
# "prompt": "Llamas are members of the camelid family"
# }'

def __init__(self, model: str, base_url: str, ollama_additional_kwargs: dict):
self.model = model
self.base_url = base_url
self.ollama_additional_kwargs = ollama_additional_kwargs

def get_text_embedding(self, text: str):
import httpx

headers = {"Content-Type": "application/json"}
json_data = {"model": self.model, "prompt": text}
json_data.update(self.ollama_additional_kwargs)

with httpx.Client() as client:
response = client.post(
f"{self.base_url}/api/embeddings",
headers=headers,
json=json_data,
)

response_json = response.json()
return response_json["embedding"]


def query_embedding(embedding_model, query_text: str):
Expand Down Expand Up @@ -228,4 +248,4 @@ def embedding_model(config: EmbeddingConfig, user_id: Optional[uuid.UUID] = None
return model

else:
return default_embedding_model()
raise ValueError(f"Unknown endpoint type {endpoint_type}")
933 changes: 323 additions & 610 deletions poetry.lock

Large diffs are not rendered by default.

27 changes: 11 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ readme = "README.md"
letta = "letta.main:app"

[tool.poetry.dependencies]
python = "<3.13,>=3.10"
python = "<4.0,>=3.10"
typer = {extras = ["all"], version = "^0.9.0"}
questionary = "^2.0.1"
pytz = "^2023.3.post1"
Expand All @@ -29,23 +29,21 @@ pre-commit = {version = "^3.5.0", optional = true }
pg8000 = {version = "^1.30.3", optional = true}
websockets = {version = "^12.0", optional = true}
docstring-parser = ">=0.16,<0.17"
httpx = "^0.27.2"
httpx = "^0.28.0"
numpy = "^1.26.2"
demjson3 = "^3.0.6"
#tiktoken = ">=0.7.0,<0.8.0"
pyyaml = "^6.0.1"
sqlalchemy-json = "^0.7.0"
fastapi = {version = "^0.104.1", optional = true}
fastapi = { version = "^0.115.6", optional = true}
uvicorn = {version = "^0.24.0.post1", optional = true}
pydantic = ">=2.7.4,<2.10.0"
pyautogen = {version = "0.2.22", optional = true}
html2text = "^2020.1.16"
docx2txt = "^0.8"
sqlalchemy = "^2.0.25"
pexpect = {version = "^4.9.0", optional = true}
pyright = {version = "^1.1.347", optional = true}
qdrant-client = {version="^1.9.1", optional = true}
pymilvus = {version ="^2.4.3", optional = true}
#pymilvus = {version ="^2.4.3", optional = true}
python-box = "^7.1.1"
sqlmodel = "^0.0.16"
autoflake = {version = "^2.3.0", optional = true}
Expand All @@ -57,35 +55,32 @@ pydantic-settings = "^2.2.1"
httpx-sse = "^0.4.0"
isort = { version = "^5.13.2", optional = true }
docker = {version = "^7.1.0", optional = true}
tiktoken = "^0.7.0"
nltk = "^3.8.1"
jinja2 = "^3.1.4"
locust = {version = "^2.31.5", optional = true}
llama-index = "^0.11.9"
llama-index-embeddings-openai = "^0.2.5"
llama-index-embeddings-ollama = "^0.3.1"
wikipedia = {version = "^1.4.0", optional = true}
composio-langchain = "^0.5.28"
composio-core = "^0.5.51"
alembic = "^1.13.3"
pyhumps = "^3.8.0"
psycopg2 = {version = "^2.9.10", optional = true}
psycopg2-binary = {version = "^2.9.10", optional = true}
e2b-code-interpreter = {version = "^1.0.1", optional = true}
pathvalidate = "^3.2.1"
langchain-community = {version = "^0.3.7", optional = true}
langchain = {version = "^0.3.7", optional = true}
sentry-sdk = {extras = ["fastapi"], version = "2.19.1"}
brotli = "^1.1.0"
grpcio = "^1.68.1"
grpcio-tools = "^1.68.1"
llama-index = "^0.12.2"
llama-index-embeddings-openai = "^0.3.1"
e2b-code-interpreter = {version = "^1.0.3", optional = true}

[tool.poetry.extras]
#local = ["llama-index-embeddings-huggingface"]
postgres = ["pgvector", "pg8000", "psycopg2-binary", "psycopg2"]
milvus = ["pymilvus"]
dev = ["pytest", "pytest-asyncio", "pexpect", "black", "pre-commit", "datasets", "pyright", "pytest-order", "autoflake", "isort", "locust"]
server = ["websockets", "fastapi", "uvicorn"]
autogen = ["pyautogen"]
qdrant = ["qdrant-client"]
ollama = ["llama-index-embeddings-ollama"]
cloud-tool-sandbox = ["e2b-code-interpreter"]
external-tools = ["docker", "langchain", "wikipedia", "langchain-community"]
tests = ["wikipedia"]
Expand All @@ -98,7 +93,7 @@ ipdb = "^0.13.13"

[tool.black]
line-length = 140
target-version = ['py310', 'py311']
target-version = ['py310', 'py311', 'py312', 'py313']
extend-exclude = "examples/*"

[build-system]
Expand Down

0 comments on commit d0dbb9d

Please sign in to comment.