Skip to content

Commit

Permalink
fix: fix dashscope first message role issue (#149)
Browse files Browse the repository at this point in the history
fix: fix dashscope first message role issue (#149)
Co-Authored-By: Minghan Zhang <[email protected]>
  • Loading branch information
Sh1n3zZ and zmh-program committed Mar 27, 2024
1 parent 60ea2d7 commit d0bf977
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions adapter/dashscope/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,21 @@ func (c *ChatInstance) GetHeader() map[string]string {

func (c *ChatInstance) FormatMessages(message []globals.Message) []Message {
var messages []Message
var start bool
for _, v := range message {
if v.Role == globals.Tool {
continue
}

if !start {
start = true

// dashscope first message should be [`user`, `system`] role, convert other roles to `user`
if v.Role != globals.User && v.Role != globals.System {
v.Role = globals.User
}
}

messages = append(messages, Message{
Role: v.Role,
Content: v.Content,
Expand Down

0 comments on commit d0bf977

Please sign in to comment.