Skip to content

Commit

Permalink
Fix index out of range
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshineplan committed May 6, 2024
1 parent 76e0db1 commit 6c6b2d8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions chatgpt/chatgpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (stream *ChatStream) Next() (ai.ChatResponse, error) {
stream.merged = ""
return nil, err
}
if stream.cs != nil {
if stream.cs != nil && len(resp.Choices) > 0 {
stream.merged += resp.Choices[0].Delta.Content
}
return &ChatResponse[openai.ChatCompletionStreamResponse]{resp}, nil
Expand Down Expand Up @@ -256,7 +256,9 @@ func (session *ChatSession) Chat(ctx context.Context, messages ...string) (ai.Ch
return nil, err
}
addToHistory(&session.history, openai.ChatMessageRoleUser, messages...)
session.history = append(session.history, resp.Choices[0].Message)
if len(resp.Choices) > 0 {
session.history = append(session.history, resp.Choices[0].Message)
}
return &ChatResponse[openai.ChatCompletionResponse]{resp}, nil
}

Expand Down

0 comments on commit 6c6b2d8

Please sign in to comment.