Skip to content

Commit

Permalink
bug: role assistant message maybe have function_call
Browse files Browse the repository at this point in the history
  • Loading branch information
deanyychen committed Aug 16, 2023
1 parent eb0cbd3 commit 7575c90
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions llms/openai/openaillm_chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func (o *Chat) Generate(ctx context.Context, messageSets [][]schema.ChatMessage,
msg.Role = "system"
case schema.ChatMessageTypeAI:
msg.Role = "assistant"
if aiChatMsg, ok := m.(schema.AIChatMessage); ok && aiChatMsg.FunctionCall != nil {
msg.FunctionCall = &openaiclient.FunctionCall{Name: aiChatMsg.FunctionCall.Name,

Check failure on line 62 in llms/openai/openaillm_chat.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
Arguments: aiChatMsg.FunctionCall.Arguments}
}
case schema.ChatMessageTypeHuman:
msg.Role = "user"
case schema.ChatMessageTypeGeneric:
Expand All @@ -71,16 +75,11 @@ func (o *Chat) Generate(ctx context.Context, messageSets [][]schema.ChatMessage,
msgs[i] = msg
}
req := &openaiclient.ChatRequest{
Model: opts.Model,
StopWords: opts.StopWords,
Messages: msgs,
StreamingFunc: opts.StreamingFunc,
Temperature: opts.Temperature,
MaxTokens: opts.MaxTokens,
N: opts.N,
FrequencyPenalty: opts.FrequencyPenalty,
PresencePenalty: opts.PresencePenalty,

Model: opts.Model, StopWords: opts.StopWords,
Messages: msgs, StreamingFunc: opts.StreamingFunc,
Temperature: opts.Temperature, MaxTokens: opts.MaxTokens,
N: opts.N, FrequencyPenalty: opts.FrequencyPenalty,
PresencePenalty: opts.PresencePenalty,
FunctionCallBehavior: openaiclient.FunctionCallBehavior(opts.FunctionCallBehavior),
}
for _, fn := range opts.Functions {
Expand Down Expand Up @@ -116,7 +115,6 @@ func (o *Chat) Generate(ctx context.Context, messageSets [][]schema.ChatMessage,
GenerationInfo: generationInfo,
})
}

return generations, nil
}

Expand Down

0 comments on commit 7575c90

Please sign in to comment.