async function compareOptions(topic: string, options: string[]) {
const response = await valyu.answer(
`Compare the pros and cons of ${options.join(", ")} for ${topic}`,
{
systemInstructions: "Provide a comprehensive comparison with objective analysis. Include specific examples, metrics, and real-world considerations for each option.",
structuredOutput: {
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 && response.data_type === "structured") {
const comparison = response.contents as any;
console.log("=== Comparative Analysis ===");
console.log(`\n${comparison.comparison_summary}`);
console.log("\n=== Option Analysis ===");
comparison.options.forEach((option: any) => {
console.log(`\n${option.name.toUpperCase()}`);
console.log(`Best for: ${option.best_for}`);
console.log(`Learning curve: ${option.learning_curve}`);
console.log(`Market adoption: ${option.market_adoption}`);
console.log("Pros:");
option.pros.forEach((pro: string) => console.log(` ✓ ${pro}`));
console.log("Cons:");
option.cons.forEach((con: string) => console.log(` ✗ ${con}`));
});
console.log(`\n=== Final Recommendation ===`);
console.log(comparison.recommendation);
return comparison;
}
return null;
}
// Usage examples
const frameworkComparison = await compareOptions(
"enterprise web applications",
["React", "Vue", "Angular"]
);
const databaseComparison = await compareOptions(
"scalable microservices architecture",
["PostgreSQL", "MongoDB", "Cassandra"]
);