Skip to content

fix(local): route Ollama through native /api/chat for think: false - #11

Merged
haoruilee merged 2 commits into
mainfrom
cursor/ollama-native-chat-api-b4e6
Apr 2, 2026
Merged

haoruilee merged 2 commits into
mainfrom
cursor/ollama-native-chat-api-b4e6

Conversation

@haoruilee

@haoruilee haoruilee commented Apr 2, 2026 •

Copy link
Copy Markdown
Member

Summary

Ollama 0.18.x honors think on the native POST /api/chat endpoint but not on the OpenAI-compatible /v1/chat/completions path. The plugin was sending local traffic to the latter, so think: false (and localDisableThinking) had no effect on reasoning-style models.

Changes

  • LocalAdapter now calls ${localProxyUrl}/api/chat for both non-streaming and streaming chat.
  • Request body uses Ollama’s shape: model, messages (same OpenAI-style array), stream, optional native think, and options for temperature, top_p, num_predict (from max_tokens). Optional tools / tool_choice / stop are forwarded when present.
  • Non-stream: maps the final Ollama JSON object to an OpenAI chat.completion (choices[0].message, finish_reason, optional usage from eval counts).
  • Stream: parses Ollama NDJSON and emits OpenAI-style SSE (data: { ... chat.completion.chunk ... }\n\n plus data: [DONE]) so the existing proxy (text/event-stream) stays compatible with OpenAI clients.
  • Version: 1.2.14 → 1.2.15 (package.json, openclaw.plugin.json, package-lock.json).

Tests

  • Unit tests updated to assert /api/chat URL and Ollama-shaped mock responses; npm test passes.

Notes

  • Ping / model listing still use /api/tags (and /v1/models fallback) as before.
  • Merge to main is fine after review; optional: run npm run test:e2e locally if you have Ollama + key.
Open in Web Open in Cursor 

Ollama 0.18.x ignores think on /v1/chat/completions. Route local chat
through /api/chat, map responses to OpenAI ChatCompletion shape, and
emit SSE chunks from NDJSON streams for the plugin proxy.

Co-authored-by: 0x4C33 <haoruilee@users.noreply.github.com>
@haoruilee
haoruilee marked this pull request as ready for review April 2, 2026 06:51
Co-authored-by: 0x4C33 <haoruilee@users.noreply.github.com>
@haoruilee
haoruilee merged commit bf704e5 into main Apr 2, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants