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
10528988
authored
Oct 15, 2024
by
1808837298@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 上游渠道为OpenAI渠道类型时,透传请求 (close #532)
parent
1d8271e0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
8 deletions
+18
-8
relay/relay-text.go
+18
-8
No files found.
relay/relay-text.go
View file @
10528988
...
...
@@ -76,6 +76,7 @@ func TextHelper(c *gin.Context) *dto.OpenAIErrorWithStatusCode {
}
// map model name
isModelMapped
:=
false
modelMapping
:=
c
.
GetString
(
"model_mapping"
)
//isModelMapped := false
if
modelMapping
!=
""
&&
modelMapping
!=
"{}"
{
...
...
@@ -85,6 +86,7 @@ func TextHelper(c *gin.Context) *dto.OpenAIErrorWithStatusCode {
return
service
.
OpenAIErrorWrapperLocal
(
err
,
"unmarshal_model_mapping_failed"
,
http
.
StatusInternalServerError
)
}
if
modelMap
[
textRequest
.
Model
]
!=
""
{
isModelMapped
=
true
textRequest
.
Model
=
modelMap
[
textRequest
.
Model
]
// set upstream model name
//isModelMapped = true
...
...
@@ -159,15 +161,23 @@ func TextHelper(c *gin.Context) *dto.OpenAIErrorWithStatusCode {
adaptor
.
Init
(
relayInfo
)
var
requestBody
io
.
Reader
convertedRequest
,
err
:=
adaptor
.
ConvertRequest
(
c
,
relayInfo
,
textRequest
)
if
err
!=
nil
{
return
service
.
OpenAIErrorWrapperLocal
(
err
,
"convert_request_failed"
,
http
.
StatusInternalServerError
)
}
jsonData
,
err
:=
json
.
Marshal
(
convertedRequest
)
if
err
!=
nil
{
return
service
.
OpenAIErrorWrapperLocal
(
err
,
"json_marshal_failed"
,
http
.
StatusInternalServerError
)
if
relayInfo
.
ChannelType
==
common
.
ChannelTypeOpenAI
&&
!
isModelMapped
{
body
,
err
:=
common
.
GetRequestBody
(
c
)
if
err
!=
nil
{
return
service
.
OpenAIErrorWrapperLocal
(
err
,
"get_request_body_failed"
,
http
.
StatusInternalServerError
)
}
requestBody
=
bytes
.
NewBuffer
(
body
)
}
else
{
convertedRequest
,
err
:=
adaptor
.
ConvertRequest
(
c
,
relayInfo
,
textRequest
)
if
err
!=
nil
{
return
service
.
OpenAIErrorWrapperLocal
(
err
,
"convert_request_failed"
,
http
.
StatusInternalServerError
)
}
jsonData
,
err
:=
json
.
Marshal
(
convertedRequest
)
if
err
!=
nil
{
return
service
.
OpenAIErrorWrapperLocal
(
err
,
"json_marshal_failed"
,
http
.
StatusInternalServerError
)
}
requestBody
=
bytes
.
NewBuffer
(
jsonData
)
}
requestBody
=
bytes
.
NewBuffer
(
jsonData
)
statusCodeMappingStr
:=
c
.
GetString
(
"status_code_mapping"
)
resp
,
err
:=
adaptor
.
DoRequest
(
c
,
relayInfo
,
requestBody
)
...
...
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