Skip to content

Commit

Permalink
fix: fix claude system prompt wrong life cycle issue (merge pr coaide…
Browse files Browse the repository at this point in the history
…v#154)

fix: skip the first claude system message
  • Loading branch information
zmh-program authored Mar 30, 2024
2 parents 12f497a + 6fea649 commit c27fdf3
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions adapter/claude/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ func (c *ChatInstance) GetTokens(props *adaptercommon.ChatProps) int {
}

func (c *ChatInstance) ConvertMessages(props *adaptercommon.ChatProps) []globals.Message {
// anthropic api: top message must be user message, system message is not allowed
// anthropic api: top message must be user message, only `user` and `assistant` role messages are allowd
start := false

result := make([]globals.Message, 0)

for _, message := range props.Message {
if message.Role == globals.System {
continue
}

// if is first message, set it to user message
if !start {
start = true
Expand All @@ -70,11 +74,6 @@ func (c *ChatInstance) ConvertMessages(props *adaptercommon.ChatProps) []globals
continue
}

// if is system message, set it to user message
if message.Role == globals.System {
continue
}

// anthropic api does not allow multi-same role messages
if len(result) > 0 && result[len(result)-1].Role == message.Role {
result[len(result)-1].Content += "\n" + message.Content
Expand Down

0 comments on commit c27fdf3

Please sign in to comment.