Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkbrnd committed Feb 7, 2025
1 parent 27017fc commit 8b2b8d8
Showing 1 changed file with 47 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pydantic import BaseModel, Field

from agno.agent import Agent, AgentMemory, RunResponse # noqa
from agno.media import Image
from agno.models.openai import OpenAIChat
from agno.tools.duckduckgo import DuckDuckGoTools

Expand All @@ -14,6 +15,19 @@ def test_basic():
assert len(response.messages) == 3
assert [m.role for m in response.messages] == ["system", "user", "assistant"]

# Test metrics structure and types
input_tokens = response.metrics["input_tokens"]
output_tokens = response.metrics["output_tokens"]
total_tokens = response.metrics["total_tokens"]

assert isinstance(input_tokens[0], int)
assert input_tokens[0] > 0
assert isinstance(output_tokens[0], int)
assert output_tokens[0] > 0
assert isinstance(total_tokens[0], int)
assert total_tokens[0] > 0
assert total_tokens[0] == input_tokens[0] + output_tokens[0]


def test_basic_stream():
agent = Agent(model=OpenAIChat(id="gpt-4o"), markdown=True)
Expand All @@ -29,23 +43,6 @@ def test_basic_stream():
assert isinstance(response, RunResponse)


def test_basic_metrics():
agent = Agent(model=OpenAIChat(id="gpt-4o"), markdown=True)
response = agent.run("Share a 2 sentence horror story")

# Test metrics structure and types
input_tokens = response.metrics["input_tokens"]
output_tokens = response.metrics["output_tokens"]
total_tokens = response.metrics["total_tokens"]

assert isinstance(input_tokens[0], int)
assert input_tokens[0] > 0
assert isinstance(output_tokens[0], int)
assert output_tokens[0] > 0
assert isinstance(total_tokens[0], int)
assert total_tokens[0] > 0
assert total_tokens[0] == input_tokens[0] + output_tokens[0]
assert False

def test_tool_use():
agent = Agent(
Expand All @@ -58,13 +55,12 @@ def test_tool_use():
response = agent.run("What is the capital of France and what's the current weather there?")

# Verify tool usage
assert any(msg.tool_calls for msg in response.messages if msg.role == "assistant")
assert any(msg.tool_calls for msg in response.messages)
assert response.content is not None
assert "Paris" in response.content


def test_with_memory():
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
agent = Agent(
model=OpenAIChat(id="gpt-4o"),
add_history_to_messages=True,
Expand All @@ -84,7 +80,19 @@ def test_with_memory():
assert len(agent.memory.messages) == 5
assert [m.role for m in agent.memory.messages] == ["system", "user", "assistant", "user", "assistant"]

# TODO: Assert metrics
# Test metrics structure and types
input_tokens = response2.metrics["input_tokens"]
output_tokens = response2.metrics["output_tokens"]
total_tokens = response2.metrics["total_tokens"]

assert isinstance(input_tokens[0], int)
assert input_tokens[0] > 0
assert isinstance(output_tokens[0], int)
assert output_tokens[0] > 0
assert isinstance(total_tokens[0], int)
assert total_tokens[0] > 0
assert total_tokens[0] == input_tokens[0] + output_tokens[0]



def test_structured_output():
Expand All @@ -105,3 +113,22 @@ class MovieScript(BaseModel):
assert response.content.title is not None
assert response.content.genre is not None
assert response.content.plot is not None

def test_image_input():
agent = Agent(
model=OpenAIChat(id="gpt-4o"),
tools=[DuckDuckGoTools()],
markdown=True,
)

response = agent.run(
"Tell me about this image and give me the latest news about it.",
images=[
Image(
url="https://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg"
)
],
)

assert "golden" in response.content.lower()
assert len(response.messages) == 5

0 comments on commit 8b2b8d8

Please sign in to comment.