Skip to content
Draft
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
44 changes: 44 additions & 0 deletions app/api/collection-job/[job_id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { NextResponse } from 'next/server';

const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000';

// GET /api/collection/collection_job/[collection_job_id] - Get collection job status
export async function GET(
request: Request,
{ params }: { params: Promise<{ collection_job_id: string }> }
) {
const { collection_job_id } = await params;
const apiKey = request.headers.get('X-API-KEY');

if (!apiKey) {
return NextResponse.json(
{ error: 'Missing X-API-KEY header' },
{ status: 401 }
);
}

try {
const response = await fetch(
`${backendUrl}/api/v1/collection_jobs/${collection_job_id}`,
{
headers: {
'X-API-KEY': apiKey,
},
}
);

const text = await response.text();
const data = text ? JSON.parse(text) : {};

if (!response.ok) {
return NextResponse.json(data, { status: response.status });
}

return NextResponse.json(data, { status: response.status });
} catch (error: any) {
return NextResponse.json(
{ success: false, error: error.message, data: null },
{ status: 500 }
);
}
}
86 changes: 86 additions & 0 deletions app/api/collection/[collection_id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { NextResponse } from 'next/server';

const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000';

// GET /api/collection/[collection_id] - Get a specific collection
export async function GET(
request: Request,
{ params }: { params: Promise<{ collection_id: string }> }
) {
const { collection_id } = await params;
const apiKey = request.headers.get('X-API-KEY');

if (!apiKey) {
return NextResponse.json(
{ error: 'Missing X-API-KEY header' },
{ status: 401 }
);
}

try {
const response = await fetch(
`${backendUrl}/api/v1/collections/${collection_id}?include_docs=true`,
{
headers: {
'X-API-KEY': apiKey,
},
}
);

const text = await response.text();
const data = text ? JSON.parse(text) : {};

if (!response.ok) {
return NextResponse.json(data, { status: response.status });
}

return NextResponse.json(data, { status: response.status });
} catch (error: any) {
return NextResponse.json(
{ success: false, error: error.message, data: null },
{ status: 500 }
);
}
}

// DELETE /api/collection/[collection_id] - Delete a collection
export async function DELETE(
request: Request,
{ params }: { params: Promise<{ collection_id: string }> }
) {
const { collection_id } = await params;
const apiKey = request.headers.get('X-API-KEY');

if (!apiKey) {
return NextResponse.json(
{ error: 'Missing X-API-KEY header' },
{ status: 401 }
);
}

try {
const response = await fetch(
`${backendUrl}/api/v1/collections/${collection_id}`,
{
method: 'DELETE',
headers: {
'X-API-KEY': apiKey,
},
}
);

const text = await response.text();
const data = text ? JSON.parse(text) : { success: true };

if (!response.ok) {
return NextResponse.json(data, { status: response.status });
}

return NextResponse.json(data, { status: response.status });
} catch (error: any) {
return NextResponse.json(
{ success: false, error: error.message, data: null },
{ status: 500 }
);
}
}
84 changes: 84 additions & 0 deletions app/api/collection/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { NextRequest, NextResponse } 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');

if (!apiKey) {
return NextResponse.json(
{ error: 'Missing X-API-KEY header' },
{ status: 401 }
);
}

try {
const response = await fetch(`${backendUrl}/api/v1/collections/`, {
headers: {
'X-API-KEY': apiKey,
},
});

// Handle empty responses (204 No Content, etc.)
const text = await response.text();
const data = text ? JSON.parse(text) : [];

if (!response.ok) {
return NextResponse.json(data, { status: response.status });
}

return NextResponse.json(data, { status: response.status });
} catch (error: any) {
return NextResponse.json(
{ success: false, error: error.message, data: null },
{ status: 500 }
);
}
}

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 JSON body from the request
const body = await request.json();

// 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/collections/`, {
method: 'POST',
body: JSON.stringify(body),
headers: {
'X-API-KEY': apiKey,
'Content-Type': 'application/json',
},
});

// 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 }
);
}
}
1 change: 1 addition & 0 deletions app/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default function Sidebar({ collapsed, activeRoute = '/evaluations' }: Sid
]
},
{ name: 'Documents', route: '/document' },
{ name: 'Knowledge base', route: '/knowledge-base' },
// { name: 'Model Testing', route: '/model-testing', comingSoon: true },
// { name: 'Guardrails', route: '/guardrails', comingSoon: true },
// { name: 'Redteaming', route: '/redteaming', comingSoon: true },
Expand Down
Loading