-
-
Notifications
You must be signed in to change notification settings - Fork 41
[Feature] Add DeepSeek reasoning content support #641
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
Conversation
…ctor message transformations - Add processDeepSeekThinkMessages function to handle reasoning_content for DeepSeek reasoner models - Extract transformSystemMessages function from langchainMessageToOpenAIMessage for better code organization - Support reasoning_content in ChatCompletionResponseMessage type - Fix bug in removeSystemMessage logic (was iterating over empty array) - Optimize image service plugin detection to avoid repeated lookups in read_chat_message - Bump shared-adapter version to 1.0.18 and update all adapter package dependencies The reasoning_content feature enables DeepSeek models to maintain their thinking process across multi-turn tool calling conversations by preserving reasoning_content from the last turn (starting from the last non-tool-call AI message).
|
Caution Review failedThe pull request is closed. 演练本PR在两个关键模块中引入条件逻辑优化。第一处为图像处理模块添加了插件可用性缓存标志,以优化重复检查。第二处为DeepSeek推理模型扩展了消息变换能力,包括系统消息过滤和推理内容合并功能。 变更
代码审查工作量估计🎯 3 (中等) | ⏱️ ~25 分钟 需要特别关注的领域:
可能相关的PR
诗
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro ⛔ Files ignored due to path filters (15)
📒 Files selected for processing (2)
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 @dingyi222666, 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 introduces comprehensive support for DeepSeek's reasoning mode, enabling the system to correctly process and retain Highlights
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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request is well-executed. It successfully adds support for DeepSeek's reasoning content, fixes a significant bug in the removeSystemMessage logic by refactoring it into transformSystemMessages, and introduces a sensible optimization for detecting the image service plugin. The dependency updates across the packages are also correctly handled. I have a couple of suggestions for the new utility functions in packages/shared-adapter/src/utils.ts to make them even more concise and idiomatic using modern array methods. Overall, great work on improving functionality and code quality.
| let lastTurnStartIndex = -1 | ||
| for (let i = originalMessages.length - 1; i >= 0; i--) { | ||
| const message = originalMessages[i] | ||
| if (message.getType() === 'ai') { | ||
| const aiMessage = message as AIMessage | ||
| // Check if it's a non-tool-call AI message | ||
| if (!aiMessage.tool_calls || aiMessage.tool_calls.length === 0) { | ||
| lastTurnStartIndex = i | ||
| break | ||
| } | ||
| } | ||
| } |
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.
The for loop to find the index of the last AI message can be simplified by using the Array.prototype.findLastIndex() method. This makes the intent of the code clearer and more declarative.
const lastTurnStartIndex = originalMessages.findLastIndex((message) => {
if (message.getType() !== 'ai') {
return false;
}
const aiMessage = message as AIMessage;
// Check if it's a non-tool-call AI message
return !aiMessage.tool_calls || aiMessage.tool_calls.length === 0;
});| export function transformSystemMessages( | ||
| messages: ChatCompletionResponseMessage[] | ||
| ): ChatCompletionResponseMessage[] { | ||
| const mappedMessage: ChatCompletionResponseMessage[] = [] | ||
|
|
||
| if (mappedMessage[0].role === 'assistant') { | ||
| mappedMessage.unshift({ | ||
| role: 'user', | ||
| content: | ||
| 'Continue what I said to you last time. Follow these instructions.' | ||
| }) | ||
| for (let i = 0; i < messages.length; i++) { | ||
| const message = messages[i] | ||
|
|
||
| if (message.role !== 'system') { | ||
| mappedMessage.push(message) | ||
| continue | ||
| } | ||
|
|
||
| return mappedMessage | ||
| // Skip system messages (remove them) | ||
| continue | ||
| } | ||
|
|
||
| return result | ||
| // Ensure the conversation doesn't end with an assistant message | ||
| if (mappedMessage[mappedMessage.length - 1]?.role === 'assistant') { | ||
| mappedMessage.push({ | ||
| role: 'user', | ||
| content: | ||
| 'Continue what I said to you last message. Follow these instructions.' | ||
| }) | ||
| } | ||
|
|
||
| // Ensure the conversation doesn't start with an assistant message | ||
| if (mappedMessage[0]?.role === 'assistant') { | ||
| mappedMessage.unshift({ | ||
| role: 'user', | ||
| content: | ||
| 'Continue what I said to you last time. Follow these instructions.' | ||
| }) | ||
| } | ||
|
|
||
| return mappedMessage | ||
| } |
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.
This function can be made more concise and readable by using the Array.prototype.filter() method to remove system messages, instead of a for loop. This is a more idiomatic way to handle array filtering in TypeScript. I've also added a guard for an empty array after filtering and removed the now-unnecessary optional chaining.
export function transformSystemMessages(
messages: ChatCompletionResponseMessage[]
): ChatCompletionResponseMessage[] {
const mappedMessage = messages.filter(
(message) => message.role !== 'system'
);
if (mappedMessage.length === 0) {
return mappedMessage;
}
// Ensure the conversation doesn't end with an assistant message
if (mappedMessage[mappedMessage.length - 1].role === 'assistant') {
mappedMessage.push({
role: 'user',
content:
'Continue what I said to you last message. Follow these instructions.'
});
}
// Ensure the conversation doesn't start with an assistant message
if (mappedMessage[0].role === 'assistant') {
mappedMessage.unshift({
role: 'user',
content:
'Continue what I said to you last time. Follow these instructions.'
});
}
return mappedMessage;
}
This PR adds support for DeepSeek's reasoning mode and refactors message transformation utilities.
New Features
processDeepSeekThinkMessagesfunction to preserve reasoning_content for DeepSeek reasoner models during multi-turn tool callingreasoning_contentfield in message transformationsBug Fixes
removeSystemMessagelogic that was iterating over empty arrayOther Changes
transformSystemMessagesfunction for better code organization