[Fix] Restore adapter v1 endpoint and streaming compatibility#787
[Fix] Restore adapter v1 endpoint and streaming compatibility#787dingyi222666 merged 1 commit intov1-devfrom
Conversation
Normalize requester URL handling so OpenAI-compatible adapters stop appending version prefixes twice, and map generated Claude thinking variants back to real API models when needed. Also handle message-only stream chunks and readable timing logs so provider responses do not drop content and middleware latency is easier to inspect. Affected: adapter-claude, adapter-doubao, adapter-rwkv, core, shared-adapter
概览本PR对多个适配器和核心模块进行了改动,主要包括:为Claude适配器添加thinking模型变体处理和模型白名单机制、重构多个适配器的URL拼接逻辑、新增时间格式化工具函数、以及改进流式响应元数据事件处理。 变更清单
序列图不适用。本次变更主要为局部逻辑改进、工具函数添加和URL拼接简化,不涉及跨多组件的新功能流程。 估计代码审查工作量🎯 3 (中等复杂) | ⏱️ ~25 分钟 相关PR
诗文
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on enhancing the robustness and compatibility of the adapter system. It addresses critical issues related to API endpoint versioning, particularly for OpenAI-compatible and specific adapters like RWKV and Doubao, by streamlining URL concatenation logic. Furthermore, it significantly improves the Claude adapter's model resolution, especially for 'thinking' models, and refines stream processing to ensure no data loss when full message payloads are received without delta chunks. These changes collectively aim to provide a more stable and predictable interaction with various LLM APIs. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a number of valuable fixes and improvements across the board. It successfully restores v1 endpoint compatibility, enhances Claude model handling by dynamically deriving "thinking" variants, and improves stream processing to prevent data loss. The refactoring to centralize URL concatenation logic and the addition of human-readable duration formatting for logs are also welcome changes that improve code quality and maintainability. I have one suggestion for improving code clarity.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/adapter-claude/src/client.ts (1)
214-219: 建议:THINKING_MODELS常量可考虑内联根据编码规范:"Do not define named constants unless the value is truly important and reused; inline literal values directly at call sites"。
THINKING_MODELS仅在一处使用。不过,考虑到这是支持 thinking 功能的模型前缀列表,将其作为常量有助于未来维护和更新,当前实现可以接受。🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/adapter-claude/src/client.ts` around lines 214 - 219, THINKING_MODELS is only used once so inline the literal array at its single call site instead of keeping the named constant: remove the THINKING_MODELS declaration and replace references to THINKING_MODELS with the array literal ['claude-3-7-sonnet-','claude-opus-4','claude-sonnet-4','claude-haiku-4-5']; if you prefer to keep readability, alternatively leave THINKING_MODELS but add a short comment explaining it represents supported thinking-model prefixes to justify the named constant.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/adapter-claude/src/client.ts`:
- Around line 214-219: THINKING_MODELS is only used once so inline the literal
array at its single call site instead of keeping the named constant: remove the
THINKING_MODELS declaration and replace references to THINKING_MODELS with the
array literal
['claude-3-7-sonnet-','claude-opus-4','claude-sonnet-4','claude-haiku-4-5']; if
you prefer to keep readability, alternatively leave THINKING_MODELS but add a
short comment explaining it represents supported thinking-model prefixes to
justify the named constant.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 8ba717d2-7a75-4570-8ba8-e8a58a2a6eb6
📒 Files selected for processing (9)
packages/adapter-claude/src/client.tspackages/adapter-claude/src/requester.tspackages/adapter-doubao/src/requester.tspackages/adapter-rwkv/src/index.tspackages/adapter-rwkv/src/requester.tspackages/core/src/chains/chain.tspackages/core/src/llm-core/platform/api.tspackages/core/src/utils/time.tspackages/shared-adapter/src/requester.ts
💤 Files with no reviewable changes (2)
- packages/core/src/llm-core/platform/api.ts
- packages/adapter-rwkv/src/requester.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 22446d77f0
ℹ️ 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".
This pr restores v1-compatible endpoint handling across shared and adapter-specific requesters, fixes Claude thinking model resolution, and preserves streamed message chunks that arrive as final message payloads.
New Features
Bug fixes
/v1or/v3path segments.-thinkingmodel names back to supported API models before requests are sent.messagepayloads withoutdeltachunks so content is not dropped./v1endpoint.Other Changes