Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

Commit

Permalink
fix(openai): fix the message order in the chat completion request (#36)
Browse files Browse the repository at this point in the history
Because

- we should put `system message` before `user message`, see [OpenAI API
reference](https://platform.openai.com/docs/api-reference/chat/create?lang=curl)

This commit

- fix the message order for OpenAI chat completion request
  • Loading branch information
xiaofei-du authored Nov 5, 2023
1 parent e2ff255 commit 7ef3177
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/openai/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ func (e *Execution) Execute(inputs []*structpb.Struct) ([]*structpb.Struct, erro
}

messages := []Message{}
messages = append(messages, Message{Role: "user", Content: inputStruct.Prompt})
if inputStruct.SystemMessage != nil {
messages = append(messages, Message{Role: "system", Content: *inputStruct.SystemMessage})
}
messages = append(messages, Message{Role: "user", Content: inputStruct.Prompt})

req := TextCompletionReq{
Messages: messages,
Expand Down

0 comments on commit 7ef3177

Please sign in to comment.