-
Notifications
You must be signed in to change notification settings - Fork 0
UI: STT Evals #44
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?
UI: STT Evals #44
Changes from all commits
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,26 @@ | ||
| import { NextResponse, NextRequest } 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'); | ||
|
|
||
| try { | ||
| const response = await fetch(`${backendUrl}/api/v1/evaluations/stt/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 config', data: null }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,64 @@ | ||||||||||
| 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/stt/datasets`, { | ||||||||||
| headers: { | ||||||||||
| 'X-API-KEY': apiKey || '', | ||||||||||
| }, | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| const data = await response.json(); | ||||||||||
| return NextResponse.json(data); | ||||||||||
|
Comment on lines
+16
to
+17
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. Backend status not forwarded — same issue as Proposed fix const data = await response.json();
- return NextResponse.json(data);
+ return NextResponse.json(data, { status: response.status });📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| } catch (error) { | ||||||||||
| return NextResponse.json( | ||||||||||
| { success: false, error: error.message, data: null }, | ||||||||||
| { status: 500 } | ||||||||||
| ); | ||||||||||
|
Comment on lines
+18
to
+22
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.
Apply the same 🤖 Prompt for AI Agents |
||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
| 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/stt/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', details:error.message}, | ||||||||||
| {status:500} | ||||||||||
| ); | ||||||||||
|
Comment on lines
+56
to
+61
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.
🤖 Prompt for AI Agents |
||||||||||
| } | ||||||||||
|
|
||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { NextRequest, NextResponse } from 'next/server'; | ||
|
|
||
|
|
||
| export async function POST(request: NextRequest) { | ||
| try { | ||
| // Get the API key from request headers | ||
| const apiKey = request.headers.get('X-API-KEY'); | ||
|
|
||
| if (!apiKey) { | ||
| return NextResponse.json( | ||
| { error: 'Missing X-API-KEY header' }, | ||
| { status: 401 } | ||
| ); | ||
| } | ||
|
|
||
| // Get the form data from the request | ||
| const formData = await request.formData(); | ||
|
|
||
| // Get backend URL from environment variable | ||
| const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000'; | ||
|
|
||
| // Forward the request to the actual backend | ||
| const response = await fetch(`${backendUrl}/api/v1/evaluations/stt/files`, { | ||
| method: 'POST', | ||
| body: formData, | ||
| headers: { | ||
| 'X-API-KEY': apiKey, | ||
|
|
||
| }, | ||
| }); | ||
|
|
||
| // Handle empty responses (204 No Content, etc.) | ||
| const text = await response.text(); | ||
| const data = text ? JSON.parse(text) : { success: true }; | ||
|
|
||
| // Return the response with the same status code | ||
| if (!response.ok) { | ||
| return NextResponse.json(data, { status: response.status }); | ||
| } | ||
|
|
||
| return NextResponse.json(data, { status: response.status }); | ||
| } catch (error: any) { | ||
| console.error('Proxy error:', error); | ||
| return NextResponse.json( | ||
| { error: 'Failed to forward request to backend', details: error.message }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,26 @@ | ||||||||||||||||||||||
| import { NextResponse, NextRequest } 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'; | ||||||||||||||||||||||
|
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.
Environment variables prefixed with 🤖 Prompt for AI Agents |
||||||||||||||||||||||
| const apiKey = request.headers.get('X-API-KEY'); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| try { | ||||||||||||||||||||||
| const response = await fetch(`${backendUrl}/api/v1/evaluations/stt/results/${result_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 config', data: null }, | ||||||||||||||||||||||
| { status: 500 } | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
|
Comment on lines
+20
to
+24
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. Error message is inaccurate — copy-paste artifact. The error says Proposed fix- { success: false, error: 'Failed to fetch config', data: null },
+ { success: false, error: 'Failed to fetch result', data: null },📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { NextResponse, NextRequest } 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'); | ||
|
|
||
| try { | ||
| const response = await fetch(`${backendUrl}/api/v1/evaluations/stt/runs/${run_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 config', data: null }, | ||
| { status: 500 } | ||
| ); | ||
|
Comment on lines
+20
to
+24
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. Error message is inaccurate — should reference "run", not "config". Proposed fix- { success: false, error: 'Failed to fetch config', data: null },
+ { success: false, error: 'Failed to fetch run', data: null },🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,64 @@ | ||||||||||||||||||||||||
| 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/stt/runs`, { | ||||||||||||||||||||||||
| headers: { | ||||||||||||||||||||||||
| 'X-API-KEY': apiKey || '', | ||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const data = await response.json(); | ||||||||||||||||||||||||
| return NextResponse.json(data); | ||||||||||||||||||||||||
|
Comment on lines
+16
to
+17
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. Backend HTTP status is silently dropped — client always receives 200. Unlike the Proposed fix const data = await response.json();
- return NextResponse.json(data);
+ return NextResponse.json(data, { status: response.status });📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||
| return NextResponse.json( | ||||||||||||||||||||||||
| { success: false, error: error.message, data: null }, | ||||||||||||||||||||||||
| { status: 500 } | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
|
Comment on lines
+18
to
+22
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.
In TypeScript, the caught Proposed fix } catch (error) {
return NextResponse.json(
- { success: false, error: error.message, data: null },
+ { success: false, error: error instanceof Error ? error.message : 'Internal server error', data: null },
{ status: 500 }
);
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| 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/stt/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', details:error.message}, | ||||||||||||||||||||||||
| {status:500} | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
|
Comment on lines
+56
to
+61
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. Same Proposed fix } catch (error) {
console.error('Proxy error:', error);
return NextResponse.json(
- {error:'Failed to forward request', details:error.message},
+ {error:'Failed to forward request', details: error instanceof Error ? error.message : 'Unknown error'},
{status:500}
);
}🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
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.
Error message is inaccurate — should reference "dataset", not "config".
Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents