Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{% if context.memory.agent_description %}{{ context.memory.agent_description }}

{% endif %}
<tables>
{% for df in context.dfs %}
{% include 'shared/dataframe.tmpl' with context %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest

from pandasai.core.prompts import GeneratePythonCodeWithSQLPrompt
from pandasai.helpers.memory import Memory


@pytest.fixture
Expand All @@ -17,6 +18,16 @@ def mock_context():
return context


@pytest.fixture
def render_context():
context = Mock()
context.dfs = []
context.skills = []
context.config.direct_sql = True
context.vectorstore = None
return context


def test_to_json(mock_context):
"""Test that to_json returns the expected structure with all required fields"""
prompt = GeneratePythonCodeWithSQLPrompt(context=mock_context, output_type="code")
Expand Down Expand Up @@ -46,3 +57,31 @@ def test_to_json(mock_context):
assert result["config"]["direct_sql"] is True
assert "output_type" in result["config"]
assert result["config"]["output_type"] == "code"


def test_template_renders_agent_description(render_context):
"""Test that agent_description appears in rendered template."""
memory = Memory(memory_size=10, agent_description="I am a helpful analytics agent")
memory.add("What is the average salary?", is_user=True)
render_context.memory = memory

prompt = GeneratePythonCodeWithSQLPrompt(
context=render_context, last_code_generated=None, output_type="number"
)
rendered = prompt.to_string()

assert "I am a helpful analytics agent" in rendered


def test_template_no_description_when_none(render_context):
"""Test that no description block when agent_description is None."""
memory = Memory(memory_size=10)
memory.add("What is the average salary?", is_user=True)
render_context.memory = memory

prompt = GeneratePythonCodeWithSQLPrompt(
context=render_context, last_code_generated=None, output_type="number"
)
rendered = prompt.to_string()

assert "I am a helpful" not in rendered