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

Add support for reasoning_content field in chat completion messages for DeepSeek R1 #925

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

goodenough227
Copy link

@goodenough227 goodenough227 commented Jan 23, 2025

feat: Add support for reasoning_content field in chat completion messages

This PR adds support for the reasoning_content field in the ChatCompletionMessage struct to accommodate models that return their reasoning process separately from the main content. This feature is particularly useful for:

  • DeepSeek R1 model

Both models return their step-by-step reasoning process through this field.

Changes:

  • Added reasoning_content field to ChatCompletionMessage struct
  • Updated JSON marshaling/unmarshaling to handle the new field
  • Field is optional (omitempty) to maintain backwards compatibility

Example response structure:

{
    "role": "assistant",
    "reasoning_content": "1. First, I analyze the question...\n2. Based on the given information...",
    "content": "The final answer is..."
}

Copy link

codecov bot commented Jan 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.87%. Comparing base (774fc9d) to head (5273861).
Report is 85 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #925      +/-   ##
==========================================
+ Coverage   98.46%   98.87%   +0.41%     
==========================================
  Files          24       27       +3     
  Lines        1364     1783     +419     
==========================================
+ Hits         1343     1763     +420     
+ Misses         15       14       -1     
  Partials        6        6              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sashabaranov
Copy link
Owner

@goodenough227 could you please point to the OpenAI API reference for this one? Or is this field only supported by DeepSeek currently?

@yayanet
Copy link

yayanet commented Jan 26, 2025

@goodenough227 could you please point to the OpenAI API reference for this one? Or is this field only supported by DeepSeek currently?

I also have a need for this feature.
The reasoning_content field is currently specific to deepseek-reasoner model (docs)

@goodenough227 goodenough227 changed the title Add support for reasoning_content field in chat completion messages for DeepSeek R1 and OpenAI O1 Add support for reasoning_content field in chat completion messages for DeepSeek R1 Jan 26, 2025
@goodenough227
Copy link
Author

goodenough227 commented Jan 26, 2025

@goodenough227 could you please point to the OpenAI API reference for this one? Or is this field only supported by DeepSeek currently?

sorry for this wrong description generated by AI code hepler. "reasoning_content" field is only supported by deepseek R1 currently.

@sashabaranov
Copy link
Owner

Originally, this repository was targeted on the official OpenAI API. But, in the context of the official client popping up — I'm willing to merge this reasoning_content field that OpenAI API might not support.

My only ask here is: can we please clearly indicate that this field is not supported by OpenAI? Ideally, it should be obvious from the variable name and from reading the docs. Thank you!

@goodenough227
Copy link
Author

goodenough227 commented Feb 5, 2025

Originally, this repository was targeted on the official OpenAI API. But, in the context of the official client popping up — I'm willing to merge this reasoning_content field that OpenAI API might not support.

My only ask here is: can we please clearly indicate that this field is not supported by OpenAI? Ideally, it should be obvious from the variable name and from reading the docs. Thank you!

Get it. I have written a comment on this field.

# Conflicts:
#	chat.go
#	openai_test.go
@goodenough227 goodenough227 reopened this Feb 5, 2025
@goodenough227
Copy link
Author

@sashabaranov I have added comments in a similar way as in the previous code, please review

@He-hongjun
Copy link

Hope to merge and support this as soon as possible. Thank you for your contribution! @sashabaranov @goodenough227

@wangriyu
Copy link

wangriyu commented Mar 6, 2025

please review&approved, thank you @sashabaranov @goodenough227

@xiaozhi747
Copy link

mark

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.

6 participants