Files
gpt-pilot/tests/agents/test_convo.py
Senko Rasic 5b474ccc1f merge gpt-pilot 0.2 codebase
This is a complete rewrite of the GPT Pilot core, from the ground
up, making the agentic architecture front and center, and also
fixing some long-standing problems with the database architecture
that weren't feasible to solve without breaking compatibility.

As the database structure and config file syntax have changed,
we have automatic imports for projects and current configs,
see the README.md file for details.

This also relicenses the project to FSL-1.1-MIT license.
2024-05-22 21:42:25 +02:00

44 lines
1.2 KiB
Python

from unittest.mock import MagicMock
from pydantic import BaseModel, Field
from core.agents.convo import AgentConvo
def test_init():
"""Test that init stores the agent instance and adds a system message."""
agent = MagicMock(agent_type="spec-writer", current_state=None)
convo = AgentConvo(agent)
assert convo.agent_instance == agent
assert len(convo.messages) == 1
assert convo.messages[0]["role"] == "system"
def test_fork():
"""Test that fork() creates a new AgentConvo instance, not base Convo."""
agent = MagicMock(agent_type="spec-writer", current_state=None)
convo = AgentConvo(agent)
child = convo.fork()
assert child.agent_instance == agent
child.template("ask_questions")
assert len(convo.messages) == 1
assert len(child.messages) == 2
def test_require_schema():
"""Test that require_schema() adds a message with the schema description."""
class MyModel(BaseModel):
name: str = Field(description="User name")
age: int
agent = MagicMock(agent_type="spec-writer", current_state=None)
convo = AgentConvo(agent).require_schema(MyModel)
assert len(convo.messages) == 2
assert '"description": "User name"' in convo.messages[1]["content"]