first commit

This commit is contained in:
lingyuzeng
2026-03-22 13:16:22 +08:00
commit ba7d42da13
23 changed files with 3541 additions and 0 deletions

30
src/routes/ollama.ts Executable file
View File

@@ -0,0 +1,30 @@
import { FastifyInstance, FastifyPluginAsync } from 'fastify';
import { forwardChatRequest } from '../proxy/forward';
import { logger } from '../utils/logger';
const ollamaRoutes: FastifyPluginAsync = async (server: FastifyInstance) => {
server.post('/api/chat', async (request, reply) => {
try {
const body = request.body as any;
// Currently only supporting non-streaming requests in this proxy MVP
if (body?.stream === true) {
// As per requirements: return clear error or pass through without rewriting
// We'll return a clear error for now, because stream parsing is out of scope for MVP
reply.status(400).send({
error: "Streaming is not supported by this proxy MVP. Please set stream=false."
});
return;
}
const response = await forwardChatRequest(body);
reply.status(200).send(response);
} catch (error: any) {
logger.error('Error handling /api/chat:', error.message);
reply.status(500).send({ error: error.message });
}
});
};
export default ollamaRoutes;