File size: 1,817 Bytes
7e5cb25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97826e4
7e5cb25
 
 
97826e4
7e5cb25
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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 (
    <table style={{ maxWidth: 1200 }}>
      <thead>
        <tr>
          <th>Prompt</th>
          <th>{model1Data?.name}</th>
          <th>{model2Data?.name}</th>
        </tr>
      </thead>
      <tbody>
        {tableDataArray.map((row, i) => (
          <tr key={i}>
            <td>
              <pre>{row.prompt}</pre>
            </td>
            <td>
              <pre>{row.model1?.result?.trim()}</pre>
              <p>{row.model1 ? `Score: ${row.model1?.score}` : "Not rated"}</p>
            </td>
            <td>
              <pre>{row.model2?.result?.trim()}</pre>
              <p>{row.model2 ? `Score: ${row.model2?.score}` : "Not rated"}</p>
            </td>
          </tr>
        ))}
      </tbody>
    </table>
  )
}