| |
| """ |
| Test script to verify the Pydantic structured output functionality. |
| """ |
|
|
| import asyncio |
| import sys |
| import os |
|
|
| |
| sys.path.append(os.path.dirname(os.path.abspath(__file__))) |
|
|
| from tools.tavily_search_tool import ReportOutput, get_structured_report_from_state |
| from datetime import datetime |
|
|
| async def test_structured_output(): |
| """Test the structured report output functionality.""" |
| |
| print("π§ͺ Testing Pydantic ReportOutput model...") |
| |
| |
| test_report = ReportOutput( |
| title="Test Report", |
| abstract="This is a test abstract for our report.", |
| content="""# Test Report |
| |
| ## Introduction |
| This is the introduction section. |
| |
| ## Main Content |
| This is the main content section with some details. |
| |
| ## Conclusion |
| This is the conclusion section. |
| """, |
| sections=["Introduction", "Main Content", "Conclusion"], |
| word_count=25, |
| sources_used=["Source 1", "Source 2"] |
| ) |
| |
| print(f"β
Created ReportOutput successfully!") |
| print(f"π Title: {test_report.title}") |
| print(f"π Abstract: {test_report.abstract}") |
| print(f"π Word Count: {test_report.word_count}") |
| print(f"ποΈ Sections: {test_report.sections}") |
| print(f"π Sources: {test_report.sources_used}") |
| print(f"β° Generated at: {test_report.generated_at}") |
| |
| |
| print("\nπ Testing serialization...") |
| serialized = test_report.model_dump() |
| print(f"β
Serialized data keys: {list(serialized.keys())}") |
| |
| |
| print("\nπ Testing state extraction...") |
| mock_state = { |
| "structured_report": serialized, |
| "other_data": "some value" |
| } |
| |
| extracted_report = get_structured_report_from_state(mock_state) |
| if extracted_report: |
| print(f"β
Successfully extracted report from state!") |
| print(f"π Extracted title: {extracted_report.title}") |
| print(f"π Extracted word count: {extracted_report.word_count}") |
| else: |
| print("β Failed to extract report from state") |
| |
| |
| empty_report = get_structured_report_from_state({}) |
| if empty_report is None: |
| print("β
Correctly returned None for empty state") |
| else: |
| print("β Should have returned None for empty state") |
| |
| print("\nπ All tests completed!") |
|
|
| if __name__ == "__main__": |
| asyncio.run(test_structured_output()) |