Skip to content
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

Merged
merged 4 commits into from
Jan 30, 2025

Conversation

Kadxy
Copy link
Collaborator

@Kadxy Kadxy commented Jan 30, 2025

💻 变更类型 | Change Type

  • feat
  • fix
  • refactor
  • perf
  • style
  • test
  • docs
  • ci
  • chore
  • build

🔀 变更说明 | Description of Change

Closes #6104

📝 补充信息 | Additional Information

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced message streaming with improved thinking state detection.
    • Added a user interface specifically designed for the DeepSeek Reasoner Model.
  • Improvements

    • Refined text content extraction for messages.
    • Updated message handling for DeepSeek AI platform.
    • Improved response parsing and content management.
  • Technical Enhancements

    • Introduced new utility functions for more precise message processing.
    • Updated streaming mechanism to better handle AI thinking states.

@Kadxy Kadxy linked an issue Jan 30, 2025 that may be closed by this pull request
Copy link

vercel bot commented Jan 30, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nextchat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 30, 2025 4:36pm

Copy link
Contributor

coderabbitai bot commented Jan 30, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The 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 deepseek.ts, utils.ts, and utils/chat.ts. The primary modification is the implementation of a new streaming mechanism that can handle and display the reasoning content returned by DeepSeek models, allowing users to see the model's thinking process during interactions.

Changes

File Change Summary
app/client/platforms/deepseek.ts - Updated imports to include streamWithThink and getMessageTextContentWithoutThinking
- Modified chat method to handle different message roles
- Enhanced response handling to process reasoning_content
app/utils.ts - Added getMessageTextContentWithoutThinking function
- Updated trimTopic regex patterns
- Minor adjustment to isVisionModel function
app/utils/chat.ts - Introduced new streamWithThink function
- Enhanced SSE parsing to support thinking state
- Added logic for handling thinking mode during streaming
README.md - Added new section for "DeepSeek R1 Now Support!" with description and image

Assessment against linked issues

Objective Addressed Explanation
Support DeepSeek reasoning_content COT display [#6104]
Display thinking process for reasoning models

Poem

🐰 A rabbit's tale of thinking clear,
DeepSeek's thoughts now drawing near
Reasoning flows, no longer shy
Each thought a star across the sky
Code dancing with intelligence bright! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dabb7c7 and 143be69.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • app/client/platforms/deepseek.ts (7 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nextchat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 30, 2025 4:36pm

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 using tools?.length instead of tools && 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 of streamWithThink 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 toggling console.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

📥 Commits

Reviewing files that changed from the base of the PR and between 553b8c9 and dabb7c7.

📒 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 of parseSSE.
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 the if (!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 to streamWithThink.
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 the getMessageTextContentWithoutThinking 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 by getMessageTextContentWithoutThinking.
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.

Comment on lines +379 to +380
funcs: Record<string, Function>,
controller: AbortController,
Copy link
Contributor

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.

Suggested change
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)

Copy link

vercel bot commented Jan 30, 2025

Deployment failed with the following error:

You don't have permission to create a Preview Deployment for this project.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@Leizhenpeng Leizhenpeng merged commit c41e86f into main Jan 30, 2025
1 check failed
@Kadxy Kadxy mentioned this pull request Jan 30, 2025
10 tasks
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.

[Feature Request] 请求支持deepseek的reasoning_content COT显示
3 participants