fix: fix claude system prompt (merge pr #152)

This commit is contained in:
Minghan Zhang 2024-03-30 18:58:55 +08:00 committed by GitHub
commit 12f497a655
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -72,7 +72,7 @@ func (c *ChatInstance) ConvertMessages(props *adaptercommon.ChatProps) []globals
// if is system message, set it to user message
if message.Role == globals.System {
message.Role = globals.User
continue
}
// anthropic api does not allow multi-same role messages
@ -126,12 +126,22 @@ func (c *ChatInstance) GetMessages(props *adaptercommon.ChatProps) []Message {
})
}
func (c *ChatInstance) GetSystemPrompt(props *adaptercommon.ChatProps) (prompt string) {
for _, message := range props.Message {
if message.Role == globals.System {
prompt += message.Content
}
}
return
}
func (c *ChatInstance) GetChatBody(props *adaptercommon.ChatProps, stream bool) *ChatBody {
messages := c.GetMessages(props)
return &ChatBody{
Messages: messages,
MaxTokens: c.GetTokens(props),
Model: props.Model,
System: c.GetSystemPrompt(props),
Stream: stream,
Temperature: props.Temperature,
TopP: props.TopP,

View File

@ -23,6 +23,7 @@ type ChatBody struct {
Messages []Message `json:"messages"`
MaxTokens int `json:"max_tokens"`
Model string `json:"model"`
System string `json:"system"`
Stream bool `json:"stream"`
Temperature *float32 `json:"temperature,omitempty"`
TopP *float32 `json:"top_p,omitempty"`