Skip to content

Commit

Permalink
Merge pull request #108 from samgozman/107-runtimeboundserror-runtime…
Browse files Browse the repository at this point in the history
…-error

fix: bound error
  • Loading branch information
samgozman authored Feb 24, 2024
2 parents 4cded13 + 6be9119 commit 7966016
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions composer/composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func (c *Composer) Compose(ctx context.Context, news journalist.NewsList) ([]*Co
return nil, newError(err, errlvl.WARN, "Compose", "OpenAiClient.CreateChatCompletion")
}

if len(resp.Choices) == 0 {
return nil, newError(errors.New("empty response"), errlvl.WARN, "Compose", "OpenAiClient.CreateChatCompletion")
}

matches, err := aiJSONStringFixer(resp.Choices[0].Message.Content)
if err != nil {
return nil, newError(err, errlvl.ERROR, "Compose", "aiJSONStringFixer")
Expand Down Expand Up @@ -152,6 +156,10 @@ func (c *Composer) Summarise(ctx context.Context, headlines []*Headline, headlin
return nil, newError(err, errlvl.WARN, "Summarise", "OpenAiClient.CreateChatCompletion")
}

if len(resp.Choices) == 0 {
return nil, newError(errors.New("empty response"), errlvl.WARN, "Summarise", "OpenAiClient.CreateChatCompletion")
}

matches, err := aiJSONStringFixer(resp.Choices[0].Message.Content)
if err != nil {
return nil, newError(err, errlvl.ERROR, "Summarise", "aiJSONStringFixer")
Expand Down Expand Up @@ -196,6 +204,10 @@ func (c *Composer) Filter(ctx context.Context, news journalist.NewsList) (journa
return nil, newError(err, errlvl.WARN, "Filter", "TogetherAIClient.CreateChatCompletion")
}

if len(resp.Choices) == 0 {
return nil, newError(errors.New("empty response"), errlvl.WARN, "Filter", "TogetherAIClient.CreateChatCompletion")
}

matches, err := aiJSONStringFixer(resp.Choices[0].Text)
if err != nil {
return nil, newError(err, errlvl.ERROR, "Filter", "aiJSONStringFixer")
Expand Down

0 comments on commit 7966016

Please sign in to comment.