( apiKey string, baseURL string, model string, maxTokens int, thinkingBudgetTokens *int, retryConfig *RetryConfig, apiType ...string, )
| 867 | } |
| 868 | |
| 869 | if finishReason == "tool_calls" { |
| 870 | indexes := make([]int, 0, len(toolCallBuffers)) |
| 871 | for idx := range toolCallBuffers { |
| 872 | indexes = append(indexes, idx) |
| 873 | } |
| 874 | sort.Ints(indexes) |
| 875 | |
| 876 | for _, idx := range indexes { |
| 877 | buf := toolCallBuffers[idx] |
| 878 | if buf.Name != "" { |
| 879 | parsed := map[string]any{} |
| 880 | if strings.TrimSpace(buf.Arguments) != "" { |
| 881 | if err := json.Unmarshal([]byte(buf.Arguments), &parsed); err != nil { |
| 882 | parsed = map[string]any{} |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | out <- EventResult{Event: map[string]any{ |
| 887 | "type": "tool_use", |
| 888 | "id": buf.ID, |
| 889 | "name": buf.Name, |
| 890 | "input": parsed, |
| 891 | }} |
| 892 | } else if buf.Arguments != "" { |
| 893 | out <- EventResult{Event: map[string]any{ |
| 894 | "type": "error", |
| 895 | "message": fmt.Sprintf("Tool call at index %d is missing a function name; arguments were: %s", idx, truncateString(buf.Arguments, 200)), |
no test coverage detected