Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/components/bulk/ResultsTable.astro
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ const csvData = JSON.parse(dataset.csv_data) as Record<string, unknown>[];
const headers = csvData.length > 0 ? Object.keys(csvData[0]) : [];

// Parse selected models from run
const selectedModels = JSON.parse(run.selected_models) as string[];
const selectedModels = JSON.parse(run.selected_models) as Array<{
id: string;
name: string;
provider: string;
}>;

// Group results by row index and model for easy lookup
const resultsMap = new Map<string, RowResult>();
Expand Down Expand Up @@ -281,11 +285,11 @@ const getActionsLeftOffset = (headerCount: number) => `calc(6rem + ${headerCount
</th>
<!-- Model output columns -->
{
selectedModels.map((modelId) => (
selectedModels.map((model) => (
<th class="min-w-[200px] max-w-[300px]" scope="col">
<div class="flex items-center gap-2">
<span>Output</span>
<span class="badge badge-sm badge-neutral">{modelId}</span>
<span class="badge badge-sm badge-neutral">{model.name}</span>
</div>
</th>
))
Expand Down Expand Up @@ -379,15 +383,15 @@ const getActionsLeftOffset = (headerCount: number) => `calc(6rem + ${headerCount
</ul>
</div>
</td>
{selectedModels.map((modelId) => {
const resultKey = `${rowIndex}-${modelId}`;
{selectedModels.map((model) => {
const resultKey = `${rowIndex}-${model.id}`;
const result = resultsMap.get(resultKey);
const status = result?.status || 'pending';

return (
<td
class="min-w-[200px] max-w-[300px]"
data-model-id={modelId}
data-model-id={model.id}
data-row-index={rowIndex}
>
<div class="flex flex-col gap-2 group relative">
Expand All @@ -398,9 +402,9 @@ const getActionsLeftOffset = (headerCount: number) => `calc(6rem + ${headerCount
class="btn btn-ghost btn-xs btn-circle opacity-0 group-hover:opacity-100 transition-opacity"
data-action="regenerate-cell"
data-row-index={rowIndex}
data-model-id={modelId}
title={`Regenerate output for ${modelId}`}
aria-label={`Regenerate row ${rowIndex + 1} with ${modelId}`}
data-model-id={model.id}
title={`Regenerate output for ${model.name}`}
aria-label={`Regenerate row ${rowIndex + 1} with ${model.name}`}
>
<Icon name="refresh" size="sm" />
</button>
Expand Down
27 changes: 23 additions & 4 deletions src/pages/api/bulk/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import type { APIRoute } from 'astro';
import { getRunWithResults } from '@lib/db';
import { getRunWithResults, getModelById } from '@lib/db';
import { badRequest, notFound, createErrorResponse } from '@lib/api-error-handler';
import { createLogger } from '@lib/logger';

Expand All @@ -18,7 +18,7 @@ const logger = createLogger('API:Bulk:Results');
* Get complete results for a bulk evaluation run
*
* Query params: run_id (required)
* Response: 200 with { run, dataset, headers, results_by_row, models }
* Response: 200 with { run, dataset, headers, selected_models (with id, name, provider), rows, summary }
* 400 with { error: string }
* 404 with { error: string }
*/
Expand All @@ -44,8 +44,20 @@ export const GET: APIRoute = async ({ url }) => {
const csvRows = JSON.parse(data.dataset.csv_data) as Record<string, unknown>[];
const headers = Object.keys(csvRows[0] || {});

// Parse selected models
// Parse selected models and fetch model names
const selectedModels = JSON.parse(data.selected_models) as string[];
const modelInfoMap = new Map<string, { id: string; name: string; provider: string }>();

for (const modelId of selectedModels) {
const model = getModelById(modelId);
if (model) {
modelInfoMap.set(modelId, {
id: model.id,
name: model.model_name,
provider: model.provider,
});
}
}

// Group results by row index and model for easy display
const resultsByRow: Record<
Expand Down Expand Up @@ -83,6 +95,13 @@ export const GET: APIRoute = async ({ url }) => {

logger.logApiRequest('GET', '/api/bulk/results', 200, Date.now() - startTime);

// Build selected_models array with model names
const modelsWithName = selectedModels
.map((modelId) => modelInfoMap.get(modelId))
.filter(
(model): model is { id: string; name: string; provider: string } => model !== undefined
);

return new Response(
JSON.stringify({
run: {
Expand All @@ -106,7 +125,7 @@ export const GET: APIRoute = async ({ url }) => {
created_at: data.dataset.created_at,
},
headers,
selected_models: selectedModels,
selected_models: modelsWithName,
rows: rowsWithResults,
// Summary statistics
summary: {
Expand Down
16 changes: 8 additions & 8 deletions src/pages/bulk-eval/[id].astro
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let initialData: {
created_at: string;
};
headers: string[];
selected_models: string[];
selected_models: Array<{ id: string; name: string; provider: string }>;
rows: Array<{
index: number;
data: Record<string, unknown>;
Expand Down Expand Up @@ -148,7 +148,7 @@ if (notFound || !initialData) {
<div class="flex flex-wrap gap-1 mt-1">
{
initialData.selected_models.map((model) => (
<span class="badge badge-ghost badge-xs">{model}</span>
<span class="badge badge-ghost badge-xs">{model.name}</span>
))
}
</div>
Expand Down Expand Up @@ -458,7 +458,7 @@ if (notFound || !initialData) {
row_count: number;
};
headers: string[];
selected_models: string[];
selected_models: Array<{ id: string; name: string; provider: string }>;
rows: Array<{
index: number;
data: Record<string, unknown>;
Expand Down Expand Up @@ -597,11 +597,11 @@ if (notFound || !initialData) {
.join('')}
${selectedModels
.map(
(modelId: string) => `
(model: { id: string; name: string; provider: string }) => `
<th class="min-w-[200px] max-w-[300px]">
<div class="flex items-center gap-2">
<span>Output</span>
<span class="badge badge-sm badge-neutral">${modelId}</span>
<span class="badge badge-sm badge-neutral">${model.name}</span>
</div>
</th>
`
Expand Down Expand Up @@ -630,8 +630,8 @@ if (notFound || !initialData) {
})
.join('')}
${selectedModels
.map((modelId: string) => {
const result = row.results[modelId];
.map((model: { id: string; name: string; provider: string }) => {
const result = row.results[model.id];
let cellContent = '';

if (result?.status === 'completed') {
Expand Down Expand Up @@ -662,7 +662,7 @@ if (notFound || !initialData) {
}

return `
<td class="min-w-[200px] max-w-[300px]" data-model-id="${modelId}">
<td class="min-w-[200px] max-w-[300px]" data-model-id="${model.id}">
${cellContent}
</td>
`;
Expand Down
Loading