mirror of
https://github.com/coaidev/coai.git
synced 2025-05-21 22:10:12 +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 {
|
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
|
start := false
|
||||||
|
|
||||||
result := make([]globals.Message, 0)
|
result := make([]globals.Message, 0)
|
||||||
|
|
||||||
for _, message := range props.Message {
|
for _, message := range props.Message {
|
||||||
|
if message.Role == globals.System {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// if is first message, set it to user message
|
// if is first message, set it to user message
|
||||||
if !start {
|
if !start {
|
||||||
start = true
|
start = true
|
||||||
@ -70,11 +74,6 @@ func (c *ChatInstance) ConvertMessages(props *adaptercommon.ChatProps) []globals
|
|||||||
continue
|
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
|
// anthropic api does not allow multi-same role messages
|
||||||
if len(result) > 0 && result[len(result)-1].Role == message.Role {
|
if len(result) > 0 && result[len(result)-1].Role == message.Role {
|
||||||
result[len(result)-1].Content += "\n" + message.Content
|
result[len(result)-1].Content += "\n" + message.Content
|
||||||
|
Loading…
Reference in New Issue
Block a user