@@ -104,6 +104,12 @@ type ChatCompletionMessage struct {
104
104
// - https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb
105
105
Name string `json:"name,omitempty"`
106
106
107
+ // This property is used for the "reasoning" feature supported by deepseek-reasoner
108
+ // which is not in the official documentation.
109
+ // the doc from deepseek:
110
+ // - https://api-docs.deepseek.com/api/create-chat-completion#responses
111
+ ReasoningContent string `json:"reasoning_content,omitempty"`
112
+
107
113
FunctionCall * FunctionCall `json:"function_call,omitempty"`
108
114
109
115
// For Role=assistant prompts this may be set to the tool calls generated by the model, such as function calls.
@@ -119,56 +125,60 @@ func (m ChatCompletionMessage) MarshalJSON() ([]byte, error) {
119
125
}
120
126
if len (m .MultiContent ) > 0 {
121
127
msg := struct {
122
- Role string `json:"role"`
123
- Content string `json:"-"`
124
- Refusal string `json:"refusal,omitempty"`
125
- MultiContent []ChatMessagePart `json:"content,omitempty"`
126
- Name string `json:"name,omitempty"`
127
- FunctionCall * FunctionCall `json:"function_call,omitempty"`
128
- ToolCalls []ToolCall `json:"tool_calls,omitempty"`
129
- ToolCallID string `json:"tool_call_id,omitempty"`
128
+ Role string `json:"role"`
129
+ Content string `json:"-"`
130
+ Refusal string `json:"refusal,omitempty"`
131
+ MultiContent []ChatMessagePart `json:"content,omitempty"`
132
+ Name string `json:"name,omitempty"`
133
+ ReasoningContent string `json:"reasoning_content,omitempty"`
134
+ FunctionCall * FunctionCall `json:"function_call,omitempty"`
135
+ ToolCalls []ToolCall `json:"tool_calls,omitempty"`
136
+ ToolCallID string `json:"tool_call_id,omitempty"`
130
137
}(m )
131
138
return json .Marshal (msg )
132
139
}
133
140
134
141
msg := struct {
135
- Role string `json:"role"`
136
- Content string `json:"content,omitempty"`
137
- Refusal string `json:"refusal,omitempty"`
138
- MultiContent []ChatMessagePart `json:"-"`
139
- Name string `json:"name,omitempty"`
140
- FunctionCall * FunctionCall `json:"function_call,omitempty"`
141
- ToolCalls []ToolCall `json:"tool_calls,omitempty"`
142
- ToolCallID string `json:"tool_call_id,omitempty"`
142
+ Role string `json:"role"`
143
+ Content string `json:"content,omitempty"`
144
+ Refusal string `json:"refusal,omitempty"`
145
+ MultiContent []ChatMessagePart `json:"-"`
146
+ Name string `json:"name,omitempty"`
147
+ ReasoningContent string `json:"reasoning_content,omitempty"`
148
+ FunctionCall * FunctionCall `json:"function_call,omitempty"`
149
+ ToolCalls []ToolCall `json:"tool_calls,omitempty"`
150
+ ToolCallID string `json:"tool_call_id,omitempty"`
143
151
}(m )
144
152
return json .Marshal (msg )
145
153
}
146
154
147
155
func (m * ChatCompletionMessage ) UnmarshalJSON (bs []byte ) error {
148
156
msg := struct {
149
- Role string `json:"role"`
150
- Content string `json:"content,omitempty"`
151
- Refusal string `json:"refusal,omitempty"`
152
- MultiContent []ChatMessagePart
153
- Name string `json:"name,omitempty"`
154
- FunctionCall * FunctionCall `json:"function_call,omitempty"`
155
- ToolCalls []ToolCall `json:"tool_calls,omitempty"`
156
- ToolCallID string `json:"tool_call_id,omitempty"`
157
+ Role string `json:"role"`
158
+ Content string `json:"content"`
159
+ Refusal string `json:"refusal,omitempty"`
160
+ MultiContent []ChatMessagePart
161
+ Name string `json:"name,omitempty"`
162
+ ReasoningContent string `json:"reasoning_content,omitempty"`
163
+ FunctionCall * FunctionCall `json:"function_call,omitempty"`
164
+ ToolCalls []ToolCall `json:"tool_calls,omitempty"`
165
+ ToolCallID string `json:"tool_call_id,omitempty"`
157
166
}{}
158
167
159
168
if err := json .Unmarshal (bs , & msg ); err == nil {
160
169
* m = ChatCompletionMessage (msg )
161
170
return nil
162
171
}
163
172
multiMsg := struct {
164
- Role string `json:"role"`
165
- Content string
166
- Refusal string `json:"refusal,omitempty"`
167
- MultiContent []ChatMessagePart `json:"content"`
168
- Name string `json:"name,omitempty"`
169
- FunctionCall * FunctionCall `json:"function_call,omitempty"`
170
- ToolCalls []ToolCall `json:"tool_calls,omitempty"`
171
- ToolCallID string `json:"tool_call_id,omitempty"`
173
+ Role string `json:"role"`
174
+ Content string
175
+ Refusal string `json:"refusal,omitempty"`
176
+ MultiContent []ChatMessagePart `json:"content"`
177
+ Name string `json:"name,omitempty"`
178
+ ReasoningContent string `json:"reasoning_content,omitempty"`
179
+ FunctionCall * FunctionCall `json:"function_call,omitempty"`
180
+ ToolCalls []ToolCall `json:"tool_calls,omitempty"`
181
+ ToolCallID string `json:"tool_call_id,omitempty"`
172
182
}{}
173
183
if err := json .Unmarshal (bs , & multiMsg ); err != nil {
174
184
return err
0 commit comments