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
Unverified
Commit
b941253a
authored
Aug 07, 2026
by
Seefs
Committed by
GitHub
Aug 07, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: test Claude/Gemini endpoints with native request format (#6698)
parent
c9bc0386
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
12 deletions
+40
-12
controller/channel-test.go
+40
-12
No files found.
controller/channel-test.go
View file @
b941253a
...
@@ -151,6 +151,11 @@ func testChannel(ctx context.Context, channel *model.Channel, testUserID int, te
...
@@ -151,6 +151,11 @@ func testChannel(ctx context.Context, channel *model.Channel, testUserID int, te
requestPath
=
"/v1/responses/compact"
requestPath
=
"/v1/responses/compact"
}
}
}
}
// Gemini 原生流式通过 URL action(:streamGenerateContent)表达而非请求体字段,
// GeminiChatRequest.IsStream 依据请求 URL 判定,合成请求路径需与生产入口保持一致
if
isStream
&&
constant
.
EndpointType
(
endpointType
)
==
constant
.
EndpointTypeGemini
{
requestPath
=
strings
.
Replace
(
requestPath
,
":generateContent"
,
":streamGenerateContent"
,
1
)
}
if
strings
.
HasPrefix
(
requestPath
,
"/v1/responses/compact"
)
{
if
strings
.
HasPrefix
(
requestPath
,
"/v1/responses/compact"
)
{
testModel
=
ratio_setting
.
WithCompactModelSuffix
(
testModel
)
testModel
=
ratio_setting
.
WithCompactModelSuffix
(
testModel
)
}
}
...
@@ -371,14 +376,18 @@ func testChannel(ctx context.Context, channel *model.Channel, testUserID int, te
...
@@ -371,14 +376,18 @@ func testChannel(ctx context.Context, channel *model.Channel, testUserID int, te
}
}
}
}
default
:
default
:
// Chat/Completion 等其他请求类型
switch
req
:=
request
.
(
type
)
{
if
generalReq
,
ok
:=
request
.
(
*
dto
.
GeneralOpenAIRequest
);
ok
{
case
*
dto
.
GeneralOpenAIRequest
:
convertedRequest
,
err
=
adaptor
.
ConvertOpenAIRequest
(
c
,
info
,
generalReq
)
convertedRequest
,
err
=
adaptor
.
ConvertOpenAIRequest
(
c
,
info
,
req
)
}
else
{
case
*
dto
.
ClaudeRequest
:
convertedRequest
,
err
=
adaptor
.
ConvertClaudeRequest
(
c
,
info
,
req
)
case
*
dto
.
GeminiChatRequest
:
convertedRequest
,
err
=
adaptor
.
ConvertGeminiRequest
(
c
,
info
,
req
)
default
:
return
testResult
{
return
testResult
{
context
:
c
,
context
:
c
,
localErr
:
errors
.
New
(
"invalid
general
request type"
),
localErr
:
errors
.
New
(
"invalid
chat
request type"
),
newAPIError
:
types
.
NewError
(
errors
.
New
(
"invalid
general
request type"
),
types
.
ErrorCodeConvertRequestFailed
),
newAPIError
:
types
.
NewError
(
errors
.
New
(
"invalid
chat
request type"
),
types
.
ErrorCodeConvertRequestFailed
),
}
}
}
}
}
}
...
@@ -733,12 +742,31 @@ func buildTestRequest(model string, endpointType string, channel *model.Channel,
...
@@ -733,12 +742,31 @@ func buildTestRequest(model string, endpointType string, channel *model.Channel,
Model
:
model
,
Model
:
model
,
Input
:
testResponsesInput
,
Input
:
testResponsesInput
,
}
}
case
constant
.
EndpointTypeAnthropic
,
constant
.
EndpointTypeGemini
,
constant
.
EndpointTypeOpenAI
:
case
constant
.
EndpointTypeAnthropic
:
// 返回 GeneralOpenAIRequest
return
&
dto
.
ClaudeRequest
{
maxTokens
:=
uint
(
16
)
Model
:
model
,
if
constant
.
EndpointType
(
endpointType
)
==
constant
.
EndpointTypeGemini
{
Stream
:
lo
.
ToPtr
(
isStream
),
maxTokens
=
3000
MaxTokens
:
lo
.
ToPtr
(
uint
(
16
)),
Messages
:
[]
dto
.
ClaudeMessage
{
{
Role
:
"user"
,
Content
:
"hi"
,
},
},
}
case
constant
.
EndpointTypeGemini
:
return
&
dto
.
GeminiChatRequest
{
Contents
:
[]
dto
.
GeminiChatContent
{
{
Role
:
"user"
,
Parts
:
[]
dto
.
GeminiPart
{{
Text
:
"hi"
}},
},
},
GenerationConfig
:
dto
.
GeminiChatGenerationConfig
{
MaxOutputTokens
:
lo
.
ToPtr
(
uint
(
3000
)),
},
}
}
case
constant
.
EndpointTypeOpenAI
:
req
:=
&
dto
.
GeneralOpenAIRequest
{
req
:=
&
dto
.
GeneralOpenAIRequest
{
Model
:
model
,
Model
:
model
,
Stream
:
lo
.
ToPtr
(
isStream
),
Stream
:
lo
.
ToPtr
(
isStream
),
...
@@ -748,7 +776,7 @@ func buildTestRequest(model string, endpointType string, channel *model.Channel,
...
@@ -748,7 +776,7 @@ func buildTestRequest(model string, endpointType string, channel *model.Channel,
Content
:
"hi"
,
Content
:
"hi"
,
},
},
},
},
MaxTokens
:
lo
.
ToPtr
(
maxTokens
),
MaxTokens
:
lo
.
ToPtr
(
uint
(
16
)
),
}
}
if
isStream
{
if
isStream
{
req
.
StreamOptions
=
&
dto
.
StreamOptions
{
IncludeUsage
:
true
}
req
.
StreamOptions
=
&
dto
.
StreamOptions
{
IncludeUsage
:
true
}
...
...
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