diff --git a/internal/llm/provider/openai.go b/internal/llm/provider/openai.go index eb5a84867aecf0a76b30a7c022ccb14bf6a2139a..1a780a74f79d0fe3c41db06145b8a9b79c72802c 100644 --- a/internal/llm/provider/openai.go +++ b/internal/llm/provider/openai.go @@ -340,6 +340,7 @@ func (o *openaiClient) stream(ctx context.Context, messages []message.Message, t toolCalls := make([]message.ToolCall, 0) msgToolCalls := make(map[int64]openai.ChatCompletionMessageToolCall) toolMap := make(map[string]openai.ChatCompletionMessageToolCall) + toolCallIDMap := make(map[string]string) for openaiStream.Next() { chunk := openaiStream.Current() // Kujtim: this is an issue with openrouter qwen, its sending -1 for the tool index @@ -367,6 +368,15 @@ func (o *openaiClient) stream(ctx context.Context, messages []message.Message, t currentContent += choice.Delta.Content } else if len(choice.Delta.ToolCalls) > 0 { toolCall := choice.Delta.ToolCalls[0] + if strings.HasPrefix(toolCall.ID, "functions.") { + exID, ok := toolCallIDMap[toolCall.ID] + if !ok { + newID := uuid.NewString() + toolCallIDMap[toolCall.ID] = newID + toolCall.ID = newID + } + toolCall.ID = exID + } newToolCall := false if existingToolCall, ok := msgToolCalls[toolCall.Index]; ok { // tool call exists if toolCall.ID != "" && toolCall.ID != existingToolCall.ID {