From a3cbe208587621a8baffff99dd34a6aba4039443 Mon Sep 17 00:00:00 2001 From: Jeffrey Lee <572199+darkthread@users.noreply.github.com> Date: Thu, 7 Mar 2024 02:37:43 +0800 Subject: [PATCH] =?UTF-8?q?Check=20if=20response=20has=20a=20choice=20befo?= =?UTF-8?q?re=20debug=20logging=20to=20prevent=20null=20r=E2=80=A6=20(#117?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Check if response has a choice before debug logging to prevent null reference. Signed-off-by: Jeffrey Lee <572199+darkthread@users.noreply.github.com> Co-authored-by: Nick Hale <4175918+njhale@users.noreply.github.com> --- pkg/openai/client.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/openai/client.go b/pkg/openai/client.go index e6c246c3..b98029c5 100644 --- a/pkg/openai/client.go +++ b/pkg/openai/client.go @@ -448,7 +448,9 @@ func (c *Client) call(ctx context.Context, request openai.ChatCompletionRequest, } else if err != nil { return nil, err } - slog.Debug("stream", "content", response.Choices[0].Delta.Content) + if len(response.Choices) > 0 { + slog.Debug("stream", "content", response.Choices[0].Delta.Content) + } if partial != nil { partialMessage = appendMessage(partialMessage, response) partial <- types.CompletionStatus{