@@ -46,6 +46,12 @@ func TestChatCompletionStreamChoiceDelta_ReasoningFieldSupport(t *testing.T) {
4646 jsonData : `{"role":"assistant","reasoning_content":"","reasoning":"Fallback value"}` ,
4747 expected : "Fallback value" ,
4848 },
49+ {
50+ name : "Non-empty reasoning_content, empty reasoning" ,
51+ jsonData : `{"role":"assistant","content":"Hello",` +
52+ `"reasoning_content":"Primary","reasoning":""}` ,
53+ expected : "Primary" ,
54+ },
4955 }
5056
5157 for _ , tt := range tests {
@@ -73,6 +79,41 @@ func TestChatCompletionStreamChoiceDelta_UnmarshalError(t *testing.T) {
7379 }
7480}
7581
82+ // TestChatCompletionStreamChoiceDelta_AllFields tests unmarshaling with all fields.
83+ func TestChatCompletionStreamChoiceDelta_AllFields (t * testing.T ) {
84+ jsonData := `{
85+ "role":"assistant",
86+ "content":"test content",
87+ "refusal":"test refusal",
88+ "reasoning":"test reasoning",
89+ "function_call":{"name":"test_func","arguments":"{}"},
90+ "tool_calls":[{"id":"call_123","type":"function","function":{"name":"test","arguments":"{}"}}]
91+ }`
92+ var delta openai.ChatCompletionStreamChoiceDelta
93+ err := json .Unmarshal ([]byte (jsonData ), & delta )
94+ if err != nil {
95+ t .Fatalf ("Failed to unmarshal JSON: %v" , err )
96+ }
97+ if delta .Role != "assistant" {
98+ t .Errorf ("Expected Role to be 'assistant', got %q" , delta .Role )
99+ }
100+ if delta .Content != "test content" {
101+ t .Errorf ("Expected Content to be 'test content', got %q" , delta .Content )
102+ }
103+ if delta .Refusal != "test refusal" {
104+ t .Errorf ("Expected Refusal to be 'test refusal', got %q" , delta .Refusal )
105+ }
106+ if delta .ReasoningContent != "test reasoning" {
107+ t .Errorf ("Expected ReasoningContent to be 'test reasoning', got %q" , delta .ReasoningContent )
108+ }
109+ if delta .FunctionCall == nil || delta .FunctionCall .Name != "test_func" {
110+ t .Error ("Expected FunctionCall to be set" )
111+ }
112+ if len (delta .ToolCalls ) != 1 || delta .ToolCalls [0 ].ID != "call_123" {
113+ t .Error ("Expected ToolCalls to be set" )
114+ }
115+ }
116+
76117// TestChatCompletionMessage_ReasoningFieldSupport tests that both
77118// reasoning_content and reasoning fields are properly supported in chat completion messages.
78119func TestChatCompletionMessage_ReasoningFieldSupport (t * testing.T ) {
@@ -112,6 +153,12 @@ func TestChatCompletionMessage_ReasoningFieldSupport(t *testing.T) {
112153 jsonData : `{"role":"assistant","reasoning_content":"","reasoning":"Fallback value"}` ,
113154 expected : "Fallback value" ,
114155 },
156+ {
157+ name : "Non-empty reasoning_content, empty reasoning" ,
158+ jsonData : `{"role":"assistant","content":"Hello",` +
159+ `"reasoning_content":"Primary","reasoning":""}` ,
160+ expected : "Primary" ,
161+ },
115162 }
116163
117164 for _ , tt := range tests {
0 commit comments