Skip to content

Commit

Permalink
claude sys msg adapt
Browse files Browse the repository at this point in the history
  • Loading branch information
Lavanille777 committed Mar 30, 2024
1 parent 5ddfbbc commit 3136a9f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion adapter/claude/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -128,10 +128,17 @@ func (c *ChatInstance) GetMessages(props *adaptercommon.ChatProps) []Message {

func (c *ChatInstance) GetChatBody(props *adaptercommon.ChatProps, stream bool) *ChatBody {
messages := c.GetMessages(props)
var systemStr string
for _, message := range messages {
if message.Role == globals.System {
systemStr += message.Content
}
}
return &ChatBody{
Messages: messages,
MaxTokens: c.GetTokens(props),
Model: props.Model,
System: systemStr
Stream: stream,
Temperature: props.Temperature,
TopP: props.TopP,
Expand Down
1 change: 1 addition & 0 deletions adapter/claude/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 3136a9f

Please sign in to comment.