Skip to content

Commit

Permalink
feat: support channel ai.ls now (close #99)
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed May 19, 2023
1 parent 7c6bf3e commit 3711f4a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 模式**,可以通过流式传输实现打字机效果。
Expand Down
2 changes: 2 additions & 0 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const (
ChannelTypeOpenAIMax = 6
ChannelTypeOhMyGPT = 7
ChannelTypeCustom = 8
ChannelTypeAILS = 9
)

var ChannelBaseURLs = []string{
Expand All @@ -139,4 +140,5 @@ var ChannelBaseURLs = []string{
"https://api.openaimax.com", // 6
"https://api.ohmygpt.com", // 7
"", // 8
"https://api.caipacity.com", // 9
}
4 changes: 2 additions & 2 deletions controller/relay-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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|>
Expand Down
10 changes: 7 additions & 3 deletions controller/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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]") {
Expand Down
1 change: 1 addition & 0 deletions web/src/constants/channel.constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
];

0 comments on commit 3711f4a

Please sign in to comment.