Skip to content

Commit e025915

Browse files
committed
add comment on field reasoning_content
1 parent 5fef03f commit e025915

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

chat.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,22 @@ type ChatMessagePart struct {
9292
}
9393

9494
type ChatCompletionMessage struct {
95-
Role string `json:"role"`
96-
ReasoningContent string `json:"reasoning_content,omitempty"`
97-
Content string `json:"content"`
98-
Refusal string `json:"refusal,omitempty"`
99-
MultiContent []ChatMessagePart
95+
Role string `json:"role"`
96+
Content string `json:"content"`
97+
Refusal string `json:"refusal,omitempty"`
98+
MultiContent []ChatMessagePart
10099

101100
// This property isn't in the official documentation, but it's in
102101
// the documentation for the official library for python:
103102
// - https://github.com/openai/openai-python/blob/main/chatml.md
104103
// - https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb
105104
Name string `json:"name,omitempty"`
106105

106+
// This property is used for the "reasoning" feature supported by deepseek-reasoner which is not in the official documentation.
107+
// the doc from deepseek:
108+
// - https://api-docs.deepseek.com/api/create-chat-completion#responses
109+
ReasoningContent string `json:"reasoning_content,omitempty"`
110+
107111
FunctionCall *FunctionCall `json:"function_call,omitempty"`
108112

109113
// For Role=assistant prompts this may be set to the tool calls generated by the model, such as function calls.
@@ -120,11 +124,11 @@ func (m ChatCompletionMessage) MarshalJSON() ([]byte, error) {
120124
if len(m.MultiContent) > 0 {
121125
msg := struct {
122126
Role string `json:"role"`
123-
ReasoningContent string `json:"reasoning_content,omitempty"`
124127
Content string `json:"-"`
125128
Refusal string `json:"refusal,omitempty"`
126129
MultiContent []ChatMessagePart `json:"content,omitempty"`
127130
Name string `json:"name,omitempty"`
131+
ReasoningContent string `json:"reasoning_content,omitempty"`
128132
FunctionCall *FunctionCall `json:"function_call,omitempty"`
129133
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
130134
ToolCallID string `json:"tool_call_id,omitempty"`
@@ -134,11 +138,11 @@ func (m ChatCompletionMessage) MarshalJSON() ([]byte, error) {
134138

135139
msg := struct {
136140
Role string `json:"role"`
137-
ReasoningContent string `json:"reasoning_content,omitempty"`
138141
Content string `json:"content"`
139142
Refusal string `json:"refusal,omitempty"`
140143
MultiContent []ChatMessagePart `json:"-"`
141144
Name string `json:"name,omitempty"`
145+
ReasoningContent string `json:"reasoning_content,omitempty"`
142146
FunctionCall *FunctionCall `json:"function_call,omitempty"`
143147
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
144148
ToolCallID string `json:"tool_call_id,omitempty"`
@@ -149,11 +153,11 @@ func (m ChatCompletionMessage) MarshalJSON() ([]byte, error) {
149153
func (m *ChatCompletionMessage) UnmarshalJSON(bs []byte) error {
150154
msg := struct {
151155
Role string `json:"role"`
152-
ReasoningContent string `json:"reasoning_content,omitempty"`
153156
Content string `json:"content"`
154157
Refusal string `json:"refusal,omitempty"`
155158
MultiContent []ChatMessagePart
156159
Name string `json:"name,omitempty"`
160+
ReasoningContent string `json:"reasoning_content,omitempty"`
157161
FunctionCall *FunctionCall `json:"function_call,omitempty"`
158162
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
159163
ToolCallID string `json:"tool_call_id,omitempty"`
@@ -165,11 +169,11 @@ func (m *ChatCompletionMessage) UnmarshalJSON(bs []byte) error {
165169
}
166170
multiMsg := struct {
167171
Role string `json:"role"`
168-
ReasoningContent string `json:"reasoning_content,omitempty"`
169172
Content string
170173
Refusal string `json:"refusal,omitempty"`
171174
MultiContent []ChatMessagePart `json:"content"`
172175
Name string `json:"name,omitempty"`
176+
ReasoningContent string `json:"reasoning_content,omitempty"`
173177
FunctionCall *FunctionCall `json:"function_call,omitempty"`
174178
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
175179
ToolCallID string `json:"tool_call_id,omitempty"`

chat_stream.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ import (
66
)
77

88
type ChatCompletionStreamChoiceDelta struct {
9-
Content string `json:"content,omitempty"`
10-
ReasoningContent string `json:"reasoning_content,omitempty"`
11-
Role string `json:"role,omitempty"`
12-
FunctionCall *FunctionCall `json:"function_call,omitempty"`
13-
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
14-
Refusal string `json:"refusal,omitempty"`
9+
Content string `json:"content,omitempty"`
10+
Role string `json:"role,omitempty"`
11+
FunctionCall *FunctionCall `json:"function_call,omitempty"`
12+
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
13+
Refusal string `json:"refusal,omitempty"`
14+
15+
// This property is used for the "reasoning" feature supported by deepseek-reasoner which is not in the official documentation.
16+
// the doc from deepseek:
17+
// - https://api-docs.deepseek.com/api/create-chat-completion#responses
18+
ReasoningContent string `json:"reasoning_content,omitempty"`
1519
}
1620

1721
type ChatCompletionStreamChoiceLogprobs struct {

0 commit comments

Comments
 (0)