fix: test Claude/Gemini endpoints with native request format (#6698)
This commit is contained in:
+40
-12
@@ -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
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
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,
|
|||||||
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,
|
|||||||
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}
|
||||||
|
|||||||
Reference in New Issue
Block a user