後端代理範例(Node.js)
app.post('/api/chat', async (req, res) => {
const { model, messages } = req.body;
const upstream = await fetch(
process.env.OLLAMA_URL + '/api/chat',
{ method:'POST', body: JSON.stringify({ model, messages, stream:true }) }
);
res.setHeader('Content-Type','text/event-stream');
upstream.body.pipeTo(
new WritableStream({ write(chunk) { res.write(chunk); } })
);
});