docs: replace README with Next.js boilerplate template
Updated README.md from a detailed OllaHub project description to the standard Next.js getting started template, likely to initialize or reset the project as a Next.js application.
This commit is contained in:
1 parent
58e5522700
commit
a3f8226fda
42 files changed
+4465
-314
No files matched your search
@@ -0,0 +1,62 @@
|
||||
import { NextRequest } from "next/server";
|
||||
import { chatWithStream } from "@/lib/ollama";
|
||||
import { convertToOllamaMessages } from "@/lib/chat";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
try {
|
||||
const { model, messages, options, system } = await req.json();
|
||||
|
||||
if (!model || !messages?.length) {
|
||||
return new Response("Missing model or messages", { status: 400 });
|
||||
}
|
||||
|
||||
const stream = new ReadableStream({
|
||||
async start(controller) {
|
||||
try {
|
||||
const ollamaMessages = convertToOllamaMessages(messages);
|
||||
const response = await chatWithStream(
|
||||
model,
|
||||
ollamaMessages,
|
||||
options,
|
||||
system
|
||||
);
|
||||
|
||||
for await (const chunk of response) {
|
||||
const token = chunk.message?.content || "";
|
||||
if (token) {
|
||||
controller.enqueue(
|
||||
new TextEncoder().encode(JSON.stringify({ token }) + "\n")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
controller.enqueue(
|
||||
new TextEncoder().encode(JSON.stringify({ done: true }) + "\n")
|
||||
);
|
||||
controller.close();
|
||||
} catch (error) {
|
||||
console.error("Chat streaming error:", error);
|
||||
controller.enqueue(
|
||||
new TextEncoder().encode(
|
||||
JSON.stringify({ error: "Failed to generate response" }) + "\n"
|
||||
)
|
||||
);
|
||||
controller.close();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return new Response(stream, {
|
||||
headers: {
|
||||
"Content-Type": "text/event-stream",
|
||||
"Cache-Control": "no-cache",
|
||||
Connection: "keep-alive",
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Chat API error:", error);
|
||||
return new Response("Internal server error", { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user