Skip to content

feat(codex): add Ollama local provider preset with proxy fixes#4075

Open
XiaoBinGan wants to merge 5 commits into
farion1231:mainfrom
XiaoBinGan:feat/ollama-codex-proxy
Open

feat(codex): add Ollama local provider preset with proxy fixes#4075
XiaoBinGan wants to merge 5 commits into
farion1231:mainfrom
XiaoBinGan:feat/ollama-codex-proxy

Conversation

@XiaoBinGan

Copy link
Copy Markdown

Summary

Add Ollama as a built-in Codex provider preset so users can run Codex against local models (qwen3.5, qwen2.5, etc.) via CC Switch proxy.

Changes

New features

  • New "local" category in ProviderCategory for local models (Ollama, LM Studio, etc.)
  • Ollama preset with 5 models: qwen3.5:9b, qwen2.5:14b, qwen2.5:7b, qwen3:8b, gpt-oss:20b
  • Reasoning config: supportsThinking=true, supportsEffort=false, outputFormat="reasoning"

Bug fixes

  1. Codex Chat URL endpoint dropped (forwarder.rs) — when codex_responses_to_chat is active but adapter build_url drops the endpoint (e.g. base_url already ends with /v1), manually append /chat/completions. Fixes 404 when proxying to Ollama.

  2. Health check 404 for isFullUrl providers (stream_check.rs) — when isFullUrl=true but the base_url doesn't actually contain /chat/completions (common for Ollama's http://127.0.0.1:11434/v1), auto-fallback to non-full URL building.

  3. Reasoning effort 400 for local models (codex.rs) — resolve_codex_chat_reasoning_config now detects Ollama providers (by id/name/base_url) and forces supportsEffort=false, preventing Codex's reasoning.effort param from reaching Ollama upstream.

Files changed

File Lines
src/types.ts +1
src/config/codexProviderPresets.ts +48
src-tauri/src/proxy/forwarder.rs +13
src-tauri/src/proxy/providers/codex.rs +37
src-tauri/src/services/stream_check.rs +13

Testing

  • ✅ TypeScript typecheck: zero errors
  • ✅ Rust cargo check: zero errors
  • ✅ Proxy integration: Codex → 15721 → Chat conversion → 11434 Ollama → 200 OK
  • ✅ Thinking/reasoning tokens correctly relayed (Qwen3.5 reasoning_content)
  • ✅ Health check passes
  • ✅ No impact on existing providers (DeepSeek, Kimi, etc.)

吴佳浩 added 5 commits June 11, 2026 15:41
- Add 'local' category to ProviderCategory for local models
- Add Ollama (Local) preset with 5 local model entries
- Configure openai_chat API format for Responses→Chat protocol conversion
- Set up thinking-mode reasoning config for Qwen series models
- Base URL: http://127.0.0.1:11434/v1

Models included: qwen3.5:9b, qwen2.5:14b, qwen2.5:7b, qwen3:8b, gpt-oss:20b
'thinking' is not a valid CodexChatReasoningOutputFormat. Ollama's
reasoning tokens arrive in delta.reasoning, so use 'reasoning'.
Codex Responses→Chat Completions conversion correctly computes
effective_endpoint=/chat/completions but adapters build_url may
drop the endpoint when base_url already ends with /v1 (e.g. Ollama).

Add post-build URL check: if codex_responses_to_chat is active and
the endpoint is missing from the final URL, manually append it.

Fixes 404 when Codex proxies to Ollama or other local models.
1. Force supports_effort=false for Ollama/local providers
   - resolve_codex_chat_reasoning_config now detects Ollama by
     provider id, name, or base_url (127.0.0.1:11434) and
     forces supports_effort=false regardless of meta values.
   - Prevents Codex reasoning.effort param from reaching
     Ollama upstream (which returns 400).

2. Fix health check URL for isFullUrl + chat providers
   - When isFullUrl=true but base_url doesn't actually contain
     /chat/completions (common for Ollama's base_url=v1/),
     automatically fall back to non-full URL building.
   - Fixes 404 in health check even if isFullUrl was
     accidentally persisted by the form.
When the UI form overwrites meta, apiFormat can be cleared.
Add is_ollama_provider() fallback in codex_provider_uses_chat_completions
so the proxy always routes Ollama requests through Chat Completions
even if the config field is missing.
@farion1231

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8990c36630

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +79 to +82
// Fallback: Ollama 等本地模型即使 meta.apiFormat 被表单覆盖清空,
// 也必须走 Chat 转换(Responses API 不被支持)。
if is_ollama_provider(provider) {
return true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check Ollama before the TOML wire_api return

This fallback does not cover the stated meta-cleared case for the new preset: the Ollama preset is still generated with wire_api = "responses" in its TOML config, so when meta.apiFormat is absent codex_provider_uses_chat_completions returns false from the earlier TOML wire_api branch and never reaches this is_ollama_provider check. In restored/raw-provider scenarios that lose meta, Codex /responses requests are forwarded to Ollama as /v1/responses instead of being converted to /chat/completions, so the local provider breaks again.

Useful? React with 👍 / 👎.

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