mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 00:28:31 +00:00
Enhance markdown feature based on PR feedback
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -6,8 +6,15 @@ from unittest.mock import patch
|
||||
from crewai import Agent, Task
|
||||
|
||||
|
||||
def test_markdown_option_in_task_prompt():
|
||||
"""Test that when markdown=True, the task prompt includes markdown formatting instructions."""
|
||||
@pytest.mark.parametrize(
|
||||
"markdown_enabled,should_contain_instructions",
|
||||
[
|
||||
(True, True),
|
||||
(False, False),
|
||||
],
|
||||
)
|
||||
def test_markdown_option_in_task_prompt(markdown_enabled, should_contain_instructions):
|
||||
"""Test that markdown flag correctly controls the inclusion of markdown formatting instructions."""
|
||||
|
||||
researcher = Agent(
|
||||
role="Researcher",
|
||||
@@ -19,35 +26,67 @@ def test_markdown_option_in_task_prompt():
|
||||
task = Task(
|
||||
description="Research advances in AI in 2023",
|
||||
expected_output="A summary of key AI advances in 2023",
|
||||
markdown=markdown_enabled,
|
||||
agent=researcher,
|
||||
)
|
||||
|
||||
prompt = task.prompt()
|
||||
|
||||
assert "Research advances in AI in 2023" in prompt
|
||||
assert "A summary of key AI advances in 2023" in prompt
|
||||
|
||||
if should_contain_instructions:
|
||||
assert "Your final answer MUST be formatted in Markdown syntax." in prompt
|
||||
assert "Use # for headers" in prompt
|
||||
assert "Use ** for bold text" in prompt
|
||||
else:
|
||||
assert "Your final answer MUST be formatted in Markdown syntax." not in prompt
|
||||
|
||||
|
||||
def test_markdown_with_empty_description():
|
||||
"""Test markdown formatting with empty description."""
|
||||
|
||||
researcher = Agent(
|
||||
role="Researcher",
|
||||
goal="Research a topic",
|
||||
backstory="You're a researcher.",
|
||||
allow_delegation=False,
|
||||
)
|
||||
|
||||
task = Task(
|
||||
description="",
|
||||
expected_output="A summary",
|
||||
markdown=True,
|
||||
agent=researcher,
|
||||
)
|
||||
|
||||
prompt = task.prompt()
|
||||
|
||||
assert "Research advances in AI in 2023" in prompt
|
||||
assert "A summary of key AI advances in 2023" in prompt
|
||||
assert prompt.strip() != ""
|
||||
assert "A summary" in prompt
|
||||
assert "Your final answer MUST be formatted in Markdown syntax." in prompt
|
||||
|
||||
|
||||
def test_markdown_option_not_in_task_prompt_by_default():
|
||||
"""Test that by default (markdown=False), the task prompt does not include markdown formatting instructions."""
|
||||
def test_markdown_with_complex_output_format():
|
||||
"""Test markdown with JSON output format to ensure compatibility."""
|
||||
|
||||
researcher = Agent(
|
||||
role="Researcher",
|
||||
goal="Research a topic",
|
||||
backstory="You're a researcher specialized in providing well-formatted content.",
|
||||
backstory="You're a researcher.",
|
||||
allow_delegation=False,
|
||||
)
|
||||
|
||||
task = Task(
|
||||
description="Research advances in AI in 2023",
|
||||
expected_output="A summary of key AI advances in 2023",
|
||||
description="Research topic",
|
||||
expected_output="Research results",
|
||||
markdown=True,
|
||||
output_json=True,
|
||||
agent=researcher,
|
||||
)
|
||||
|
||||
prompt = task.prompt()
|
||||
|
||||
assert "Research advances in AI in 2023" in prompt
|
||||
assert "A summary of key AI advances in 2023" in prompt
|
||||
assert "Your final answer MUST be formatted in Markdown syntax." not in prompt
|
||||
assert "Your final answer MUST be formatted in Markdown syntax." in prompt
|
||||
assert "Research topic" in prompt
|
||||
assert "Research results" in prompt
|
||||
|
||||
Reference in New Issue
Block a user