mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-17 14:45:11 +08:00
fix(toolcall): fix deepseek function calling bug and add json repair
- Fix: Expand stream sieve keywords to support function.name: and [TOOL_CALL_HISTORY] - Fix: Add repairInvalidJSONBackslashes to handle unescaped backslashes in Windows paths - Sync: Update JS stream sieve to match Go implementation - Test: Add unit tests for backslash repair and deepseek format parsing - Tool: Move repair json test tool to tests/repair_json_tool.go
This commit is contained in:
@@ -167,13 +167,28 @@ func findToolSegmentStart(s string) int {
|
||||
return -1
|
||||
}
|
||||
lower := strings.ToLower(s)
|
||||
keywords := []string{"tool_calls", "function.name:", "[tool_call_history]"}
|
||||
offset := 0
|
||||
for {
|
||||
keyRel := strings.Index(lower[offset:], "tool_calls")
|
||||
if keyRel < 0 {
|
||||
bestKeyIdx := -1
|
||||
matchedKeyword := ""
|
||||
|
||||
for _, kw := range keywords {
|
||||
idx := strings.Index(lower[offset:], kw)
|
||||
if idx >= 0 {
|
||||
absIdx := offset + idx
|
||||
if bestKeyIdx < 0 || absIdx < bestKeyIdx {
|
||||
bestKeyIdx = absIdx
|
||||
matchedKeyword = kw
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if bestKeyIdx < 0 {
|
||||
return -1
|
||||
}
|
||||
keyIdx := offset + keyRel
|
||||
|
||||
keyIdx := bestKeyIdx
|
||||
start := strings.LastIndex(s[:keyIdx], "{")
|
||||
if start < 0 {
|
||||
start = keyIdx
|
||||
@@ -181,7 +196,7 @@ func findToolSegmentStart(s string) int {
|
||||
if !insideCodeFence(s[:start]) {
|
||||
return start
|
||||
}
|
||||
offset = keyIdx + len("tool_calls")
|
||||
offset = keyIdx + len(matchedKeyword)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user