mirror of
https://github.com/coaidev/coai.git
synced 2025-05-19 13:00:14 +09:00
fix: fix anthropic multiple same rule issue (#138)
This commit is contained in:
parent
944fa2843d
commit
98d9ba21bd
22
README.md
22
README.md
@ -169,7 +169,7 @@ English | [简体中文](https://github.com/Deeptrain-Community/chatnio/blob/mas
|
|||||||
> - *-v ~/config:/config* mount host machine directory of configuration file, *-v ~/logs:/logs* mount host machine directory of log file,*-v ~/storage:/storage* mount generated files of additional functions
|
> - *-v ~/config:/config* mount host machine directory of configuration file, *-v ~/logs:/logs* mount host machine directory of log file,*-v ~/storage:/storage* mount generated files of additional functions
|
||||||
> - You need to configure MySQL and Redis services, please refer to the information above to modify the environment variables yourself.
|
> - You need to configure MySQL and Redis services, please refer to the information above to modify the environment variables yourself.
|
||||||
|
|
||||||
Version Update (_With Watchtower auto-updating enabled, there is no need for manual updates, Just run through the steps above again after execution._):
|
Version Update (_With Watchtower auto-updating enabled, there is no need for manual updates, Just run through the steps above again after execution._):
|
||||||
```shell
|
```shell
|
||||||
docker stop chatnio
|
docker stop chatnio
|
||||||
docker rm chatnio
|
docker rm chatnio
|
||||||
@ -287,16 +287,16 @@ English | [简体中文](https://github.com/Deeptrain-Community/chatnio/blob/mas
|
|||||||
|
|
||||||
## ✨ Some EXCELLENT Open-source Projects
|
## ✨ Some EXCELLENT Open-source Projects
|
||||||
> **Frontend projects here refer to projects that focus on user chat interfaces, backend projects refer to projects that focus on API transfer and management, and one-stop projects refer to projects that include user chat interfaces and API transfer and management**
|
> **Frontend projects here refer to projects that focus on user chat interfaces, backend projects refer to projects that focus on API transfer and management, and one-stop projects refer to projects that include user chat interfaces and API transfer and management**
|
||||||
- [Next Chat @yidadaa](https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web) (Front-end Oriented Projects)
|
- [Next Chat @yidadaa](https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web) (Front-end Oriented Projects)
|
||||||
- [Lobe Chat @arvinxx](https://github.com/lobehub/lobe-chat) (Front-end Oriented Projects)
|
- [Lobe Chat @arvinxx](https://github.com/lobehub/lobe-chat) (Front-end Oriented Projects)
|
||||||
- [Chat Box @bin-huang](https://github.com/Bin-Huang/chatbox) (Front-end Oriented Projects)
|
- [Chat Box @bin-huang](https://github.com/Bin-Huang/chatbox) (Front-end Oriented Projects)
|
||||||
- [OpenAI Forward @kenyony](https://github.com/KenyonY/openai-forward) (Back-end Oriented Projects)
|
- [OpenAI Forward @kenyony](https://github.com/KenyonY/openai-forward) (Back-end Oriented Projects)
|
||||||
- [One API @justsong](https://github.com/songquanpeng/one-api) (Back-end Oriented Projects)
|
- [One API @justsong](https://github.com/songquanpeng/one-api) (Back-end Oriented Projects)
|
||||||
- [New API @calon](https://github.com/Calcium-Ion/new-api) (Back-end Oriented Projects)
|
- [New API @calon](https://github.com/Calcium-Ion/new-api) (Back-end Oriented Projects)
|
||||||
- [FastGPT @labring](https://github.com/labring/FastGPT) (Knowledge Base)
|
- [FastGPT @labring](https://github.com/labring/FastGPT) (Knowledge Base)
|
||||||
- [Quivr @quivrhq](https://github.com/StanGirard/quivr) (Knowledge Base)
|
- [Quivr @quivrhq](https://github.com/StanGirard/quivr) (Knowledge Base)
|
||||||
- [Bingo @weaigc](https://github.com/weaigc/bingo) (Knowledge Base)
|
- [Bingo @weaigc](https://github.com/weaigc/bingo) (Knowledge Base)
|
||||||
- [Midjourney Proxy @novicezk](https://github.com/novicezk/midjourney-proxy) (Model Library)
|
- [Midjourney Proxy @novicezk](https://github.com/novicezk/midjourney-proxy) (Model Library)
|
||||||
|
|
||||||
|
|
||||||
## 📄 Open Source License
|
## 📄 Open Source License
|
||||||
|
@ -53,30 +53,43 @@ func (c *ChatInstance) GetTokens(props *adaptercommon.ChatProps) int {
|
|||||||
return *props.MaxTokens
|
return *props.MaxTokens
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ChatInstance) GetMessages(props *adaptercommon.ChatProps) []Message {
|
func (c *ChatInstance) ConvertMessages(props *adaptercommon.ChatProps) []globals.Message {
|
||||||
|
// anthropic api: top message must be user message, system message is not allowed
|
||||||
start := false
|
start := false
|
||||||
|
|
||||||
return utils.Each(props.Message, func(message globals.Message) Message {
|
result := make([]globals.Message, 0)
|
||||||
// anthropic api: top message must be user message, system message is not allowed
|
|
||||||
|
for _, message := range props.Message {
|
||||||
|
// if is first message, set it to user message
|
||||||
if !start {
|
if !start {
|
||||||
start = true
|
start = true
|
||||||
// set first message to user message
|
result = append(result, globals.Message{
|
||||||
if message.Role != globals.User {
|
Role: globals.User,
|
||||||
return Message{
|
|
||||||
Role: globals.User,
|
|
||||||
Content: message.Content,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if message.Role == globals.System {
|
|
||||||
// set system message to user message
|
|
||||||
return Message{
|
|
||||||
Role: message.Role,
|
|
||||||
Content: message.Content,
|
Content: message.Content,
|
||||||
}
|
})
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if is system message, set it to user message
|
||||||
|
if message.Role == globals.System {
|
||||||
|
message.Role = globals.User
|
||||||
|
}
|
||||||
|
|
||||||
|
// anthropic api does not allow multi-same role messages
|
||||||
|
if len(result) > 0 && result[len(result)-1].Role == message.Role {
|
||||||
|
result[len(result)-1].Content += "\n" + message.Content
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
result = append(result, message)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ChatInstance) GetMessages(props *adaptercommon.ChatProps) []Message {
|
||||||
|
converted := c.ConvertMessages(props)
|
||||||
|
return utils.Each(converted, func(message globals.Message) Message {
|
||||||
if !globals.IsVisionModel(props.Model) || message.Role != globals.User {
|
if !globals.IsVisionModel(props.Model) || message.Role != globals.User {
|
||||||
return Message{
|
return Message{
|
||||||
Role: message.Role,
|
Role: message.Role,
|
||||||
|
Loading…
Reference in New Issue
Block a user