[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-81011":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":14,"subscribersCount":14,"size":14,"stars1d":15,"stars7d":15,"stars30d":16,"stars90d":14,"forks30d":14,"starsTrendScore":17,"compositeScore":18,"rankGlobal":9,"rankLanguage":9,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":22,"hasPages":20,"topics":23,"createdAt":9,"pushedAt":9,"updatedAt":24,"readmeContent":25,"aiSummary":26,"trendingCount":14,"starSnapshotCount":14,"syncStatus":15,"lastSyncTime":27,"discoverSource":28},81011,"codex_deepseek_proxy","Nigel211\u002Fcodex_deepseek_proxy","Nigel211","将 OpenAI Responses API 请求翻译为 DeepSeek Chat Completions API 的流式代理，让 Codex 接入 DeepSeek 模型。Streaming proxy for cc-switch that bridges OpenAI Responses API to DeepSeek Chat API, enabling Codex to use DeepSeek",null,"Python",32,7,29,0,2,4,6,48.11,"MIT License",false,"main",true,[],"2026-06-12 04:01:31","# codex_proxy\n\nOpenAI Responses API ↔ DeepSeek Chat API 流式转发代理。让 Codex IDE \u002F Codex CLI 通过 cc-switch 接入 DeepSeek 模型，支持完整的工具调用（Function Calling）。\n\n## 功能\n\n- 将 Codex 发出的 OpenAI Responses API 请求翻译为 DeepSeek Chat Completions API\n- **完整支持 Function Calling**：工具定义透传、并行工具调用合并、tool 消息排序\n- 将 DeepSeek 的 SSE 流式响应翻译回 Responses API 语义事件（含 function_call 事件）\n- 自动修复消息顺序：Codex 注入的系统消息（如审批通知）会被重排，确保 tool 消息紧跟 assistant 消息\n- 禁用思考模式：避免 DeepSeek v4-pro 的 `reasoning_content` 回传兼容问题\n- 支持 cc-switch 模型选择（请求中的 model 字段优先）\n- API Key 优先级：系统环境变量 > `.env` 文件 > 首次交互输入\n\n## 环境要求\n\n- Python >= 3.9\n- DeepSeek API Key（[获取地址](https:\u002F\u002Fplatform.deepseek.com\u002Fapi_keys)）\n\n## 安装\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002F\u003Cyour-username>\u002Fcodex_proxy.git\ncd codex_proxy\npip install -r requirements.txt\n```\n\n## 使用\n\n```bash\npython codex_proxy.py\n```\n\n首次运行如果没有配置 API Key，会在命令行引导你输入（输入时内容被遮蔽），自动保存到同目录 `.env` 文件。\n\n启动后输出：\n\n```\ncodex_proxy starting ...\n   Endpoint: http:\u002F\u002F127.0.0.1:5000\n   Model:    deepseek-v4-pro\n   Key:      .env\n   Debug:    OFF\n   Routes:   \u002Fresponses, \u002Fv1\u002Fresponses, \u002Fv1\u002Fchat\u002Fcompletions\n```\n\n## 配置\n\n所有配置通过环境变量或 `.env` 文件设置（环境变量优先级更高）。\n\n| 变量 | 必填 | 默认值 | 说明 |\n|------|------|--------|------|\n| `DEEPSEEK_API_KEY` | **是** | - | DeepSeek API 密钥 |\n| `DEEPSEEK_MODEL` | 否 | `deepseek-v4-pro` | 模型名称，cc-switch 中指定的模型会覆盖此值 |\n| `DEEPSEEK_URL` | 否 | `https:\u002F\u002Fapi.deepseek.com\u002Fv1\u002Fchat\u002Fcompletions` | DeepSeek API 地址 |\n| `DEEPSEEK_DEBUG` | 否 | `0` | 设为 `1` 开启请求日志，输出到 `proxy_debug.log` |\n\n### API Key 设置方式（按优先级）\n\n1. **系统环境变量**（推荐）：`export DEEPSEEK_API_KEY=sk-xxx`\n2. **`.env` 文件**：在脚本同目录创建 `.env`，写入 `DEEPSEEK_API_KEY=sk-xxx`\n3. **交互输入**：首次启动时提示输入，自动保存到 `.env`\n\n## cc-switch 配置\n\n在 cc-switch 中将模型路由地址设为：\n\n```\nhttp:\u002F\u002F127.0.0.1:5000\n```\n\n代理注册了三个路由，cc-switch 会自动适配：\n\n- `\u002Fresponses`\n- `\u002Fv1\u002Fresponses`\n- `\u002Fv1\u002Fchat\u002Fcompletions`\n\n## 架构\n\n```\nCodex IDE\u002FCLI          cc-switch            codex_proxy           DeepSeek API\n─────────────          ─────────            ────────────          ────────────\nResponses API ────→  路由转发  ────→  格式转换 (Responses→Chat)  ────→  \u002Fv1\u002Fchat\u002Fcompletions\nSSE Stream    ←────   透传     ←────  格式转换 (Chat→Responses)   ←────  SSE Stream\n```\n\n本代理完整实现了 OpenAI Responses API 的 SSE 语义事件流，支持文本和函数调用两种输出：\n\n**纯文本响应：**\n```\nresponse.created → response.in_progress → response.output_item.added\n→ response.content_part.added → response.output_text.delta (×N)\n→ response.output_text.done → response.content_part.done\n→ response.output_item.done → response.completed\n```\n\n**函数调用响应：**\n```\nresponse.created → response.in_progress\n→ response.output_item.added (type: function_call)\n→ response.function_call_arguments.delta (×N)\n→ response.function_call_arguments.done\n→ response.output_item.done → response.completed\n```\n\n## 工具调用兼容性\n\n代理处理了 DeepSeek Chat Completions API 与 OpenAI Responses API 之间的以下差异：\n\n| 问题 | 处理方式 |\n|------|----------|\n| 工具定义格式不同 | 将 Responses API 扁平格式转为 Chat API 嵌套 `function` 格式，清除 `strict` 和 `additionalProperties` 字段 |\n| 并行工具调用 | 将 Codex 的多个连续 `function_call` 项合并为单个 assistant 消息（含多个 `tool_calls`） |\n| 消息顺序 | DeepSeek 要求 tool 消息紧跟对应的 assistant 消息；代理自动将 Codex 插入的 system 消息移到 assistant 之前 |\n| 思考模式 | 默认禁用（`thinking: {type: \"disabled\"}`），避免 `reasoning_content` 无法通过 Responses API 回传 |\n\n## 常见问题\n\n**Q: 启动后 Codex 无响应？**\n\n检查 `DEEPSEEK_API_KEY` 是否正确设置。开启 `DEEPSEEK_DEBUG=1` 后查看 `proxy_debug.log`。\n\n**Q: 如何更换模型？**\n\n在 cc-switch 中更改模型名，代理会自动透传。或设置 `DEEPSEEK_MODEL=deepseek-chat` 作为默认。\n\n**Q: 工具调用报 400 错误？**\n\n检查 `proxy_debug.log` 中的错误详情。常见原因：DeepSeek 账户余额不足、模型不支持工具调用、或请求体过大。\n\n**Q: 是否需要安装 Python？**\n\n是，需要 Python 3.9 及以上。依赖安装后启动代理即可。\n\n## License\n\nMIT\n","codex_deepseek_proxy 是一个将 OpenAI Responses API 请求翻译为 DeepSeek Chat Completions API 的流式代理，旨在让 Codex IDE 或 CLI 通过 cc-switch 接入 DeepSeek 模型。该项目核心功能包括完整支持 Function Calling、自动修复消息顺序以确保 tool 消息紧跟 assistant 消息、禁用思考模式以避免兼容性问题等。它使用 Python 开发，并要求至少 Python 3.9 版本及有效的 DeepSeek API Key。此项目适用于需要在开发环境中集成或测试不同 AI 模型的场景，特别是当开发者希望无缝切换并利用 DeepSeek 提供的强大自然语言处理能力时。","2026-06-11 04:03:10","CREATED_QUERY"]