diff --git a/README.md b/README.md index 823e252290..bea108123a 100644 --- a/README.md +++ b/README.md @@ -51,9 +51,10 @@ _✨ All in one 的 OpenAI 接口,整合各种 API 访问方式,开箱即用 + [x] **Azure OpenAI API** + [x] [API2D](https://api2d.com/r/197971) + [x] [OhMyGPT](https://aigptx.top?aff=uFpUl2Kf) - + [x] [CloseAI](https://console.openai-asia.com) - + [x] [OpenAI-SB](https://openai-sb.com) + + [x] [AI.LS](https://ai.ls) + [x] [OpenAI Max](https://openaimax.com) + + [x] [OpenAI-SB](https://openai-sb.com) + + [x] [CloseAI](https://console.openai-asia.com) + [x] 自定义渠道:例如使用自行搭建的 OpenAI 代理 2. 支持通过**负载均衡**的方式访问多个渠道。 3. 支持 **stream 模式**,可以通过流式传输实现打字机效果。 diff --git a/common/constants.go b/common/constants.go index 5cb55dfb2a..0a1f1e20d3 100644 --- a/common/constants.go +++ b/common/constants.go @@ -127,6 +127,7 @@ const ( ChannelTypeOpenAIMax = 6 ChannelTypeOhMyGPT = 7 ChannelTypeCustom = 8 + ChannelTypeAILS = 9 ) var ChannelBaseURLs = []string{ @@ -139,4 +140,5 @@ var ChannelBaseURLs = []string{ "https://api.openaimax.com", // 6 "https://api.ohmygpt.com", // 7 "", // 8 + "https://api.caipacity.com", // 9 } diff --git a/controller/relay-utils.go b/controller/relay-utils.go index a202e69b57..a53d80cc07 100644 --- a/controller/relay-utils.go +++ b/controller/relay-utils.go @@ -45,9 +45,9 @@ func countTokenMessages(messages []Message, model string) int { tokenNum += tokensPerMessage tokenNum += len(tokenEncoder.Encode(message.Content, nil, nil)) tokenNum += len(tokenEncoder.Encode(message.Role, nil, nil)) - if message.Name != "" { + if message.Name != nil { tokenNum += tokensPerName - tokenNum += len(tokenEncoder.Encode(message.Name, nil, nil)) + tokenNum += len(tokenEncoder.Encode(*message.Name, nil, nil)) } } tokenNum += 3 // Every reply is primed with <|start|>assistant<|message|> diff --git a/controller/relay.go b/controller/relay.go index d84a741c1d..4e093db5e3 100644 --- a/controller/relay.go +++ b/controller/relay.go @@ -14,9 +14,9 @@ import ( ) type Message struct { - Role string `json:"role"` - Content string `json:"content"` - Name string `json:"name"` + Role string `json:"role"` + Content string `json:"content"` + Name *string `json:"name,omitempty"` } type ChatRequest struct { @@ -232,6 +232,10 @@ func relayHelper(c *gin.Context) *OpenAIErrorWithStatusCode { go func() { for scanner.Scan() { data := scanner.Text() + if len(data) < 6 { // must be something wrong! + common.SysError("Invalid stream response: " + data) + continue + } dataChan <- data data = data[6:] if !strings.HasPrefix(data, "[DONE]") { diff --git a/web/src/constants/channel.constants.js b/web/src/constants/channel.constants.js index 6cec5885dd..b66d5c34bd 100644 --- a/web/src/constants/channel.constants.js +++ b/web/src/constants/channel.constants.js @@ -6,5 +6,6 @@ export const CHANNEL_OPTIONS = [ { key: 5, text: 'OpenAI-SB', value: 5, color: 'brown' }, { key: 6, text: 'OpenAI Max', value: 6, color: 'violet' }, { key: 7, text: 'OhMyGPT', value: 7, color: 'purple' }, + { key: 9, text: 'AI.LS', value: 9, color: 'yellow' }, { key: 8, text: '自定义', value: 8, color: 'pink' } ];