mirror of
https://github.com/coaidev/coai.git
synced 2025-05-29 18:00:14 +09:00
fix: fix claude system prompt (merge pr #152)
This commit is contained in:
commit
12f497a655
@ -72,7 +72,7 @@ func (c *ChatInstance) ConvertMessages(props *adaptercommon.ChatProps) []globals
|
|||||||
|
|
||||||
// if is system message, set it to user message
|
// if is system message, set it to user message
|
||||||
if message.Role == globals.System {
|
if message.Role == globals.System {
|
||||||
message.Role = globals.User
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// anthropic api does not allow multi-same role messages
|
// 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 {
|
func (c *ChatInstance) GetChatBody(props *adaptercommon.ChatProps, stream bool) *ChatBody {
|
||||||
messages := c.GetMessages(props)
|
messages := c.GetMessages(props)
|
||||||
return &ChatBody{
|
return &ChatBody{
|
||||||
Messages: messages,
|
Messages: messages,
|
||||||
MaxTokens: c.GetTokens(props),
|
MaxTokens: c.GetTokens(props),
|
||||||
Model: props.Model,
|
Model: props.Model,
|
||||||
|
System: c.GetSystemPrompt(props),
|
||||||
Stream: stream,
|
Stream: stream,
|
||||||
Temperature: props.Temperature,
|
Temperature: props.Temperature,
|
||||||
TopP: props.TopP,
|
TopP: props.TopP,
|
||||||
|
@ -23,6 +23,7 @@ type ChatBody struct {
|
|||||||
Messages []Message `json:"messages"`
|
Messages []Message `json:"messages"`
|
||||||
MaxTokens int `json:"max_tokens"`
|
MaxTokens int `json:"max_tokens"`
|
||||||
Model string `json:"model"`
|
Model string `json:"model"`
|
||||||
|
System string `json:"system"`
|
||||||
Stream bool `json:"stream"`
|
Stream bool `json:"stream"`
|
||||||
Temperature *float32 `json:"temperature,omitempty"`
|
Temperature *float32 `json:"temperature,omitempty"`
|
||||||
TopP *float32 `json:"top_p,omitempty"`
|
TopP *float32 `json:"top_p,omitempty"`
|
||||||
|
Loading…
Reference in New Issue
Block a user