Skip to content

Commit

Permalink
ci: add custom test and workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
carenthomas committed Feb 4, 2025
1 parent c07c4b5 commit 26fd521
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 179 deletions.
2 changes: 2 additions & 0 deletions .fernignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Specify files that shouldn't be modified by Fern

tests/custom/test_client.py
tests/custom/conftest.py
.github/workflows/ci.yml
.github/workflows/tests.yml
src/letta_client/client.py
42 changes: 42 additions & 0 deletions .github/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: ci

push:
branches: [ main ]
pull_request:

jobs:
compile:
runs-on: ubuntu-20.04
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: 3.8
- name: Bootstrap poetry
run: |
curl -sSL https://install.python-poetry.org | python - -y --version 1.5.1
- name: Install dependencies
run: poetry install
- name: Compile
run: poetry run mypy .
test:
runs-on: ubuntu-20.04
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: 3.8
- name: Bootstrap poetry
run: |
curl -sSL https://install.python-poetry.org | python - -y --version 1.5.1
- name: Install dependencies
run: poetry install

- name: Test
env:
LETTA_API_KEY: ${{ secrets.LETTA_API_KEY }}
run: poetry run pytest -rP tests/custom/test_client.py
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ jobs:
run: poetry install

- name: Test
env:
LETTA_API_KEY: ${{ secrets.LETTA_API_KEY }}
run: poetry run pytest -rP .
run: poetry run pytest -rP . --ignore=tests/custom/test_client.py

publish:
needs: [compile, test]
Expand Down
30 changes: 30 additions & 0 deletions tests/custom/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
import pytest
from typing import Generator
from letta_client import Letta, LettaEnvironment


def pytest_addoption(parser):
parser.addoption(
"--env",
default="cloud",
choices=["cloud", "localhost"],
help="Specify the Letta environment (cloud, localhost)",
)


@pytest.fixture(scope="session")
def letta_env(pytestconfig) -> LettaEnvironment:
env_map = {
"cloud": LettaEnvironment.LETTA_CLOUD,
"localhost": LettaEnvironment.SELF_HOSTED,
}
env_name = pytestconfig.getoption("env")
return env_map[env_name]


@pytest.fixture(scope="session")
def client(letta_env) -> Generator[Letta, None, None]:
api_key = os.getenv('LETTA_API_KEY')
client = Letta(environment=letta_env, token=api_key)
yield client
180 changes: 4 additions & 176 deletions tests/custom/test_client.py
Original file line number Diff line number Diff line change
@@ -1,193 +1,21 @@
'''
import os
import pytest
from typing import Generator
from letta import (
AgentState,
from letta_client import (
CreateBlock,
EmbeddingConfig,
Letta,
LettaEnvironment,
LlmConfig,
MessageCreate,
)
from letta.core.request_options import RequestOptions


@pytest.fixture(scope="session")
def client() -> Generator[Letta, None, None]:
api_key = os.getenv('LETTA_API_KEY')
if not api_key:
raise ValueError("LETTA_API_KEY environment variable must be set")
client = Letta(
environment=LettaEnvironment.LETTA_CLOUD,
token=api_key,
)
yield client
@pytest.mark.skip(reason="Temporarily skipping this test")
def test_create_agent_default(client) -> None:
agent = client.agents.create(
memory_blocks=[
CreateBlock(
value="username: caren",
label="human",
)
],
llm_config=LlmConfig(
model="gpt-4",
model_endpoint_type="openai",
model_endpoint="https://api.openai.com/v1",
model_wrapper=None,
context_window=8192,
),
embedding_config=EmbeddingConfig(
embedding_model="text-embedding-ada-002",
embedding_endpoint_type="openai",
embedding_endpoint="https://api.openai.com/v1",
embedding_dim=1536,
embedding_chunk_size=300,
),
)
assert agent is not None
agents = client.agents.list()
assert len([a for a in agents if a.id == agent.id]) == 1
client.agents.delete(agent_id=agent.id)
@pytest.mark.skip(reason="Temporarily skipping this test")
def test_create_agent_with_handle(client) -> None:
agent = client.agents.create(
memory_blocks=[
CreateBlock(
value="username: caren",
label="human",
)
],
llm="openai/gpt-4",
embedding="openai/text-embedding-ada-002",
)
assert agent is not None
agents = client.agents.list()
assert len([a for a in agents if a.id == agent.id]) == 1
client.agents.delete(agent_id=agent.id)
@pytest.mark.skip(reason="Temporarily skipping this test")
def test_create_agent_with_template(client) -> None:
agent = client.agents.create(
memory_blocks=[
CreateBlock(
value="username: caren",
label="human",
)
],
from_template="fern-testing:latest",
)
assert agent is not None
agents = client.agents.list()
assert len([a for a in agents if a.id == agent.id]) == 1
client.agents.delete(agent_id=agent.id)
@pytest.mark.skip(reason="Temporarily skipping this test")
def test_delete_agent(client) -> None:
def test_create_agent(client) -> None:
agent = client.agents.create(
memory_blocks=[
CreateBlock(
value="username: caren",
label="human",
)
],
llm="openai/gpt-4",
model="openai/gpt-4",
embedding="openai/text-embedding-ada-002",
)
assert agent is not None
agents = client.agents.list()
assert len([a for a in agents if a.id == agent.id]) == 1

client.agents.delete(agent_id=agent.id)
agents = client.agents.list()
assert len([a for a in agents if a.id == agent.id]) == 0
@pytest.fixture(scope="module")
def agent(client) -> Generator[AgentState, None, None]:
agent = client.agents.create(
memory_blocks=[
CreateBlock(
value="username: caren",
label="human",
)
],
llm="openai/gpt-4",
embedding="openai/text-embedding-ada-002",
)
yield agent
client.agents.delete(agent_id=agent.id)
@pytest.mark.skip(reason="Temporarily skipping this test")
def test_send_message(client, agent) -> None:
message_text = "Hello, how are you today?"
response = client.agents.messages.create(
agent_id=agent.id,
messages=[
MessageCreate(
role="user",
text=message_text,
),
],
)
assert len(response.messages) == 3
assert response.usage.step_count == 1
assert [message.message_type for message in response.messages] == [
"reasoning_message",
"tool_call_message",
"tool_return_message",
]
messages = client.agents.messages.list(agent_id=agent.id)
assert len(messages) > 0
user_message = [msg for msg in messages if msg.message_type == "user_message"][-1]
assert message_text in user_message.message
@pytest.mark.skip(reason="Temporarily skipping this test")
def test_send_message_with_streaming(client, agent) -> None:
message_text = "Hello, how are you today?"
response = client.agents.messages.stream(
agent_id=agent.id,
messages=[
MessageCreate(
role="user",
text=message_text,
),
],
request_options=RequestOptions(additional_headers={"Accept": "text/event-stream"}),
)
messages = []
for chunk in response:
messages.append(chunk)
assert len(messages) == 4
assert messages.pop().step_count == 1
assert [message.message_type for message in messages] == [
"reasoning_message",
"tool_call_message",
"tool_return_message",
]
messages = client.agents.messages.list(agent_id=agent.id)
assert len(messages) > 0
user_message = [msg for msg in messages if msg.message_type == "user_message"][-1]
assert message_text in user_message.message
'''
client.agents.delete(agent_id=agent.id)

0 comments on commit 26fd521

Please sign in to comment.