import db, { getModels } from "@/utils/db" export default async function Comparison({ params }) { const { slugs } = params const [model1, model2] = slugs.split("-vs-") const models = await getModels() const model1Data = models.find((m) => m.slug === model1) const model2Data = models.find((m) => m.slug === model2) // Get the models' results from the DB, const results = await db`SELECT * FROM results INNER JOIN prompts ON results.prompt = prompts.id WHERE model = ${model1Data.id} OR model = ${model2Data.id}` // Group and convert to table data with: prompt text, model 1 result, model 2 result const tableData = results.reduce((acc, result) => { const prompt = result.text // If the prompt is not in the accumulator, add it if (!acc[prompt]) { acc[prompt] = { prompt, } } // Add the result to the prompt acc[prompt][result.model === model1Data.id ? "model1" : "model2"] = result return acc }, {}) // Convert to array const tableDataArray = Object.values(tableData) return ( {tableDataArray.map((row, i) => ( ))}
Prompt {model1Data?.name} {model2Data?.name}
{row.prompt}
{row.model1?.result?.trim()}

{row.model1 ? `Score: ${row.model1?.score}` : "Not rated"}

{row.model2?.result?.trim()}

{row.model2 ? `Score: ${row.model2?.score}` : "Not rated"}

) }