Add concurrent tool calls

This commit is contained in:
dwrz
2026-07-08 01:59:11 +00:00
parent f85a9eeb3f
commit 6592bae15d
2 changed files with 58 additions and 50 deletions

View File

@@ -97,10 +97,7 @@ func (c *Client) Completions(
Timings: finalTimings,
}, nil
}
toolResults, err := c.callTools(ctx, *message)
if err != nil {
return nil, fmt.Errorf("completions: %w", err)
}
toolResults := c.callTools(ctx, *message)
messages = append(messages, toolResults...)
}
@@ -126,6 +123,7 @@ func (c *Client) completions(
Tools: c.tools,
ThinkingBudgetTokens: thinkingBudgetTokens,
ChatTemplateKWARGS: kwargs,
ParallelToolCalls: new(true),
})
if err != nil {
return nil, fmt.Errorf(
@@ -286,10 +284,7 @@ func (c *Client) CompletionsStream(
if len(message.ToolCalls) == 0 {
return nil
}
toolResults, err := c.callTools(ctx, message)
if err != nil {
return fmt.Errorf("completions stream: %w", err)
}
toolResults := c.callTools(ctx, message)
for _, tr := range toolResults {
events <- StreamEvent{
Type: streamEventMessage,
@@ -328,6 +323,7 @@ func (c *Client) completionsStream(ctx context.Context, messages []Message, mode
Tools: c.tools,
ThinkingBudgetTokens: thinkingBudgetTokens,
ChatTemplateKWARGS: kwargs,
ParallelToolCalls: new(true),
StreamOptions: &StreamOptions{IncludeUsage: true},
})
if err != nil {