Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.
openai: keep empty tool results sent as an empty content array
Dong Chen77cef85de46d
diff --git a/openai/openai.go b/openai/openai.goindex efed4e048..a3cc19a65 100644--- a/openai/openai.go+++ b/openai/openai.go@@ -685,7 +685,7 @@ func FromChatRequest(r ChatCompletionRequest, thinking ...*model.Thinking) (*api}// a tool message is a single result, so keep its parts together and// preserve the tool call it answers- if strings.ToLower(msg.Role) == "tool" && len(messages) > start {+ if strings.ToLower(msg.Role) == "tool" && (len(messages) > start || toolName != "" || msg.ToolCallID != "") {tool := api.Message{Role: msg.Role, ToolName: toolName, ToolCallID: msg.ToolCallID}for _, part := range messages[start:] {tool.Content += part.Contentdiff --git a/openai/openai_test.go b/openai/openai_test.goindex 9f32d1df8..6d72a9907 100644--- a/openai/openai_test.go+++ b/openai/openai_test.go@@ -211,6 +211,31 @@ func TestFromChatRequest_ToolMessageArrayContent(t *testing.T) {}}+func TestFromChatRequest_ToolMessageEmptyArrayContent(t *testing.T) {+ var req ChatCompletionRequest+ if err := json.Unmarshal([]byte(`{"model":"test-model","messages":[+ {"role":"assistant","tool_calls":[{"id":"call_1","type":"function","function":{"name":"screenshot","arguments":"{}"}}]},+ {"role":"tool","tool_call_id":"call_1","content":[]},+ {"role":"tool","content":[]}+ ]}`), &req); err != nil {+ t.Fatal(err)+ }++ result, err := FromChatRequest(req)+ if err != nil {+ t.Fatalf("unexpected error: %v", err)+ }++ // the empty result without a call id or name is skipped+ if len(result.Messages) != 2 {+ t.Fatalf("expected 2 messages, got %d", len(result.Messages))+ }+ tool := result.Messages[1]+ if tool.Role != "tool" || tool.ToolCallID != "call_1" || tool.ToolName != "screenshot" || tool.Content != "" {+ t.Errorf("expected empty tool message for call_1/screenshot, got role=%q id=%q name=%q content=%q", tool.Role, tool.ToolCallID, tool.ToolName, tool.Content)+ }+}+func TestFromCompleteRequest_Basic(t *testing.T) {temp := float32(0.8)req := CompletionRequest{