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
4 changes: 2 additions & 2 deletions app/api/configs/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export async function GET(request: Request) {
const apiKey = request.headers.get('X-API-KEY');

try {
const response = await fetch(`${backendUrl}/api/v1/configs`, {
const response = await fetch(`${backendUrl}/api/v1/configs/`, {
headers: {
'X-API-KEY': apiKey || '',
},
Expand Down Expand Up @@ -38,7 +38,7 @@ export async function POST(request: NextRequest) {
const body=await request.json();
const backendUrl=process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000';

const response=await fetch(`${backendUrl}/api/v1/configs`, {
const response=await fetch(`${backendUrl}/api/v1/configs/`, {
method:'POST',
body:JSON.stringify(body),
headers:{
Expand Down
81 changes: 81 additions & 0 deletions app/api/document/[document_id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { NextRequest, NextResponse } from 'next/server';


export async function GET(request: Request,
{ params }: { params: Promise<{ document_id: string }> }
) {

const { document_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 response = await fetch(`${backendUrl}/api/v1/documents/${document_id}?include_url=true`, {
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: 200 });
} catch (error: any) {
return NextResponse.json(
{ success: false, error: error.message, data: null },
{ status: 500 }
);
}
}

export async function DELETE(request: Request,
{ params }: { params: Promise<{ document_id: string }> }
) {
const { document_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 response = await fetch(`${backendUrl}/api/v1/documents/${document_id}`, {
method: 'DELETE',
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 };

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

return NextResponse.json(data, { status: 200 });
} catch (error: any) {
console.error('Delete error:', error);
return NextResponse.json(
{ error: 'Failed to delete document', details: error.message },
{ status: 500 }
);
}
}
84 changes: 84 additions & 0 deletions app/api/document/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/documents/`, {
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 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/documents/`, {
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 }
);
}
}
6 changes: 4 additions & 2 deletions app/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ interface SidebarProps {
export default function Sidebar({ collapsed, activeRoute = '/evaluations' }: SidebarProps) {
const router = useRouter();
const [expandedMenus, setExpandedMenus] = useState<Record<string, boolean>>({
'Tasks': true,
'Capabilities': true,
'Evaluations': true,
'Documents': true,
'Configurations': false,
});

Expand All @@ -56,7 +57,7 @@ export default function Sidebar({ collapsed, activeRoute = '/evaluations' }: Sid

const navItems: MenuItem[] = [
{
name: 'Tasks',
name: 'Capabilities',
icon: (
<svg className="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 7h6m-6 4h6" />
Expand All @@ -71,6 +72,7 @@ export default function Sidebar({ collapsed, activeRoute = '/evaluations' }: Sid
{ name: 'Text-to-Speech', route: '/text-to-speech', comingSoon: true },
]
},
{ name: 'Documents', route: '/document' },
// { name: 'Model Testing', route: '/model-testing', comingSoon: true },
// { name: 'Guardrails', route: '/guardrails', comingSoon: true },
// { name: 'Redteaming', route: '/redteaming', comingSoon: true },
Expand Down
2 changes: 1 addition & 1 deletion app/datasets/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -794,4 +794,4 @@ export function UploadDatasetModal({
</div>
</div>
);
}
}
Loading