Skip to content

Commit

Permalink
genai: check for nil value from service (#57)
Browse files Browse the repository at this point in the history
Avoid dereferencing a nil.
This may fix an actual bug, but even if it doesn't, it's a good idea to
assume as little as possible about values returned from the service.

For #55.
  • Loading branch information
jba committed Feb 27, 2024
1 parent a487247 commit 0bb2e23
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions genai/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func (cs *ChatSession) SendMessageStream(ctx context.Context, parts ...Part) *Ge
func (cs *ChatSession) addToHistory(cands []*Candidate) bool {
if len(cands) > 0 {
c := cands[0].Content
if c == nil {
return false
}
c.Role = roleModel
cs.History = append(cs.History, c)
return true
Expand Down

0 comments on commit 0bb2e23

Please sign in to comment.