mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-05 00:45:29 +08:00
Merge pull request #85 from CJackHwang/revert-84-codex/fix-code-conflicts-in-pr-#82
Revert "Resolve PR #82 merge conflicts and restore tool-call parsing (invoke/argument and XML arguments)"
This commit is contained in:
@@ -15,7 +15,6 @@ var antmlArgumentPattern = regexp.MustCompile(`(?is)<(?:[a-z0-9_]+:)?argument\s+
|
||||
var antmlParametersPattern = regexp.MustCompile(`(?is)<(?:[a-z0-9_]+:)?parameters\s*>\s*(\{.*?\})\s*</(?:[a-z0-9_]+:)?parameters>`)
|
||||
var invokeCallPattern = regexp.MustCompile(`(?is)<invoke\s+name="([^"]+)"\s*>(.*?)</invoke>`)
|
||||
var invokeParamPattern = regexp.MustCompile(`(?is)<parameter\s+name="([^"]+)"\s*>\s*(.*?)\s*</parameter>`)
|
||||
var invokeArgumentPattern = regexp.MustCompile(`(?is)<argument(?:\s+name="([^"]+)")?\s*>\s*(.*?)\s*</argument>`)
|
||||
|
||||
func parseXMLToolCalls(text string) []ParsedToolCall {
|
||||
matches := xmlToolCallPattern.FindAllString(text, -1)
|
||||
@@ -112,14 +111,6 @@ func parseSingleXMLToolCall(block string) (ParsedToolCall, bool) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if fallback := parseMarkupSingleToolCall("", inner); fallback.Name != "" {
|
||||
if strings.TrimSpace(name) == "" {
|
||||
name = fallback.Name
|
||||
}
|
||||
if len(params) == 0 && strings.EqualFold(strings.TrimSpace(fallback.Name), strings.TrimSpace(name)) {
|
||||
params = fallback.Input
|
||||
}
|
||||
}
|
||||
if strings.TrimSpace(name) == "" {
|
||||
return ParsedToolCall{}, false
|
||||
}
|
||||
@@ -219,23 +210,6 @@ func parseInvokeFunctionCallStyle(text string) (ParsedToolCall, bool) {
|
||||
input[k] = v
|
||||
}
|
||||
}
|
||||
for _, am := range invokeArgumentPattern.FindAllStringSubmatch(m[2], -1) {
|
||||
if len(am) < 3 {
|
||||
continue
|
||||
}
|
||||
key := strings.TrimSpace(am[1])
|
||||
raw := strings.TrimSpace(am[2])
|
||||
if raw == "" {
|
||||
continue
|
||||
}
|
||||
if key != "" {
|
||||
input[key] = raw
|
||||
continue
|
||||
}
|
||||
for k, v := range parseToolCallInput(raw) {
|
||||
input[k] = v
|
||||
}
|
||||
}
|
||||
return ParsedToolCall{Name: name, Input: input}, true
|
||||
}
|
||||
|
||||
|
||||
@@ -271,6 +271,7 @@ func TestParseToolCallsSupportsMultipleAntmlFunctionCalls(t *testing.T) {
|
||||
t.Fatalf("expected canonical names [bash read], got %#v", calls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseToolCallsDoesNotAcceptMismatchedMarkupTags(t *testing.T) {
|
||||
text := `<tool_call><name>read_file</function><arguments>{"path":"README.md"}</arguments></tool_call>`
|
||||
calls := ParseToolCalls(text, []string{"read_file"})
|
||||
|
||||
Reference in New Issue
Block a user