From 01da37b3971a6aa1c3c051c34666672b339ae2b6 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Tue, 25 Nov 2025 11:40:37 +0300 Subject: Fix: openrouter func ctx resp --- llm.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'llm.go') diff --git a/llm.go b/llm.go index 47a1d46..e7245ce 100644 --- a/llm.go +++ b/llm.go @@ -160,11 +160,14 @@ func (op OpenAIer) ParseChunk(data []byte) (*models.TextChunk, error) { Chunk: llmchunk.Choices[len(llmchunk.Choices)-1].Delta.Content, } if len(llmchunk.Choices[len(llmchunk.Choices)-1].Delta.ToolCalls) > 0 { - resp.ToolChunk = llmchunk.Choices[len(llmchunk.Choices)-1].Delta.ToolCalls[0].Function.Arguments - fname := llmchunk.Choices[len(llmchunk.Choices)-1].Delta.ToolCalls[0].Function.Name + toolCall := llmchunk.Choices[len(llmchunk.Choices)-1].Delta.ToolCalls[0] + resp.ToolChunk = toolCall.Function.Arguments + fname := toolCall.Function.Name if fname != "" { resp.FuncName = fname } + // Capture the tool call ID if available + resp.ToolID = toolCall.ID } if llmchunk.Choices[len(llmchunk.Choices)-1].FinishReason == "stop" { if resp.Chunk != "" { @@ -471,11 +474,14 @@ func (or OpenRouterChat) ParseChunk(data []byte) (*models.TextChunk, error) { // Handle tool calls similar to OpenAIer if len(llmchunk.Choices[len(llmchunk.Choices)-1].Delta.ToolCalls) > 0 { - resp.ToolChunk = llmchunk.Choices[len(llmchunk.Choices)-1].Delta.ToolCalls[0].Function.Arguments - fname := llmchunk.Choices[len(llmchunk.Choices)-1].Delta.ToolCalls[0].Function.Name + toolCall := llmchunk.Choices[len(llmchunk.Choices)-1].Delta.ToolCalls[0] + resp.ToolChunk = toolCall.Function.Arguments + fname := toolCall.Function.Name if fname != "" { resp.FuncName = fname } + // Capture the tool call ID if available + resp.ToolID = toolCall.ID } if resp.ToolChunk != "" { resp.ToolResp = true -- cgit v1.2.3