llms/ollama: fix panic when context is cancelled during streaming (#1372)

Handle case where Message might be nil (e.g., context cancelled during streaming)
by checking for nil before accessing Message.Content.

Fixes #774
This commit is contained in:
Travis Cline
2025-08-19 19:35:18 +02:00
committed by GitHub
parent fd8379f966
commit 9fc3d0aa27
+7 -1
View File
@@ -156,9 +156,15 @@ func (o *LLM) GenerateContent(ctx context.Context, messages []llms.MessageConten
return nil, err
}
// Handle case where Message might be nil (e.g., context cancelled during streaming)
content := ""
if resp.Message != nil {
content = resp.Message.Content
}
choices := []*llms.ContentChoice{
{
Content: resp.Message.Content,
Content: content,
GenerationInfo: map[string]any{
"CompletionTokens": resp.EvalCount,
"PromptTokens": resp.PromptEvalCount,