From d7d432b8a1dbea9e18f78d835112fa074051f587 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Fri, 8 Aug 2025 13:03:37 +0300 Subject: Enha: /chat /completions tool calls to live in peace --- llm.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'llm.go') diff --git a/llm.go b/llm.go index c5f10ea..3c3085f 100644 --- a/llm.go +++ b/llm.go @@ -142,8 +142,10 @@ func (op OpenAIer) ParseChunk(data []byte) (*models.TextChunk, error) { return nil, err } resp := &models.TextChunk{ - Chunk: llmchunk.Choices[len(llmchunk.Choices)-1].Delta.Content, - ToolChunk: llmchunk.Choices[len(llmchunk.Choices)-1].Delta.ToolCalls[0].Function.Arguments, + 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 } if llmchunk.Choices[len(llmchunk.Choices)-1].FinishReason == "stop" { if resp.Chunk != "" { -- cgit v1.2.3