fix: Antigravity 测试连接使用最小 token 消耗
- buildGeminiTestRequest: 输入 "." + maxOutputTokens: 1 - buildClaudeTestRequest: 输入 "." + MaxTokens: 1 - buildGenerationConfig: 支持透传 MaxTokens 参数
This commit is contained in:
@@ -429,6 +429,11 @@ func buildGenerationConfig(req *ClaudeRequest) *GeminiGenerationConfig {
|
|||||||
StopSequences: DefaultStopSequences,
|
StopSequences: DefaultStopSequences,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果请求中指定了 MaxTokens,使用请求值
|
||||||
|
if req.MaxTokens > 0 {
|
||||||
|
config.MaxOutputTokens = req.MaxTokens
|
||||||
|
}
|
||||||
|
|
||||||
// Thinking 配置
|
// Thinking 配置
|
||||||
if req.Thinking != nil && req.Thinking.Type == "enabled" {
|
if req.Thinking != nil && req.Thinking.Type == "enabled" {
|
||||||
config.ThinkingConfig = &GeminiThinkingConfig{
|
config.ThinkingConfig = &GeminiThinkingConfig{
|
||||||
|
|||||||
@@ -276,13 +276,14 @@ func (s *AntigravityGatewayService) TestConnection(ctx context.Context, account
|
|||||||
}
|
}
|
||||||
|
|
||||||
// buildGeminiTestRequest 构建 Gemini 格式测试请求
|
// buildGeminiTestRequest 构建 Gemini 格式测试请求
|
||||||
|
// 使用最小 token 消耗:输入 "." + maxOutputTokens: 1
|
||||||
func (s *AntigravityGatewayService) buildGeminiTestRequest(projectID, model string) ([]byte, error) {
|
func (s *AntigravityGatewayService) buildGeminiTestRequest(projectID, model string) ([]byte, error) {
|
||||||
payload := map[string]any{
|
payload := map[string]any{
|
||||||
"contents": []map[string]any{
|
"contents": []map[string]any{
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
"parts": []map[string]any{
|
"parts": []map[string]any{
|
||||||
{"text": "hi"},
|
{"text": "."},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -292,22 +293,26 @@ func (s *AntigravityGatewayService) buildGeminiTestRequest(projectID, model stri
|
|||||||
{"text": antigravity.GetDefaultIdentityPatch()},
|
{"text": antigravity.GetDefaultIdentityPatch()},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"generationConfig": map[string]any{
|
||||||
|
"maxOutputTokens": 1,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
payloadBytes, _ := json.Marshal(payload)
|
payloadBytes, _ := json.Marshal(payload)
|
||||||
return s.wrapV1InternalRequest(projectID, model, payloadBytes)
|
return s.wrapV1InternalRequest(projectID, model, payloadBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// buildClaudeTestRequest 构建 Claude 格式测试请求并转换为 Gemini 格式
|
// buildClaudeTestRequest 构建 Claude 格式测试请求并转换为 Gemini 格式
|
||||||
|
// 使用最小 token 消耗:输入 "." + MaxTokens: 1
|
||||||
func (s *AntigravityGatewayService) buildClaudeTestRequest(projectID, mappedModel string) ([]byte, error) {
|
func (s *AntigravityGatewayService) buildClaudeTestRequest(projectID, mappedModel string) ([]byte, error) {
|
||||||
claudeReq := &antigravity.ClaudeRequest{
|
claudeReq := &antigravity.ClaudeRequest{
|
||||||
Model: mappedModel,
|
Model: mappedModel,
|
||||||
Messages: []antigravity.ClaudeMessage{
|
Messages: []antigravity.ClaudeMessage{
|
||||||
{
|
{
|
||||||
Role: "user",
|
Role: "user",
|
||||||
Content: json.RawMessage(`"hi"`),
|
Content: json.RawMessage(`"."`),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
MaxTokens: 1024,
|
MaxTokens: 1,
|
||||||
Stream: false,
|
Stream: false,
|
||||||
}
|
}
|
||||||
return antigravity.TransformClaudeToGemini(claudeReq, projectID, mappedModel)
|
return antigravity.TransformClaudeToGemini(claudeReq, projectID, mappedModel)
|
||||||
|
|||||||
Reference in New Issue
Block a user