diff --git a/app/api/evaluations/stt/datasets/[dataset_id]/route.ts b/app/api/evaluations/stt/datasets/[dataset_id]/route.ts new file mode 100644 index 0000000..b01336b --- /dev/null +++ b/app/api/evaluations/stt/datasets/[dataset_id]/route.ts @@ -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 } + ); + } +} \ No newline at end of file diff --git a/app/api/evaluations/stt/datasets/route.ts b/app/api/evaluations/stt/datasets/route.ts new file mode 100644 index 0000000..ba41c5b --- /dev/null +++ b/app/api/evaluations/stt/datasets/route.ts @@ -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); + } catch (error) { + return NextResponse.json( + { success: false, error: error.message, 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/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} + ); + } + +} \ No newline at end of file diff --git a/app/api/evaluations/stt/files/route.ts b/app/api/evaluations/stt/files/route.ts new file mode 100644 index 0000000..ee93781 --- /dev/null +++ b/app/api/evaluations/stt/files/route.ts @@ -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 } + ); + } +} diff --git a/app/api/evaluations/stt/results/[result_id]/route.ts b/app/api/evaluations/stt/results/[result_id]/route.ts new file mode 100644 index 0000000..95ec3a0 --- /dev/null +++ b/app/api/evaluations/stt/results/[result_id]/route.ts @@ -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'; + 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 } + ); + } +} \ No newline at end of file diff --git a/app/api/evaluations/stt/runs/[run_id]/route.ts b/app/api/evaluations/stt/runs/[run_id]/route.ts new file mode 100644 index 0000000..d7d708d --- /dev/null +++ b/app/api/evaluations/stt/runs/[run_id]/route.ts @@ -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 } + ); + } +} \ No newline at end of file diff --git a/app/api/evaluations/stt/runs/route.ts b/app/api/evaluations/stt/runs/route.ts new file mode 100644 index 0000000..df41f40 --- /dev/null +++ b/app/api/evaluations/stt/runs/route.ts @@ -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); + } catch (error) { + return NextResponse.json( + { success: false, error: error.message, 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/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} + ); + } + +} \ No newline at end of file