-
Notifications
You must be signed in to change notification settings - Fork 0
TTS Evaluation: Metrics #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
2f91445
dd84333
57b3eee
ebc764c
22309ad
310bd82
4565b70
dbea04e
9289305
0be3a5b
30ff1b3
f32ad58
ca4fab4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { NextResponse } from 'next/server'; | ||
|
|
||
| export async function GET( | ||
| request: Request, | ||
| { params }: { params: Promise<{ dataset_id: string }> } | ||
| ) { | ||
| const { dataset_id } = await params; | ||
| const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000'; | ||
| const apiKey = request.headers.get('X-API-KEY'); | ||
|
|
||
| if (!apiKey) { | ||
| return NextResponse.json( | ||
| { success: false, error: 'Unauthorized: Missing API key', data: null }, | ||
| { status: 401 } | ||
| ); | ||
| } | ||
|
|
||
| try { | ||
| const response = await fetch(`${backendUrl}/api/v1/evaluations/tts/datasets/${dataset_id}`, { | ||
| headers: { | ||
| 'X-API-KEY': apiKey, | ||
| }, | ||
| }); | ||
|
|
||
| const data = await response.json(); | ||
| return NextResponse.json(data, { status: response.status }); | ||
| } catch (error) { | ||
| return NextResponse.json( | ||
| { success: false, error: 'Failed to fetch dataset', data: null }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { NextResponse, NextRequest } from 'next/server'; | ||
|
|
||
| export async function GET(request: Request) { | ||
| const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000'; | ||
| const apiKey = request.headers.get('X-API-KEY'); | ||
|
|
||
| try { | ||
| const response = await fetch(`${backendUrl}/api/v1/evaluations/tts/datasets`, { | ||
| headers: { | ||
| 'X-API-KEY': apiKey || '', | ||
| }, | ||
| }); | ||
|
|
||
| const data = await response.json(); | ||
| return NextResponse.json(data, { status: response.status }); | ||
| } catch (error) { | ||
| return NextResponse.json( | ||
| { success: false, error: error, data: null }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export async function POST(request: NextRequest) { | ||
| try { | ||
| const apiKey = request.headers.get('X-API-KEY'); | ||
| if (!apiKey) { | ||
| return NextResponse.json( | ||
| { error: 'Missing X-API-KEY. Either generate an API Key. Contact Kaapi team for more details' }, | ||
| { status: 401 } | ||
| ); | ||
| } | ||
| const body = await request.json(); | ||
| const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000'; | ||
|
|
||
| const response = await fetch(`${backendUrl}/api/v1/evaluations/tts/datasets`, { | ||
| method: 'POST', | ||
| body: JSON.stringify(body), | ||
| headers: { | ||
| 'X-API-KEY': apiKey, | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }); | ||
| const data = await response.json(); | ||
| return NextResponse.json(data, { status: response.status }); | ||
| } catch (error) { | ||
| console.error('Proxy error:', error); | ||
| return NextResponse.json( | ||
| { error: 'Failed to forward request to backend', details: error instanceof Error ? error.message : String(error) }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,63 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { NextResponse } from 'next/server'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export async function GET( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| request: Request, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { params }: { params: Promise<{ result_id: string }> } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { result_id } = await params; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const apiKey = request.headers.get('X-API-KEY'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const response = await fetch(`${backendUrl}/api/v1/evaluations/tts/results/${result_id}`, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| headers: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'X-API-KEY': apiKey || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const data = await response.json(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return NextResponse.json(data, { status: response.status }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+3
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fail fast on missing API keys for result GETs as well.
🔐 Suggested fix export async function GET(
request: Request,
{ params }: { params: Promise<{ result_id: string }> }
) {
const { result_id } = await params;
const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000';
const apiKey = request.headers.get('X-API-KEY');
+
+ if (!apiKey) {
+ return NextResponse.json(
+ { success: false, error: 'Unauthorized: Missing API key', data: null },
+ { status: 401 }
+ );
+ }
try {
const response = await fetch(`${backendUrl}/api/v1/evaluations/tts/results/${result_id}`, {
headers: {
- 'X-API-KEY': apiKey || '',
+ 'X-API-KEY': apiKey,
},
});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return NextResponse.json( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { success: false, error: 'Failed to fetch results', data: null }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { status: 500 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export async function PATCH( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| request: Request, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { params }: { params: Promise<{ result_id: string }> } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { result_id } = await params; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const apiKey = request.headers.get('X-API-KEY'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!apiKey) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return NextResponse.json( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { error: 'Missing X-API-KEY header' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { status: 401 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const body = await request.json(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const response = await fetch(`${backendUrl}/api/v1/evaluations/tts/results/${result_id}`, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| method: 'PATCH', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| headers: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'X-API-KEY': apiKey || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'Content-Type': 'application/json', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| body: JSON.stringify(body), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const data = await response.json(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return NextResponse.json(data, { status: response.status }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return NextResponse.json( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { success: false, error: 'Failed to update result feedback', data: null }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { status: 500 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,33 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { NextResponse } from 'next/server'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export async function GET( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| request: Request, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { params }: { params: Promise<{ run_id: string }> } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { run_id } = await params; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const apiKey = request.headers.get('X-API-KEY'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { searchParams } = new URL(request.url); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const queryString = searchParams.toString(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const backendUrlWithParams = queryString | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? `${backendUrl}/api/v1/evaluations/tts/runs/${run_id}?${queryString}` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : `${backendUrl}/api/v1/evaluations/tts/runs/${run_id}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const response = await fetch(backendUrlWithParams, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| headers: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'X-API-KEY': apiKey || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+8
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return 401 before proxying unauthenticated run lookups. This handler currently forwards 🔐 Suggested fix const { run_id } = await params;
const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000';
const apiKey = request.headers.get('X-API-KEY');
+
+ if (!apiKey) {
+ return NextResponse.json(
+ { success: false, error: 'Unauthorized: Missing API key', data: null },
+ { status: 401 }
+ );
+ }
const { searchParams } = new URL(request.url);
const queryString = searchParams.toString();
@@
const response = await fetch(backendUrlWithParams, {
headers: {
- 'X-API-KEY': apiKey || '',
+ 'X-API-KEY': apiKey,
},
});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const data = await response.json(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return NextResponse.json(data, { status: response.status }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return NextResponse.json( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { success: false, error: 'Failed to fetch the run', data: null }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { status: 500 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,53 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { NextResponse, NextRequest } from 'next/server'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export async function GET(request: Request) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const apiKey = request.headers.get('X-API-KEY'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const response = await fetch(`${backendUrl}/api/v1/evaluations/tts/runs`, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| headers: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'X-API-KEY': apiKey || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const data = await response.json(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return NextResponse.json(data, { status: response.status }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+3
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mirror the POST auth guard on the runs GET endpoint. Right now the list 🔐 Suggested fix export async function GET(request: Request) {
const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000';
const apiKey = request.headers.get('X-API-KEY');
+
+ if (!apiKey) {
+ return NextResponse.json(
+ { success: false, error: 'Unauthorized: Missing API key', data: null },
+ { status: 401 }
+ );
+ }
try {
const response = await fetch(`${backendUrl}/api/v1/evaluations/tts/runs`, {
headers: {
- 'X-API-KEY': apiKey || '',
+ 'X-API-KEY': apiKey,
},
});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return NextResponse.json( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { success: false, error: error, data: null }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { status: 500 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export async function POST(request: NextRequest) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const apiKey = request.headers.get('X-API-KEY'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!apiKey) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return NextResponse.json( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { error: 'Missing X-API-KEY. Either generate an API Key. Contact Kaapi team for more details' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { status: 401 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const body = await request.json(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const response = await fetch(`${backendUrl}/api/v1/evaluations/tts/runs`, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| method: 'POST', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| body: JSON.stringify(body), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| headers: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'X-API-KEY': apiKey, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'Content-Type': 'application/json', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const data = await response.json(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return NextResponse.json(data, { status: response.status }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error('Proxy error:', error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return NextResponse.json( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { error: 'Failed to forward request to backend', details: error instanceof Error ? error.message : String(error) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { status: 500 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,10 +118,10 @@ export default function DetailedResultsTable({ job }: DetailedResultsTableProps) | |
| Question | ||
| </th> | ||
| <th className="px-4 py-3 text-left text-xs font-semibold uppercase" style={{ color: '#171717', width: '25%' }}> | ||
| Answer | ||
| Ground Truth | ||
| </th> | ||
| <th className="px-4 py-3 text-left text-xs font-semibold uppercase" style={{ color: '#171717', width: '25%' }}> | ||
| Ground Truth | ||
| Answer | ||
|
Comment on lines
120
to
+124
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep the individual table and CSV column order aligned. This reorders the row view to 🤖 Prompt for AI Agents |
||
| </th> | ||
| {scoreNames.map((scoreName) => ( | ||
| <th key={scoreName} className="px-4 py-3 text-center text-xs font-semibold uppercase" style={{ color: '#171717', width: `${20 / scoreNames.length}%` }}> | ||
|
|
@@ -153,12 +153,12 @@ export default function DetailedResultsTable({ job }: DetailedResultsTableProps) | |
| }} | ||
| > | ||
| {/* Row Number */} | ||
| <td className="px-4 py-3 text-sm font-medium" style={{ color: '#737373' }}> | ||
| <td className="px-4 py-3 text-sm font-medium align-top" style={{ color: '#737373' }}> | ||
| {index + 1} | ||
| </td> | ||
|
|
||
| {/* Question */} | ||
| <td className="px-4 py-3"> | ||
| <td className="px-4 py-3 align-top" style={{ backgroundColor: '#fafafa' }}> | ||
| <div | ||
| className="text-sm overflow-auto" | ||
| style={{ | ||
|
|
@@ -171,8 +171,8 @@ export default function DetailedResultsTable({ job }: DetailedResultsTableProps) | |
| </div> | ||
| </td> | ||
|
|
||
| {/* Answer */} | ||
| <td className="px-4 py-3"> | ||
| {/* Ground Truth */} | ||
| <td className="px-4 py-3 align-top" style={{ backgroundColor: '#fafafa' }}> | ||
| <div | ||
| className="text-sm overflow-auto" | ||
| style={{ | ||
|
|
@@ -181,12 +181,12 @@ export default function DetailedResultsTable({ job }: DetailedResultsTableProps) | |
| maxHeight: '150px' | ||
| }} | ||
| > | ||
| {answer} | ||
| {groundTruth} | ||
| </div> | ||
| </td> | ||
|
|
||
| {/* Ground Truth */} | ||
| <td className="px-4 py-3"> | ||
| {/* Answer */} | ||
| <td className="px-4 py-3 align-top"> | ||
| <div | ||
| className="text-sm overflow-auto" | ||
| style={{ | ||
|
|
@@ -195,7 +195,7 @@ export default function DetailedResultsTable({ job }: DetailedResultsTableProps) | |
| maxHeight: '150px' | ||
| }} | ||
| > | ||
| {groundTruth} | ||
| {answer} | ||
| </div> | ||
| </td> | ||
|
|
||
|
|
@@ -205,7 +205,7 @@ export default function DetailedResultsTable({ job }: DetailedResultsTableProps) | |
| const { value, color, bg } = formatScoreValue(score); | ||
|
|
||
| return ( | ||
| <td key={scoreName} className="px-4 py-3 text-center"> | ||
| <td key={scoreName} className="px-4 py-3 text-center align-top"> | ||
| <div className="flex items-center justify-center gap-2"> | ||
| <div | ||
| className="inline-block px-2 py-1 rounded text-xs font-medium" | ||
|
|
@@ -404,12 +404,12 @@ function GroupedResultsTable({ traces }: { traces: GroupedTraceItem[] }) { | |
| }} | ||
| > | ||
| {/* Question ID - matching row format # column */} | ||
| <td className="px-4 py-3 text-sm font-medium" style={{ color: '#737373' }}> | ||
| <td className="px-4 py-3 text-sm font-medium align-top" style={{ color: '#737373' }}> | ||
| {group.question_id} | ||
| </td> | ||
|
|
||
| {/* Question - matching row format text cell */} | ||
| <td className="px-4 py-3"> | ||
| <td className="px-4 py-3 align-top" style={{ backgroundColor: '#fafafa' }}> | ||
| <div | ||
| className="text-sm overflow-auto" | ||
| style={{ color: '#171717', lineHeight: '1.5', maxHeight: '150px' }} | ||
|
|
@@ -419,7 +419,7 @@ function GroupedResultsTable({ traces }: { traces: GroupedTraceItem[] }) { | |
| </td> | ||
|
|
||
| {/* Ground Truth - matching row format text cell */} | ||
| <td className="px-4 py-3"> | ||
| <td className="px-4 py-3 align-top" style={{ backgroundColor: '#fafafa' }}> | ||
| <div | ||
| className="text-sm overflow-auto" | ||
| style={{ color: '#171717', lineHeight: '1.5', maxHeight: '150px' }} | ||
|
|
@@ -434,7 +434,7 @@ function GroupedResultsTable({ traces }: { traces: GroupedTraceItem[] }) { | |
| const answerScores: TraceScore[] = group.scores?.[answerIndex] || []; | ||
|
|
||
| return ( | ||
| <td key={answerIndex} className="px-4 py-3"> | ||
| <td key={answerIndex} className="px-4 py-3 align-top"> | ||
| {answer ? ( | ||
| <div> | ||
| <div | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reject unauthenticated dataset-list GETs here too.
POSTin this file andGETinapp/api/evaluations/tts/datasets/[dataset_id]/route.tsalready return 401 whenX-API-KEYis missing, but this handler still proxiesX-API-KEY: ''to the backend. That makes the auth contract inconsistent and turns a local 401 into an extra backend call whose behavior now depends on backend header parsing.🔐 Suggested fix
export async function GET(request: Request) { const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000'; const apiKey = request.headers.get('X-API-KEY'); + + if (!apiKey) { + return NextResponse.json( + { success: false, error: 'Unauthorized: Missing API key', data: null }, + { status: 401 } + ); + } try { const response = await fetch(`${backendUrl}/api/v1/evaluations/tts/datasets`, { headers: { - 'X-API-KEY': apiKey || '', + 'X-API-KEY': apiKey, }, });🤖 Prompt for AI Agents