mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-18 02:27:30 +08:00
fix bug
This commit is contained in:
64
pkg/providers/http_provider_test.go
Normal file
64
pkg/providers/http_provider_test.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package providers
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseResponse_CompatFunctionCallXML(t *testing.T) {
|
||||
p := &HTTPProvider{}
|
||||
body := []byte(`{
|
||||
"choices": [{
|
||||
"message": {
|
||||
"content": "I need to check the current state and understand what was last worked on before proceeding.\n\n<function_call><invoke><toolname>exec</toolname><parameters><command>cd /root/clawgo && git status</command></parameters></invoke></function_call>\n\n<function_call><invoke><tool_name>read_file</tool_name><parameters><path>/root/.clawgo/workspace/memory/MEMORY.md</path></parameters></invoke></function_call>"
|
||||
},
|
||||
"finish_reason": "stop"
|
||||
}]
|
||||
}`)
|
||||
|
||||
resp, err := p.parseResponse(body)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if resp == nil {
|
||||
t.Fatalf("expected response")
|
||||
}
|
||||
if len(resp.ToolCalls) != 2 {
|
||||
t.Fatalf("expected 2 tool calls, got %d", len(resp.ToolCalls))
|
||||
}
|
||||
|
||||
if resp.ToolCalls[0].Name != "exec" {
|
||||
t.Fatalf("expected first tool exec, got %q", resp.ToolCalls[0].Name)
|
||||
}
|
||||
if got, ok := resp.ToolCalls[0].Arguments["command"].(string); !ok || got == "" {
|
||||
t.Fatalf("expected first tool command arg, got %#v", resp.ToolCalls[0].Arguments)
|
||||
}
|
||||
|
||||
if resp.ToolCalls[1].Name != "read_file" {
|
||||
t.Fatalf("expected second tool read_file, got %q", resp.ToolCalls[1].Name)
|
||||
}
|
||||
if got, ok := resp.ToolCalls[1].Arguments["path"].(string); !ok || got == "" {
|
||||
t.Fatalf("expected second tool path arg, got %#v", resp.ToolCalls[1].Arguments)
|
||||
}
|
||||
|
||||
if resp.Content == "" {
|
||||
t.Fatalf("expected non-empty cleaned content")
|
||||
}
|
||||
if containsFunctionCallMarkup(resp.Content) {
|
||||
t.Fatalf("expected function call markup removed from content, got %q", resp.Content)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseCompatFunctionCalls_NoMarkup(t *testing.T) {
|
||||
calls, cleaned := parseCompatFunctionCalls("hello")
|
||||
if len(calls) != 0 {
|
||||
t.Fatalf("expected 0 calls, got %d", len(calls))
|
||||
}
|
||||
if cleaned != "hello" {
|
||||
t.Fatalf("expected content unchanged, got %q", cleaned)
|
||||
}
|
||||
}
|
||||
|
||||
func containsFunctionCallMarkup(s string) bool {
|
||||
return len(s) > 0 && (strings.Contains(s, "<function_call>") || strings.Contains(s, "</function_call>"))
|
||||
}
|
||||
Reference in New Issue
Block a user