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
a04afb22
authored
Jun 09, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support set proxy for channel OpenAI (close #139)
parent
ac11307f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
7 deletions
+25
-7
README.md
+2
-2
controller/channel-test.go
+2
-0
controller/relay.go
+4
-0
middleware/distributor.go
+3
-5
web/src/pages/Channel/EditChannel.js
+14
-0
No files found.
README.md
View file @
a04afb22
...
@@ -50,7 +50,7 @@ _✨ All in one 的 OpenAI 接口,整合各种 API 访问方式,开箱即用
...
@@ -50,7 +50,7 @@ _✨ All in one 的 OpenAI 接口,整合各种 API 访问方式,开箱即用
## 功能
## 功能
1.
支持多种 API 访问渠道,欢迎 PR 或提 issue 添加更多渠道:
1.
支持多种 API 访问渠道,欢迎 PR 或提 issue 添加更多渠道:
+
[
x
]
OpenAI 官方通道
+
[
x
]
OpenAI 官方通道
(支持配置代理)
+
[
x
]
**Azure OpenAI API**
+
[
x
]
**Azure OpenAI API**
+
[
x
]
[
API2D
]
(https://api2d.com/r/197971)
+
[
x
]
[
API2D
]
(https://api2d.com/r/197971)
+
[
x
]
[
OhMyGPT
]
(https://aigptx.top?aff=uFpUl2Kf)
+
[
x
]
[
OhMyGPT
]
(https://aigptx.top?aff=uFpUl2Kf)
...
@@ -59,7 +59,7 @@ _✨ All in one 的 OpenAI 接口,整合各种 API 访问方式,开箱即用
...
@@ -59,7 +59,7 @@ _✨ All in one 的 OpenAI 接口,整合各种 API 访问方式,开箱即用
+
[
x
]
[
OpenAI Max
]
(https://openaimax.com)
+
[
x
]
[
OpenAI Max
]
(https://openaimax.com)
+
[
x
]
[
OpenAI-SB
]
(https://openai-sb.com)
+
[
x
]
[
OpenAI-SB
]
(https://openai-sb.com)
+
[
x
]
[
CloseAI
]
(https://console.openai-asia.com/r/2412)
+
[
x
]
[
CloseAI
]
(https://console.openai-asia.com/r/2412)
+
[
x
]
自定义渠道:例如
使用自行搭建的 OpenAI 代理
+
[
x
]
自定义渠道:例如
各种未收录的第三方代理服务
2.
支持通过
**负载均衡**
的方式访问多个渠道。
2.
支持通过
**负载均衡**
的方式访问多个渠道。
3.
支持
**stream 模式**
,可以通过流式传输实现打字机效果。
3.
支持
**stream 模式**
,可以通过流式传输实现打字机效果。
4.
支持
**多机部署**
,
[
详见此处
](
#多机部署
)
。
4.
支持
**多机部署**
,
[
详见此处
](
#多机部署
)
。
...
...
controller/channel-test.go
View file @
a04afb22
...
@@ -27,6 +27,8 @@ func testChannel(channel *model.Channel, request *ChatRequest) error {
...
@@ -27,6 +27,8 @@ func testChannel(channel *model.Channel, request *ChatRequest) error {
}
else
{
}
else
{
if
channel
.
Type
==
common
.
ChannelTypeCustom
{
if
channel
.
Type
==
common
.
ChannelTypeCustom
{
requestURL
=
channel
.
BaseURL
requestURL
=
channel
.
BaseURL
}
else
if
channel
.
Type
==
common
.
ChannelTypeOpenAI
&&
channel
.
BaseURL
!=
""
{
requestURL
=
channel
.
BaseURL
}
}
requestURL
+=
"/v1/chat/completions"
requestURL
+=
"/v1/chat/completions"
}
}
...
...
controller/relay.go
View file @
a04afb22
...
@@ -147,6 +147,10 @@ func relayHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
...
@@ -147,6 +147,10 @@ func relayHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
requestURL
:=
c
.
Request
.
URL
.
String
()
requestURL
:=
c
.
Request
.
URL
.
String
()
if
channelType
==
common
.
ChannelTypeCustom
{
if
channelType
==
common
.
ChannelTypeCustom
{
baseURL
=
c
.
GetString
(
"base_url"
)
baseURL
=
c
.
GetString
(
"base_url"
)
}
else
if
channelType
==
common
.
ChannelTypeOpenAI
{
if
c
.
GetString
(
"base_url"
)
!=
""
{
baseURL
=
c
.
GetString
(
"base_url"
)
}
}
}
fullRequestURL
:=
fmt
.
Sprintf
(
"%s%s"
,
baseURL
,
requestURL
)
fullRequestURL
:=
fmt
.
Sprintf
(
"%s%s"
,
baseURL
,
requestURL
)
if
channelType
==
common
.
ChannelTypeAzure
{
if
channelType
==
common
.
ChannelTypeAzure
{
...
...
middleware/distributor.go
View file @
a04afb22
...
@@ -82,11 +82,9 @@ func Distribute() func(c *gin.Context) {
...
@@ -82,11 +82,9 @@ func Distribute() func(c *gin.Context) {
c
.
Set
(
"channel_id"
,
channel
.
Id
)
c
.
Set
(
"channel_id"
,
channel
.
Id
)
c
.
Set
(
"channel_name"
,
channel
.
Name
)
c
.
Set
(
"channel_name"
,
channel
.
Name
)
c
.
Request
.
Header
.
Set
(
"Authorization"
,
fmt
.
Sprintf
(
"Bearer %s"
,
channel
.
Key
))
c
.
Request
.
Header
.
Set
(
"Authorization"
,
fmt
.
Sprintf
(
"Bearer %s"
,
channel
.
Key
))
if
channel
.
Type
==
common
.
ChannelTypeCustom
||
channel
.
Type
==
common
.
ChannelTypeAzure
{
c
.
Set
(
"base_url"
,
channel
.
BaseURL
)
c
.
Set
(
"base_url"
,
channel
.
BaseURL
)
if
channel
.
Type
==
common
.
ChannelTypeAzure
{
if
channel
.
Type
==
common
.
ChannelTypeAzure
{
c
.
Set
(
"api_version"
,
channel
.
Other
)
c
.
Set
(
"api_version"
,
channel
.
Other
)
}
}
}
c
.
Next
()
c
.
Next
()
}
}
...
...
web/src/pages/Channel/EditChannel.js
View file @
a04afb22
...
@@ -199,6 +199,20 @@ const EditChannel = () => {
...
@@ -199,6 +199,20 @@ const EditChannel = () => {
}}
>
填入所有模型
<
/Button
>
}}
>
填入所有模型
<
/Button
>
<
/div
>
<
/div
>
{
{
inputs
.
type
===
1
&&
(
<
Form
.
Field
>
<
Form
.
Input
label
=
'代理'
name
=
'base_url'
placeholder
=
{
'请输入 OpenAI API 代理地址,如果不需要请留空,格式为:https://api.openai.com'
}
onChange
=
{
handleInputChange
}
value
=
{
inputs
.
base_url
}
autoComplete
=
'new-password'
/>
<
/Form.Field
>
)
}
{
batch
?
<
Form
.
Field
>
batch
?
<
Form
.
Field
>
<
Form
.
TextArea
<
Form
.
TextArea
label
=
'密钥'
label
=
'密钥'
...
...
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