Skip to content

Commit

Permalink
Merge pull request #251 from cyuxlif/main
Browse files Browse the repository at this point in the history
bug: role assistant message maybe have function_call
  • Loading branch information
tmc authored Aug 23, 2023
2 parents fef0821 + 4d4fece commit e216ca1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions llms/openai/openaillm_chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (o *Chat) Call(ctx context.Context, messages []schema.ChatMessage, options
return r[0].Message, nil
}

//nolint:funlen
func (o *Chat) Generate(ctx context.Context, messageSets [][]schema.ChatMessage, options ...llms.CallOption) ([]*llms.Generation, error) { // nolint:lll,cyclop
opts := llms.CallOptions{}
for _, opt := range options {
Expand All @@ -58,6 +59,12 @@ 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,
Arguments: aiChatMsg.FunctionCall.Arguments,
}
}
case schema.ChatMessageTypeHuman:
msg.Role = "user"
case schema.ChatMessageTypeGeneric:
Expand Down

0 comments on commit e216ca1

Please sign in to comment.