Skip to content

Commit a3cbe20

Browse files
darkthreadnjhale
andauthored
Check if response has a choice before debug logging to prevent null r… (#117)
* Check if response has a choice before debug logging to prevent null reference. Signed-off-by: Jeffrey Lee <[email protected]> Co-authored-by: Nick Hale <[email protected]>
1 parent 1fb78c2 commit a3cbe20

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pkg/openai/client.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,9 @@ func (c *Client) call(ctx context.Context, request openai.ChatCompletionRequest,
448448
} else if err != nil {
449449
return nil, err
450450
}
451-
slog.Debug("stream", "content", response.Choices[0].Delta.Content)
451+
if len(response.Choices) > 0 {
452+
slog.Debug("stream", "content", response.Choices[0].Delta.Content)
453+
}
452454
if partial != nil {
453455
partialMessage = appendMessage(partialMessage, response)
454456
partial <- types.CompletionStatus{

0 commit comments

Comments
 (0)