-
Notifications
You must be signed in to change notification settings - Fork 60.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support DeepSeek API streaming reasoning content #6116
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Caution Review failedThe pull request is closed. WalkthroughThe pull request introduces enhancements to the DeepSeek API integration, focusing on supporting the reasoning content (Chain of Thought) display. The changes span multiple files, including Changes
Assessment against linked issues
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (5)
app/utils/chat.ts (2)
517-517
: Consider using optional chaining for safe checks.
Static analysis suggests usingtools?.length
instead oftools && tools.length
. This is a minor improvement that can make the code more concise:- tools: tools && tools.length ? tools : undefined, + tools: tools?.length ? tools : undefined,🧰 Tools
🪛 Biome (1.9.4)
[error] 517-517: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
374-631
: Overall structure ofstreamWithThink
is solid, but be cautious of complexity.
The logic handles multiple states (thinking vs. normal mode) and branching. Over time, this may grow cumbersome. Consider refactoring to smaller functions if the complexity increases.🧰 Tools
🪛 Biome (1.9.4)
[error] 494-495: This code is unreachable
... because this statement will return from the function beforehand
(lint/correctness/noUnreachable)
[error] 517-517: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 379-380: Don't use 'Function' as a type.
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
(lint/complexity/noBannedTypes)
app/client/platforms/deepseek.ts (2)
118-119
: Debug log might be verbose in production.
Consider togglingconsole.log
statements behind a debug flag or removing them in production builds to avoid cluttered logs.
Line range hint
132-198
: Parsing SSE data for reasoning content is well-structured.
If performance becomes an issue, consider limiting repetitive JSON parse operations by batching messages or reusing references.app/utils.ts (1)
19-20
: Regex usage is appropriate but watch out for edge cases.
If you anticipate extended punctuation or additional quote-like characters, consider making the pattern more comprehensive.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
app/client/platforms/deepseek.ts
(7 hunks)app/utils.ts
(3 hunks)app/utils/chat.ts
(2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
app/utils/chat.ts
[error] 494-495: This code is unreachable
... because this statement will return from the function beforehand
(lint/correctness/noUnreachable)
[error] 517-517: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 379-380: Don't use 'Function' as a type.
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
(lint/complexity/noBannedTypes)
🔇 Additional comments (8)
app/utils/chat.ts (3)
347-350
: Early exit for empty messages looks correct.
This addition helps avoid unnecessary processing and can improve performance.
352-352
: Consider verifying the output ofparseSSE
.
Although it's wrapped in a try-catch block, ensure that malformed messages don't propagate unexpected data or break the flow.
494-495
: False positive from static analysis on unreachable code.
Although a static analysis tool flagged these lines as unreachable, they appear to be valid returns from within theif (!running && runTools.length > 0)
block. Confirm that your control flow is correct and that these lines do not inadvertently exit too early.🧰 Tools
🪛 Biome (1.9.4)
[error] 494-495: This code is unreachable
... because this statement will return from the function beforehand
(lint/correctness/noUnreachable)
app/client/platforms/deepseek.ts (3)
16-16
: Good migration tostreamWithThink
.
Replacing the old streaming logic with the new function will allow for better handling of "thinking mode" in your application.
25-28
: Clean import structure for new helper method.
Adding thegetMessageTextContentWithoutThinking
function is consistent with how the assistant content is now processed.
73-79
: Logical separation of assistant vs. user messages is clear.
Always ensure the correct function is used to strip or retain the "thinking" lines, based on the role.app/utils.ts (2)
244-264
: Ensure only intentional lines are filtered out bygetMessageTextContentWithoutThinking
.
If a user’s actual content starts with"> "
, it will be discarded. Confirm that the user experience aligns with these rules, or introduce a more robust approach to detect genuine “thinking” lines.
281-281
: Sufficient usage of.split(...)
and.map(...)
.
No immediate concerns here. The code is clean and idiomatic.
funcs: Record<string, Function>, | ||
controller: AbortController, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Avoid using Function
as a type.
Using Function
is considered a bad practice in TypeScript because it disables type checking for function arguments and return types. Use a more specific function signature, for example:
- funcs: Record<string, Function>
+ funcs: Record<string, (args: Record<string, unknown>) => Promise<any> | any>
(or whichever shape best represents your use case).
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
funcs: Record<string, Function>, | |
controller: AbortController, | |
funcs: Record<string, (args: Record<string, unknown>) => Promise<any> | any>, | |
controller: AbortController, |
🧰 Tools
🪛 Biome (1.9.4)
[error] 379-380: Don't use 'Function' as a type.
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
(lint/complexity/noBannedTypes)
Deployment failed with the following error:
View Documentation: https://vercel.com/docs/accounts/team-members-and-roles |
💻 变更类型 | Change Type
🔀 变更说明 | Description of Change
Closes #6104
📝 补充信息 | Additional Information
Summary by CodeRabbit
Release Notes
New Features
Improvements
Technical Enhancements