Its working but needs a massive clean up

This commit is contained in:
Brandon Hancock
2025-03-25 13:38:52 -04:00
parent 998afcd498
commit 06854fff86
7 changed files with 355 additions and 302 deletions

View File

@@ -79,61 +79,61 @@ async def main():
result = await agent.kickoff_async("What is the population of Tokyo in 2023?")
print(f"Raw response: {result.raw}")
# Example 2: Query with structured output
print("\n=== Example 2: Structured Output ===")
structured_query = """
Research the impact of climate change on coral reefs.
YOU MUST format your response as a valid JSON object with the following structure:
{
"main_findings": "A summary of the main findings",
"key_points": ["Point 1", "Point 2", "Point 3"],
"sources": ["Source 1", "Source 2"]
}
Include at least 3 key points and 2 sources. Wrap your JSON in ```json and ``` tags.
"""
# # Example 2: Query with structured output
# print("\n=== Example 2: Structured Output ===")
# structured_query = """
# Research the impact of climate change on coral reefs.
result = await agent.kickoff_async(structured_query)
# YOU MUST format your response as a valid JSON object with the following structure:
# {
# "main_findings": "A summary of the main findings",
# "key_points": ["Point 1", "Point 2", "Point 3"],
# "sources": ["Source 1", "Source 2"]
# }
if result.pydantic:
# Cast to the specific type for better IDE support
research_result = cast(ResearchResult, result.pydantic)
print(f"Main findings: {research_result.main_findings}")
print("\nKey points:")
for i, point in enumerate(research_result.key_points, 1):
print(f"{i}. {point}")
print("\nSources:")
for i, source in enumerate(research_result.sources, 1):
print(f"{i}. {source}")
else:
print(f"Raw response: {result.raw}")
print(
"\nNote: Structured output was not generated. The LLM may need more explicit instructions to format the response as JSON."
)
# Include at least 3 key points and 2 sources. Wrap your JSON in ```json and ``` tags.
# """
# Example 3: Multi-turn conversation
print("\n=== Example 3: Multi-turn Conversation ===")
messages = [
{"role": "user", "content": "I'm planning a trip to Japan."},
{
"role": "assistant",
"content": "That sounds exciting! Japan is a beautiful country with rich culture, delicious food, and stunning landscapes. What would you like to know about Japan to help with your trip planning?",
},
{
"role": "user",
"content": "What are the best times to visit Tokyo and Kyoto?",
},
]
# result = await agent.kickoff_async(structured_query)
result = await agent.kickoff_async(messages)
print(f"Response: {result.raw}")
# if result.pydantic:
# # Cast to the specific type for better IDE support
# research_result = cast(ResearchResult, result.pydantic)
# print(f"Main findings: {research_result.main_findings}")
# print("\nKey points:")
# for i, point in enumerate(research_result.key_points, 1):
# print(f"{i}. {point}")
# print("\nSources:")
# for i, source in enumerate(research_result.sources, 1):
# print(f"{i}. {source}")
# else:
# print(f"Raw response: {result.raw}")
# print(
# "\nNote: Structured output was not generated. The LLM may need more explicit instructions to format the response as JSON."
# )
# Print usage metrics if available
if result.usage_metrics:
print("\nUsage metrics:")
for key, value in result.usage_metrics.items():
print(f"{key}: {value}")
# # Example 3: Multi-turn conversation
# print("\n=== Example 3: Multi-turn Conversation ===")
# messages = [
# {"role": "user", "content": "I'm planning a trip to Japan."},
# {
# "role": "assistant",
# "content": "That sounds exciting! Japan is a beautiful country with rich culture, delicious food, and stunning landscapes. What would you like to know about Japan to help with your trip planning?",
# },
# {
# "role": "user",
# "content": "What are the best times to visit Tokyo and Kyoto?",
# },
# ]
# result = await agent.kickoff_async(messages)
# print(f"Response: {result.raw}")
# # Print usage metrics if available
# if result.usage_metrics:
# print("\nUsage metrics:")
# for key, value in result.usage_metrics.items():
# print(f"{key}: {value}")
if __name__ == "__main__":