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
710c88cb
authored
Nov 19, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 暂时禁用透传功能
parent
55f9a48f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
19 deletions
+22
-19
relay/channel/openai/adaptor.go
+1
-1
relay/relay-text.go
+21
-18
No files found.
relay/channel/openai/adaptor.go
View file @
710c88cb
...
@@ -102,7 +102,7 @@ func (a *Adaptor) ConvertRequest(c *gin.Context, info *relaycommon.RelayInfo, re
...
@@ -102,7 +102,7 @@ func (a *Adaptor) ConvertRequest(c *gin.Context, info *relaycommon.RelayInfo, re
if
request
==
nil
{
if
request
==
nil
{
return
nil
,
errors
.
New
(
"request is nil"
)
return
nil
,
errors
.
New
(
"request is nil"
)
}
}
if
info
.
ChannelType
!=
common
.
ChannelTypeOpenAI
{
if
info
.
ChannelType
!=
common
.
ChannelTypeOpenAI
&&
info
.
ChannelType
!=
common
.
ChannelTypeAzure
{
request
.
StreamOptions
=
nil
request
.
StreamOptions
=
nil
}
}
if
strings
.
HasPrefix
(
request
.
Model
,
"o1-"
)
{
if
strings
.
HasPrefix
(
request
.
Model
,
"o1-"
)
{
...
...
relay/relay-text.go
View file @
710c88cb
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"encoding/json"
"encoding/json"
"errors"
"errors"
"fmt"
"fmt"
"github.com/bytedance/sonic"
"io"
"io"
"math"
"math"
"net/http"
"net/http"
...
@@ -76,7 +77,7 @@ func TextHelper(c *gin.Context) (openaiErr *dto.OpenAIErrorWithStatusCode) {
...
@@ -76,7 +77,7 @@ func TextHelper(c *gin.Context) (openaiErr *dto.OpenAIErrorWithStatusCode) {
}
}
// map model name
// map model name
isModelMapped
:=
false
//
isModelMapped := false
modelMapping
:=
c
.
GetString
(
"model_mapping"
)
modelMapping
:=
c
.
GetString
(
"model_mapping"
)
//isModelMapped := false
//isModelMapped := false
if
modelMapping
!=
""
&&
modelMapping
!=
"{}"
{
if
modelMapping
!=
""
&&
modelMapping
!=
"{}"
{
...
@@ -86,7 +87,7 @@ func TextHelper(c *gin.Context) (openaiErr *dto.OpenAIErrorWithStatusCode) {
...
@@ -86,7 +87,7 @@ func TextHelper(c *gin.Context) (openaiErr *dto.OpenAIErrorWithStatusCode) {
return
service
.
OpenAIErrorWrapperLocal
(
err
,
"unmarshal_model_mapping_failed"
,
http
.
StatusInternalServerError
)
return
service
.
OpenAIErrorWrapperLocal
(
err
,
"unmarshal_model_mapping_failed"
,
http
.
StatusInternalServerError
)
}
}
if
modelMap
[
textRequest
.
Model
]
!=
""
{
if
modelMap
[
textRequest
.
Model
]
!=
""
{
isModelMapped
=
true
//
isModelMapped = true
textRequest
.
Model
=
modelMap
[
textRequest
.
Model
]
textRequest
.
Model
=
modelMap
[
textRequest
.
Model
]
// set upstream model name
// set upstream model name
//isModelMapped = true
//isModelMapped = true
...
@@ -165,23 +166,25 @@ func TextHelper(c *gin.Context) (openaiErr *dto.OpenAIErrorWithStatusCode) {
...
@@ -165,23 +166,25 @@ func TextHelper(c *gin.Context) (openaiErr *dto.OpenAIErrorWithStatusCode) {
adaptor
.
Init
(
relayInfo
)
adaptor
.
Init
(
relayInfo
)
var
requestBody
io
.
Reader
var
requestBody
io
.
Reader
if
relayInfo
.
ChannelType
==
common
.
ChannelTypeOpenAI
&&
!
isModelMapped
{
//if relayInfo.ChannelType == common.ChannelTypeOpenAI && !isModelMapped {
body
,
err
:=
common
.
GetRequestBody
(
c
)
// body, err := common.GetRequestBody(c)
if
err
!=
nil
{
// if err != nil {
return
service
.
OpenAIErrorWrapperLocal
(
err
,
"get_request_body_failed"
,
http
.
StatusInternalServerError
)
// return service.OpenAIErrorWrapperLocal(err, "get_request_body_failed", http.StatusInternalServerError)
}
// }
requestBody
=
bytes
.
NewBuffer
(
body
)
// requestBody = bytes.NewBuffer(body)
}
else
{
//} else {
convertedRequest
,
err
:=
adaptor
.
ConvertRequest
(
c
,
relayInfo
,
textRequest
)
//
if
err
!=
nil
{
//}
return
service
.
OpenAIErrorWrapperLocal
(
err
,
"convert_request_failed"
,
http
.
StatusInternalServerError
)
}
convertedRequest
,
err
:=
adaptor
.
ConvertRequest
(
c
,
relayInfo
,
textRequest
)
jsonData
,
err
:=
json
.
Marshal
(
convertedRequest
)
if
err
!=
nil
{
if
err
!=
nil
{
return
service
.
OpenAIErrorWrapperLocal
(
err
,
"convert_request_failed"
,
http
.
StatusInternalServerError
)
return
service
.
OpenAIErrorWrapperLocal
(
err
,
"json_marshal_failed"
,
http
.
StatusInternalServerError
)
}
}
jsonData
,
err
:=
sonic
.
Marshal
(
convertedRequest
)
requestBody
=
bytes
.
NewBuffer
(
jsonData
)
if
err
!=
nil
{
return
service
.
OpenAIErrorWrapperLocal
(
err
,
"json_marshal_failed"
,
http
.
StatusInternalServerError
)
}
}
requestBody
=
bytes
.
NewBuffer
(
jsonData
)
statusCodeMappingStr
:=
c
.
GetString
(
"status_code_mapping"
)
statusCodeMappingStr
:=
c
.
GetString
(
"status_code_mapping"
)
var
httpResp
*
http
.
Response
var
httpResp
*
http
.
Response
...
...
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