fix: test Claude/Gemini endpoints with native request format (#6698)

This commit is contained in:
Seefs
2026-08-07 13:35:46 +08:00
committed by GitHub
parent c9bc038649
commit b941253aea
+40 -12
View File
@@ -151,6 +151,11 @@ func testChannel(ctx context.Context, channel *model.Channel, testUserID int, te
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") {
testModel = ratio_setting.WithCompactModelSuffix(testModel)
}
@@ -371,14 +376,18 @@ func testChannel(ctx context.Context, channel *model.Channel, testUserID int, te
}
}
default:
// Chat/Completion 等其他请求类型
if generalReq, ok := request.(*dto.GeneralOpenAIRequest); ok {
convertedRequest, err = adaptor.ConvertOpenAIRequest(c, info, generalReq)
} else {
switch req := request.(type) {
case *dto.GeneralOpenAIRequest:
convertedRequest, err = adaptor.ConvertOpenAIRequest(c, info, req)
case *dto.ClaudeRequest:
convertedRequest, err = adaptor.ConvertClaudeRequest(c, info, req)
case *dto.GeminiChatRequest:
convertedRequest, err = adaptor.ConvertGeminiRequest(c, info, req)
default:
return testResult{
context: c,
localErr: errors.New("invalid general request type"),
newAPIError: types.NewError(errors.New("invalid general request type"), types.ErrorCodeConvertRequestFailed),
localErr: errors.New("invalid chat request type"),
newAPIError: types.NewError(errors.New("invalid chat request type"), types.ErrorCodeConvertRequestFailed),
}
}
}
@@ -733,12 +742,31 @@ func buildTestRequest(model string, endpointType string, channel *model.Channel,
Model: model,
Input: testResponsesInput,
}
case constant.EndpointTypeAnthropic, constant.EndpointTypeGemini, constant.EndpointTypeOpenAI:
// 返回 GeneralOpenAIRequest
maxTokens := uint(16)
if constant.EndpointType(endpointType) == constant.EndpointTypeGemini {
maxTokens = 3000
case constant.EndpointTypeAnthropic:
return &dto.ClaudeRequest{
Model: model,
Stream: lo.ToPtr(isStream),
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{
Model: model,
Stream: lo.ToPtr(isStream),
@@ -748,7 +776,7 @@ func buildTestRequest(model string, endpointType string, channel *model.Channel,
Content: "hi",
},
},
MaxTokens: lo.ToPtr(maxTokens),
MaxTokens: lo.ToPtr(uint(16)),
}
if isStream {
req.StreamOptions = &dto.StreamOptions{IncludeUsage: true}