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
2cb7b9ae
authored
Jul 26, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: improve error messaging and JSON schema handling in distributor and relay components
parent
f6107734
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
11 deletions
+17
-11
dto/openai_request.go
+2
-2
middleware/distributor.go
+6
-7
relay/channel/gemini/relay-gemini.go
+6
-2
relay/relay-text.go
+3
-0
No files found.
dto/openai_request.go
View file @
2cb7b9ae
...
@@ -8,14 +8,14 @@ import (
...
@@ -8,14 +8,14 @@ import (
type
ResponseFormat
struct
{
type
ResponseFormat
struct
{
Type
string
`json:"type,omitempty"`
Type
string
`json:"type,omitempty"`
JsonSchema
*
FormatJsonSchema
`json:"json_schema,omitempty"`
JsonSchema
json
.
RawMessage
`json:"json_schema,omitempty"`
}
}
type
FormatJsonSchema
struct
{
type
FormatJsonSchema
struct
{
Description
string
`json:"description,omitempty"`
Description
string
`json:"description,omitempty"`
Name
string
`json:"name"`
Name
string
`json:"name"`
Schema
any
`json:"schema,omitempty"`
Schema
any
`json:"schema,omitempty"`
Strict
any
`json:"strict,omitempty"`
Strict
json
.
RawMessage
`json:"strict,omitempty"`
}
}
type
GeneralOpenAIRequest
struct
{
type
GeneralOpenAIRequest
struct
{
...
...
middleware/distributor.go
View file @
2cb7b9ae
...
@@ -111,18 +111,17 @@ func Distribute() func(c *gin.Context) {
...
@@ -111,18 +111,17 @@ func Distribute() func(c *gin.Context) {
if
userGroup
==
"auto"
{
if
userGroup
==
"auto"
{
showGroup
=
fmt
.
Sprintf
(
"auto(%s)"
,
selectGroup
)
showGroup
=
fmt
.
Sprintf
(
"auto(%s)"
,
selectGroup
)
}
}
message
:=
fmt
.
Sprintf
(
"获取分组 %s 下模型 %s 的可用渠道失败(distributor): %s"
,
showGroup
,
modelRequest
.
Model
,
err
.
Error
())
message
:=
fmt
.
Sprintf
(
"获取分组 %s 下模型 %s 的可用渠道失败(
数据库一致性已被破坏,
distributor): %s"
,
showGroup
,
modelRequest
.
Model
,
err
.
Error
())
// 如果错误,但是渠道不为空,说明是数据库一致性问题
// 如果错误,但是渠道不为空,说明是数据库一致性问题
if
channel
!=
nil
{
//if channel != nil {
common
.
SysError
(
fmt
.
Sprintf
(
"渠道不存在:%d"
,
channel
.
Id
))
// common.SysError(fmt.Sprintf("渠道不存在:%d", channel.Id))
message
=
"数据库一致性已被破坏,请联系管理员"
// message = "数据库一致性已被破坏,请联系管理员"
}
//}
// 如果错误,而且渠道为空,说明是没有可用渠道
abortWithOpenAiMessage
(
c
,
http
.
StatusServiceUnavailable
,
message
)
abortWithOpenAiMessage
(
c
,
http
.
StatusServiceUnavailable
,
message
)
return
return
}
}
if
channel
==
nil
{
if
channel
==
nil
{
abortWithOpenAiMessage
(
c
,
http
.
StatusServiceUnavailable
,
fmt
.
Sprintf
(
"分组 %s 下模型 %s
的可用渠道不存在(数据库一致性已被破坏,
distributor)"
,
userGroup
,
modelRequest
.
Model
))
abortWithOpenAiMessage
(
c
,
http
.
StatusServiceUnavailable
,
fmt
.
Sprintf
(
"分组 %s 下模型 %s
无可用渠道(
distributor)"
,
userGroup
,
modelRequest
.
Model
))
return
return
}
}
}
}
...
...
relay/channel/gemini/relay-gemini.go
View file @
2cb7b9ae
...
@@ -219,11 +219,15 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest, info *relaycommon
...
@@ -219,11 +219,15 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest, info *relaycommon
if
textRequest
.
ResponseFormat
!=
nil
&&
(
textRequest
.
ResponseFormat
.
Type
==
"json_schema"
||
textRequest
.
ResponseFormat
.
Type
==
"json_object"
)
{
if
textRequest
.
ResponseFormat
!=
nil
&&
(
textRequest
.
ResponseFormat
.
Type
==
"json_schema"
||
textRequest
.
ResponseFormat
.
Type
==
"json_object"
)
{
geminiRequest
.
GenerationConfig
.
ResponseMimeType
=
"application/json"
geminiRequest
.
GenerationConfig
.
ResponseMimeType
=
"application/json"
if
textRequest
.
ResponseFormat
.
JsonSchema
!=
nil
&&
textRequest
.
ResponseFormat
.
JsonSchema
.
Schema
!=
nil
{
if
len
(
textRequest
.
ResponseFormat
.
JsonSchema
)
>
0
{
cleanedSchema
:=
removeAdditionalPropertiesWithDepth
(
textRequest
.
ResponseFormat
.
JsonSchema
.
Schema
,
0
)
// 先将json.RawMessage解析
var
jsonSchema
dto
.
FormatJsonSchema
if
err
:=
common
.
Unmarshal
(
textRequest
.
ResponseFormat
.
JsonSchema
,
&
jsonSchema
);
err
==
nil
{
cleanedSchema
:=
removeAdditionalPropertiesWithDepth
(
jsonSchema
.
Schema
,
0
)
geminiRequest
.
GenerationConfig
.
ResponseSchema
=
cleanedSchema
geminiRequest
.
GenerationConfig
.
ResponseSchema
=
cleanedSchema
}
}
}
}
}
tool_call_ids
:=
make
(
map
[
string
]
string
)
tool_call_ids
:=
make
(
map
[
string
]
string
)
var
system_content
[]
string
var
system_content
[]
string
//shouldAddDummyModelMessage := false
//shouldAddDummyModelMessage := false
...
...
relay/relay-text.go
View file @
2cb7b9ae
...
@@ -175,6 +175,9 @@ func TextHelper(c *gin.Context) (newAPIError *types.NewAPIError) {
...
@@ -175,6 +175,9 @@ func TextHelper(c *gin.Context) (newAPIError *types.NewAPIError) {
if
err
!=
nil
{
if
err
!=
nil
{
return
types
.
NewErrorWithStatusCode
(
err
,
types
.
ErrorCodeReadRequestBodyFailed
,
http
.
StatusBadRequest
)
return
types
.
NewErrorWithStatusCode
(
err
,
types
.
ErrorCodeReadRequestBodyFailed
,
http
.
StatusBadRequest
)
}
}
if
common
.
DebugEnabled
{
println
(
"requestBody: "
,
string
(
body
))
}
requestBody
=
bytes
.
NewBuffer
(
body
)
requestBody
=
bytes
.
NewBuffer
(
body
)
}
else
{
}
else
{
convertedRequest
,
err
:=
adaptor
.
ConvertOpenAIRequest
(
c
,
relayInfo
,
textRequest
)
convertedRequest
,
err
:=
adaptor
.
ConvertOpenAIRequest
(
c
,
relayInfo
,
textRequest
)
...
...
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