diff options
| author | Grail Finder <wohilas@gmail.com> | 2026-03-03 14:13:18 +0300 |
|---|---|---|
| committer | Grail Finder <wohilas@gmail.com> | 2026-03-03 14:13:18 +0300 |
| commit | fb4deb1161cca50d1affea850f842c7683647ecd (patch) | |
| tree | 6f122bccaca9a0254d8da8c7d5da325479af0de2 /llm.go | |
| parent | 0e5d37666f92bc75f12f118fc77a7e4af4a5924b (diff) | |
Fix: handle empty choices
Diffstat (limited to 'llm.go')
| -rw-r--r-- | llm.go | 22 |
1 files changed, 18 insertions, 4 deletions
@@ -224,11 +224,9 @@ func (op LCPChat) ParseChunk(data []byte) (*models.TextChunk, error) { logger.Error("failed to decode", "error", err, "line", string(data)) return nil, err } - - // Handle multiple choices safely if len(llmchunk.Choices) == 0 { - logger.Warn("LCPChat ParseChunk: no choices in response", "data", string(data)) - return &models.TextChunk{Finished: true}, nil + logger.Warn("LCPChat empty chunk choices", "raw_data", string(data), "chunk", llmchunk) + return &models.TextChunk{}, nil } lastChoice := llmchunk.Choices[len(llmchunk.Choices)-1] resp := &models.TextChunk{ @@ -349,6 +347,10 @@ func (ds DeepSeekerCompletion) ParseChunk(data []byte) (*models.TextChunk, error logger.Error("failed to decode", "error", err, "line", string(data)) return nil, err } + if len(llmchunk.Choices) == 0 { + logger.Warn("empty chunk choices", "raw_data", string(data), "chunk", llmchunk) + return &models.TextChunk{}, nil + } resp := &models.TextChunk{ Chunk: llmchunk.Choices[0].Text, } @@ -414,6 +416,10 @@ func (ds DeepSeekerChat) ParseChunk(data []byte) (*models.TextChunk, error) { return nil, err } resp := &models.TextChunk{} + if len(llmchunk.Choices) == 0 { + logger.Warn("empty chunk choices", "raw_data", string(data), "chunk", llmchunk) + return resp, nil + } if llmchunk.Choices[0].FinishReason != "" { if llmchunk.Choices[0].Delta.Content != "" { logger.Error("text inside of finish llmchunk", "chunk", llmchunk) @@ -496,6 +502,10 @@ func (or OpenRouterCompletion) ParseChunk(data []byte) (*models.TextChunk, error logger.Error("failed to decode", "error", err, "line", string(data)) return nil, err } + if len(llmchunk.Choices) == 0 { + logger.Warn("empty chunk choices", "raw_data", string(data), "chunk", llmchunk) + return &models.TextChunk{}, nil + } resp := &models.TextChunk{ Chunk: llmchunk.Choices[len(llmchunk.Choices)-1].Text, } @@ -558,6 +568,10 @@ func (or OpenRouterChat) ParseChunk(data []byte) (*models.TextChunk, error) { logger.Error("failed to decode", "error", err, "line", string(data)) return nil, err } + if len(llmchunk.Choices) == 0 { + logger.Warn("empty chunk choices", "raw_data", string(data), "chunk", llmchunk) + return &models.TextChunk{}, nil + } lastChoice := llmchunk.Choices[len(llmchunk.Choices)-1] resp := &models.TextChunk{ Chunk: lastChoice.Delta.Content, |
