mirror of
https://github.com/coaidev/coai.git
synced 2025-05-22 06:20:14 +09:00
fix: fix claude system prompt wrong life cycle issue (merge pr #154)
fix: skip the first claude system message
This commit is contained in:
commit
c27fdf3bec
@ -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
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user