1import { debug } from "@/src/lib/debug";
2import { NextResponse } from "next/server";
3import ollama from "ollama";
4
5export async function GET() {
6 try {
7 const response = await ollama.list();
8 const models = (response.models || []).map((model) => ({
9 name: model.name,
10 model: model.name, // Use name as the model identifier
11 }));
12 return NextResponse.json({ models });
13 } catch (err) {
14 debug(
15 `[Models API] Error fetching models:`,
16 err instanceof Error ? err.message : "Unknown error"
17 );
18 return NextResponse.json({ error: "Failed to fetch models" }, { status: 500 });
19 }
20}