diff --git a/cmd/main.go b/cmd/main.go index 4ddbbfd..f135750 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -15,7 +15,7 @@ import ( "github.com/YspCoder/clawgo/pkg/logger" ) -var version = "1.2.9" +var version = "1.2.10" var buildTime = "unknown" const logo = ">" diff --git a/pkg/providers/openai_compat_adapter.go b/pkg/providers/openai_compat_adapter.go index 5911de1..9914c26 100644 --- a/pkg/providers/openai_compat_adapter.go +++ b/pkg/providers/openai_compat_adapter.go @@ -52,6 +52,10 @@ func parseOpenAICompatResponse(body []byte) (*LLMResponse, error) { if len(choice.Message.ToolCalls) > 0 { resp.ToolCalls = make([]ToolCall, 0, len(choice.Message.ToolCalls)) for _, tc := range choice.Message.ToolCalls { + args := map[string]interface{}{} + if strings.TrimSpace(tc.Function.Arguments) != "" { + _ = json.Unmarshal([]byte(tc.Function.Arguments), &args) + } resp.ToolCalls = append(resp.ToolCalls, ToolCall{ ID: tc.ID, Type: tc.Type, @@ -59,7 +63,8 @@ func parseOpenAICompatResponse(body []byte) (*LLMResponse, error) { Name: tc.Function.Name, Arguments: tc.Function.Arguments, }, - Name: tc.Function.Name, + Name: tc.Function.Name, + Arguments: args, }) } } diff --git a/pkg/providers/openai_compat_provider_test.go b/pkg/providers/openai_compat_provider_test.go index 76d46e1..bba8220 100644 --- a/pkg/providers/openai_compat_provider_test.go +++ b/pkg/providers/openai_compat_provider_test.go @@ -226,6 +226,22 @@ func TestParseOpenAICompatResponseCapturesReasoningContent(t *testing.T) { } } +func TestParseOpenAICompatResponsePopulatesToolArgumentsMap(t *testing.T) { + resp, err := parseOpenAICompatResponse([]byte(`{"choices":[{"message":{"tool_calls":[{"id":"call_1","type":"function","function":{"name":"remind","arguments":"{\"message\":\"开会\",\"time_expr\":\"10m\"}"}}]},"finish_reason":"tool_calls"}]}`)) + if err != nil { + t.Fatalf("parseOpenAICompatResponse error: %v", err) + } + if len(resp.ToolCalls) != 1 { + t.Fatalf("tool calls = %#v, want one call", resp.ToolCalls) + } + if got := asString(resp.ToolCalls[0].Arguments["message"]); got != "开会" { + t.Fatalf("message = %q, want 开会", got) + } + if got := asString(resp.ToolCalls[0].Arguments["time_expr"]); got != "10m" { + t.Fatalf("time_expr = %q, want 10m", got) + } +} + func TestOpenAICompatMessagesIncludeReasoningContent(t *testing.T) { msgs := openAICompatMessages([]Message{{ Role: "assistant",