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
51c8c666
authored
Feb 01, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: support AI Gateway, close #52
parent
47ddee3e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
3 deletions
+8
-3
controller/channel-test.go
+1
-1
controller/relay-text.go
+2
-1
controller/relay-utils.go
+5
-1
No files found.
controller/channel-test.go
View file @
51c8c666
...
@@ -45,7 +45,7 @@ func testChannel(channel *model.Channel, request ChatRequest) (err error, openai
...
@@ -45,7 +45,7 @@ func testChannel(channel *model.Channel, request ChatRequest) (err error, openai
}
}
requestURL
:=
common
.
ChannelBaseURLs
[
channel
.
Type
]
requestURL
:=
common
.
ChannelBaseURLs
[
channel
.
Type
]
if
channel
.
Type
==
common
.
ChannelTypeAzure
{
if
channel
.
Type
==
common
.
ChannelTypeAzure
{
requestURL
=
fmt
.
Sprintf
(
"%s/openai/deployments/%s/chat/completions?api-version=2023-03-15-preview"
,
channel
.
GetBaseURL
(),
request
.
Model
)
requestURL
=
getFullRequestURL
(
channel
.
GetBaseURL
(),
fmt
.
Sprintf
(
"/openai/deployments/%s/chat/completions?api-version=2023-03-15-preview"
,
request
.
Model
),
channel
.
Type
)
}
else
{
}
else
{
if
channel
.
GetBaseURL
()
!=
""
{
if
channel
.
GetBaseURL
()
!=
""
{
requestURL
=
channel
.
GetBaseURL
()
requestURL
=
channel
.
GetBaseURL
()
...
...
controller/relay-text.go
View file @
51c8c666
...
@@ -149,7 +149,8 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
...
@@ -149,7 +149,8 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
model_
=
strings
.
TrimSuffix
(
model_
,
"-0301"
)
model_
=
strings
.
TrimSuffix
(
model_
,
"-0301"
)
model_
=
strings
.
TrimSuffix
(
model_
,
"-0314"
)
model_
=
strings
.
TrimSuffix
(
model_
,
"-0314"
)
model_
=
strings
.
TrimSuffix
(
model_
,
"-0613"
)
model_
=
strings
.
TrimSuffix
(
model_
,
"-0613"
)
fullRequestURL
=
fmt
.
Sprintf
(
"%s/openai/deployments/%s/%s"
,
baseURL
,
model_
,
task
)
requestURL
=
fmt
.
Sprintf
(
"/openai/deployments/%s/%s"
,
model_
,
task
)
fullRequestURL
=
getFullRequestURL
(
baseURL
,
requestURL
,
channelType
)
}
}
case
APITypeClaude
:
case
APITypeClaude
:
fullRequestURL
=
"https://api.anthropic.com/v1/complete"
fullRequestURL
=
"https://api.anthropic.com/v1/complete"
...
...
controller/relay-utils.go
View file @
51c8c666
...
@@ -295,9 +295,13 @@ func relayErrorHandler(resp *http.Response) (openAIErrorWithStatusCode *OpenAIEr
...
@@ -295,9 +295,13 @@ func relayErrorHandler(resp *http.Response) (openAIErrorWithStatusCode *OpenAIEr
func
getFullRequestURL
(
baseURL
string
,
requestURL
string
,
channelType
int
)
string
{
func
getFullRequestURL
(
baseURL
string
,
requestURL
string
,
channelType
int
)
string
{
fullRequestURL
:=
fmt
.
Sprintf
(
"%s%s"
,
baseURL
,
requestURL
)
fullRequestURL
:=
fmt
.
Sprintf
(
"%s%s"
,
baseURL
,
requestURL
)
if
channelType
==
common
.
ChannelTypeOpenAI
{
if
strings
.
HasPrefix
(
baseURL
,
"https://gateway.ai.cloudflare.com"
)
{
if
strings
.
HasPrefix
(
baseURL
,
"https://gateway.ai.cloudflare.com"
)
{
switch
channelType
{
case
common
.
ChannelTypeOpenAI
:
fullRequestURL
=
fmt
.
Sprintf
(
"%s%s"
,
baseURL
,
strings
.
TrimPrefix
(
requestURL
,
"/v1"
))
fullRequestURL
=
fmt
.
Sprintf
(
"%s%s"
,
baseURL
,
strings
.
TrimPrefix
(
requestURL
,
"/v1"
))
case
common
.
ChannelTypeAzure
:
fullRequestURL
=
fmt
.
Sprintf
(
"%s%s"
,
baseURL
,
strings
.
TrimPrefix
(
requestURL
,
"/openai/deployments"
))
}
}
}
}
return
fullRequestURL
return
fullRequestURL
...
...
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