| 26 | } |
| 27 | |
| 28 | func TestParserStreamingChunked(t *testing.T) { |
| 29 | p := NewParser() |
| 30 | // 模型分段发出 |
| 31 | segments := []string{ |
| 32 | "让我先", |
| 33 | "查一下文件:", |
| 34 | "<tool_call>", |
| 35 | `{"name": "bash",`, |
| 36 | ` "arguments": {"command": "ls"}}`, |
| 37 | "</tool_call>", |
| 38 | " ", |
| 39 | } |
| 40 | var allText string |
| 41 | var allCalls []official.ToolCall |
| 42 | for _, s := range segments { |
| 43 | txt, calls := p.Feed(s) |
| 44 | allText += txt |
| 45 | allCalls = append(allCalls, calls...) |
| 46 | } |
| 47 | if allText != "让我先查一下文件: " { |
| 48 | t.Fatalf("concatenated text = %q", allText) |
| 49 | } |
| 50 | if len(allCalls) != 1 { |
| 51 | t.Fatalf("calls = %d", len(allCalls)) |
| 52 | } |
| 53 | if allCalls[0].Function.Name != "bash" { |
| 54 | t.Fatalf("name = %q", allCalls[0].Function.Name) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func TestParserMultipleCalls(t *testing.T) { |
| 59 | p := NewParser() |