1 line
2.9 KiB
JSON
1 line
2.9 KiB
JSON
{"repo": "chacha-bing/paperpilot", "files": {"src/app/api/chat/route.ts": {"412d0bf7d99cdbde2571e86743059d36136dcb3b": {"t": 1785745583.1843693, "n": 1214, "h": "d3e5464500e67685", "c": "/**\n * POST /api/chat - 流式对话接口\n *\n * 接收 messages,调用 AIService.streamChat,返回 NDJSON 流(content + reasoning_content)。\n */\nimport { NextResponse } from \"next/server\";\n\nimport { AIService } from \"@/services/ai.service\";\n\nexport const runtime = \"nodejs\";\n\nexport async function POST(request: Request): Promise<Response> {\n const apiKey = process.env.DEEPSEEK_API_KEY;\n if (!apiKey) {\n return NextResponse.json(\n { error: \"缺少 DEEPSEEK_API_KEY 配置,无法调用 AI 服务。\" },\n { status: 500 }\n );\n }\n\n const body = (await request.json()) as {\n messages: { role: \"system\" | \"user\" | \"assistant\"; content: string }[];\n };\n\n const ai = new AIService(apiKey);\n\n const stream = new ReadableStream({\n async start(controller) {\n const encoder = new TextEncoder();\n try {\n for await (const chunk of ai.streamChat({ messages: body.messages })) {\n const payload = JSON.stringify(chunk);\n controller.enqueue(encoder.encode(`${payload}\\n`));\n }\n } catch (error) {\n controller.error(error);\n } finally {\n controller.close();\n }\n }\n });\n\n return new Response(stream, {\n headers: {\n \"Content-Type\": \"application/x-ndjson\"\n }\n });\n}\n\n"}, "a774aef4faa657c8cb3e412aa6afa83e1a83d05d": {"t": 1785754500.0163996, "n": 1214, "h": "d3e5464500e67685", "c": "/**\n * POST /api/chat - 流式对话接口\n *\n * 接收 messages,调用 AIService.streamChat,返回 NDJSON 流(content + reasoning_content)。\n */\nimport { NextResponse } from \"next/server\";\n\nimport { AIService } from \"@/services/ai.service\";\n\nexport const runtime = \"nodejs\";\n\nexport async function POST(request: Request): Promise<Response> {\n const apiKey = process.env.DEEPSEEK_API_KEY;\n if (!apiKey) {\n return NextResponse.json(\n { error: \"缺少 DEEPSEEK_API_KEY 配置,无法调用 AI 服务。\" },\n { status: 500 }\n );\n }\n\n const body = (await request.json()) as {\n messages: { role: \"system\" | \"user\" | \"assistant\"; content: string }[];\n };\n\n const ai = new AIService(apiKey);\n\n const stream = new ReadableStream({\n async start(controller) {\n const encoder = new TextEncoder();\n try {\n for await (const chunk of ai.streamChat({ messages: body.messages })) {\n const payload = JSON.stringify(chunk);\n controller.enqueue(encoder.encode(`${payload}\\n`));\n }\n } catch (error) {\n controller.error(error);\n } finally {\n controller.close();\n }\n }\n });\n\n return new Response(stream, {\n headers: {\n \"Content-Type\": \"application/x-ndjson\"\n }\n });\n}\n\n"}}}} |