Merge pull request #1248 from foxplaying/patch-2

Gemini:尝试传入自定义base_url(实验性)
pull/1258/head
UnCLAS-Prommer 2025-09-22 01:07:46 +08:00 committed by GitHub
commit f075f28f02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View File

@ -349,6 +349,18 @@ class GeminiClient(BaseClient):
api_key=api_provider.api_key,
) # 这里和openai不一样gemini会自己决定自己是否需要retry
# 尝试传入自定义base_url(实验性必须为Gemini格式)
if hasattr(api_provider, "base_url") and api_provider.base_url:
base_url = api_provider.base_url.rstrip("/") # 去掉末尾 /
self.client._api_client._http_options.base_url = base_url
# 如果 base_url 已经带了 /v1 或 /v1beta就清掉 SDK 的 api_version
if base_url.endswith("/v1") or base_url.endswith("/v1beta"):
self.client._api_client._http_options.api_version = None
# 让 GeminiClient 内部也能访问底层 api_client
self._api_client = self.client._api_client
@staticmethod
def clamp_thinking_budget(tb: int, model_id: str) -> int:
"""

View File

@ -23,7 +23,7 @@ retry_interval = 5
[[api_providers]] # 特殊Google的Gimini使用特殊API与OpenAI格式不兼容需要配置client为"gemini"
name = "Google"
base_url = "https://api.google.com/v1"
base_url = "https://generativelanguage.googleapis.com/v1beta"
api_key = "your-google-api-key-1"
client_type = "gemini"
max_retry = 2