Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
05de29c8
authored
May 19, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support channel ai.ls now (close #99)
parent
d15ca331
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
13 additions
and
5 deletions
+13
-5
README.md
+3
-2
common/constants.go
+2
-0
controller/relay-utils.go
+2
-2
controller/relay.go
+5
-1
web/src/constants/channel.constants.js
+1
-0
No files found.
README.md
View file @
05de29c8
...
...
@@ -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 模式**
,可以通过流式传输实现打字机效果。
...
...
common/constants.go
View file @
05de29c8
...
...
@@ -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
}
controller/relay-utils.go
View file @
05de29c8
...
...
@@ -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|>
...
...
controller/relay.go
View file @
05de29c8
...
...
@@ -16,7 +16,7 @@ import (
type
Message
struct
{
Role
string
`json:"role"`
Content
string
`json:"content"`
Name
string
`json:"name
"`
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]"
)
{
...
...
web/src/constants/channel.constants.js
View file @
05de29c8
...
...
@@ -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'
}
];
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment