Files
OllaHub/app/api/ollama/warmup/route.ts
T
Evandro Fonseca Junior 1545020afe feat(api): add pagination to messages endpoint and improve chat API robustness
- Add pagination support to /api/conversations/[id]/messages with limit and before query params, returning hasMore and cursor for efficient message fetching
- Enhance /api/ollama/chat by adding non-blocking Ollama availability check and conditionally disabling debug logging in production环境下Featured
2025-10-29 17:22:21 -03:00

30 lines
767 B
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { Ollama } from "ollama";
import { OLLAMA_HOST } from "@/lib/ollama";
export const dynamic = "force-dynamic";
export async function GET(req: NextRequest) {
try {
const url = new URL(req.url);
const model = url.searchParams.get("model");
if (!model) {
return NextResponse.json({ error: "model required" }, { status: 400 });
}
const client = new Ollama({ host: OLLAMA_HOST });
await client.chat({
model,
messages: [{ role: "system", content: "warm" }],
stream: false,
options: { keep_alive: "5m" },
});
return NextResponse.json({ warmed: true });
} catch (e) {
return NextResponse.json({ warmed: false }, { status: 200 });
}
}