mirror of
https://github.com/aljazceru/enclava.git
synced 2025-12-18 16:04:28 +01:00
clean commit
This commit is contained in:
45
frontend/src/app/api/llm/models/route.ts
Normal file
45
frontend/src/app/api/llm/models/route.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { NextRequest, NextResponse } from "next/server"
|
||||
|
||||
const BACKEND_URL = process.env.INTERNAL_API_URL || "http://shifra-backend:8000"
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const token = request.headers.get("authorization")
|
||||
|
||||
if (!token) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
|
||||
}
|
||||
|
||||
const response = await fetch(`${BACKEND_URL}/api/v1/llm/models`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Authorization": token,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.text()
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch models", details: errorData },
|
||||
{ status: response.status }
|
||||
)
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
const transformedModels = data.data?.map((model: any) => ({
|
||||
id: model.id,
|
||||
name: model.id,
|
||||
provider: model.owned_by || "unknown"
|
||||
})) || []
|
||||
|
||||
return NextResponse.json({ data: transformedModels })
|
||||
} catch (error) {
|
||||
console.error("Error fetching models:", error)
|
||||
return NextResponse.json(
|
||||
{ error: "Internal server error" },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user