Skip to content
Open
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
2 changes: 1 addition & 1 deletion app/api/evaluations/datasets/[dataset_id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function DELETE(
} catch (error: any) {
console.error('Proxy error:', error);
return NextResponse.json(
{ error: 'Failed to forward request to backend', details: error.message },
{ error: 'Failed to forward request to backend', details: error instanceof Error ? error.message : String(error) },
{ status: 500 }
);
}
Expand Down
4 changes: 2 additions & 2 deletions app/api/evaluations/datasets/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function GET(request: NextRequest) {
} catch (error: any) {
console.error('Proxy error:', error);
return NextResponse.json(
{ error: 'Failed to forward request to backend', details: error.message },
{ error: 'Failed to forward request to backend', details: error instanceof Error ? error.message : String(error) },
{ status: 500 }
);
}
Expand Down Expand Up @@ -92,7 +92,7 @@ export async function POST(request: NextRequest) {
} catch (error: any) {
console.error('Proxy error:', error);
return NextResponse.json(
{ error: 'Failed to forward request to backend', details: error.message },
{ error: 'Failed to forward request to backend', details: error instanceof Error ? error.message : String(error) },
{ status: 500 }
);
}
Expand Down
4 changes: 2 additions & 2 deletions app/api/evaluations/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export async function GET(request: NextRequest) {
} catch (error) {
console.error('Proxy error:', error);
return NextResponse.json(
{ error: 'Failed to fetch evaluations', details: error.message },
{ error: 'Failed to forward request to backend', details: error instanceof Error ? error.message : String(error) },
{ status: 500 }
);
}
Expand Down Expand Up @@ -84,7 +84,7 @@ export async function POST(request: NextRequest) {
} catch (error) {
console.error('Proxy error:', error);
return NextResponse.json(
{ error: 'Failed to forward request', details: error.message },
{ error: 'Failed to forward request to backend', details: error instanceof Error ? error.message : String(error) },
{ status: 500 }
);
}
Expand Down
26 changes: 26 additions & 0 deletions app/api/evaluations/stt/datasets/[dataset_id]/route.ts
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 dataset', data: null },
{ status: 500 }
);
}
}
65 changes: 65 additions & 0 deletions app/api/evaluations/stt/datasets/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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, { 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/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 to backend', details: error instanceof Error ? error.message : String(error)},
{status:500}
);
}

}
49 changes: 49 additions & 0 deletions app/api/evaluations/stt/files/route.ts
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 instanceof Error ? error.message : String(error) },
{ status: 500 }
);
}
}
64 changes: 64 additions & 0 deletions app/api/evaluations/stt/results/[result_id]/route.ts
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,
{ 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 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/stt/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 }
);
}
}
26 changes: 26 additions & 0 deletions app/api/evaluations/stt/runs/[run_id]/route.ts
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 the run', data: null },
{ status: 500 }
);
}
}
64 changes: 64 additions & 0 deletions app/api/evaluations/stt/runs/route.ts
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, { 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/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 to backend', details: error instanceof Error ? error.message : String(error)},
{status:500}
);
}

}
49 changes: 0 additions & 49 deletions app/api/speech-to-text/evaluate/route.ts

This file was deleted.

Loading