Skip to content

Commit

Permalink
feat: refactor OpenAI response handling logic
Browse files Browse the repository at this point in the history
- Extract the summary prefix from OpenAI response and handle function call arguments if present
- Add a conditional block to check for non-nil function calls within the OpenAI response handling code

Signed-off-by: appleboy <appleboy.tw@gmail.com>
  • Loading branch information
appleboy committed Apr 6, 2024
1 parent 1853601 commit aa0deff
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cmd/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,11 @@ var commitCmd = &cobra.Command{
return err
}
if len(resp.Choices) > 0 {
args := openai.GetSummaryPrefixArgs(resp.Choices[0].Message.FunctionCall.Arguments)
summaryPrix = args.Prefix
summaryPrix = strings.TrimSpace(resp.Choices[0].Message.Content)
if resp.Choices[0].Message.FunctionCall != nil {
args := openai.GetSummaryPrefixArgs(resp.Choices[0].Message.FunctionCall.Arguments)
summaryPrix = args.Prefix
}
}
color.Magenta("PromptTokens: " + strconv.Itoa(resp.Usage.PromptTokens) +
", CompletionTokens: " + strconv.Itoa(resp.Usage.CompletionTokens) +
Expand Down

0 comments on commit aa0deff

Please sign in to comment.