Skip to content

Commit

Permalink
fix: fix claude system prompt (merge pr coaidev#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program authored Mar 30, 2024
2 parents bd714d5 + aac7603 commit 12f497a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 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 @@ -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,
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 12f497a

Please sign in to comment.