def compare_options(topic: str, options: List[str]):
response = valyu.answer(
f"Compare the pros and cons of {', '.join(options)} for {topic}",
system_instructions="Provide a comprehensive comparison with objective analysis. Include specific examples, metrics, and real-world considerations for each option.",
structured_output={
"type": "object",
"properties": {
"comparison_summary": {
"type": "string",
"description": "Brief overview of the comparison"
},
"options": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"pros": {
"type": "array",
"items": {"type": "string"}
},
"cons": {
"type": "array",
"items": {"type": "string"}
},
"best_for": {"type": "string"},
"learning_curve": {"type": "string"},
"market_adoption": {"type": "string"},
"performance_rating": {"type": "string"}
}
}
},
"decision_matrix": {
"type": "object",
"properties": {
"criteria": {
"type": "array",
"items": {"type": "string"}
},
"scores": {
"type": "object",
"description": "Scores for each option on each criteria"
}
}
},
"recommendation": {
"type": "string",
"description": "Final recommendation with reasoning"
}
},
"required": ["comparison_summary", "options", "recommendation"]
}
)
if response.success and response.data_type == "structured":
comparison = response.contents
print("=== Comparative Analysis ===")
print(f"\n{comparison['comparison_summary']}")
print("\n=== Option Analysis ===")
for option in comparison['options']:
print(f"\n{option['name'].upper()}")
print(f"Best for: {option['best_for']}")
print(f"Learning curve: {option['learning_curve']}")
print(f"Market adoption: {option['market_adoption']}")
print("Pros:")
for pro in option['pros']:
print(f" ✓ {pro}")
print("Cons:")
for con in option['cons']:
print(f" ✗ {con}")
print(f"\n=== Final Recommendation ===")
print(comparison['recommendation'])
return comparison
return None
# Usage examples
framework_comparison = compare_options(
"enterprise web applications",
["React", "Vue", "Angular"]
)
database_comparison = compare_options(
"scalable microservices architecture",
["PostgreSQL", "MongoDB", "Cassandra"]
)