mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-05-07 05:32:42 +08:00
refactor(gemini): 优化 Gemini API 请求中可选参数的处理
- 调整 `gemini_chat_service` 中的 `_build_payload` 函数,使其在请求中未明确提供 `generationConfig` 和 `systemInstruction` 时,不会向 Gemini API 发送默认的空值(例如 `{}` 或 `""`)。现在将传递 `None`,这更符合 API 的预期行为。
- 在 `gemini_routes` 的 `verify_key` 函数中,为测试 API 密钥有效性的示例请求添加了明确的 `generationConfig`,以确保验证调用的健壮性。
This commit is contained in:
@@ -279,9 +279,10 @@ async def verify_key(api_key: str, chat_service: GeminiChatService = Depends(get
|
||||
contents=[
|
||||
GeminiContent(
|
||||
role="user",
|
||||
parts=[{"text": "hi"}]
|
||||
parts=[{"text": "hi"}],
|
||||
)
|
||||
]
|
||||
],
|
||||
generation_config={"temperature": 0.7, "top_p": 1.0, "max_output_tokens": 10}
|
||||
)
|
||||
|
||||
response = await chat_service.generate_content(
|
||||
|
||||
@@ -90,8 +90,8 @@ def _build_payload(model: str, request: GeminiRequest) -> Dict[str, Any]:
|
||||
"contents": request_dict.get("contents", []),
|
||||
"tools": _build_tools(model, request_dict),
|
||||
"safetySettings": _get_safety_settings(model),
|
||||
"generationConfig": request_dict.get("generationConfig", {}),
|
||||
"systemInstruction": request_dict.get("systemInstruction", ""),
|
||||
"generationConfig": request_dict.get("generationConfig"),
|
||||
"systemInstruction": request_dict.get("systemInstruction"),
|
||||
}
|
||||
|
||||
if model.endswith("-image") or model.endswith("-image-generation"):
|
||||
|
||||
Reference in New Issue
Block a user