From 398f488b1bae5c9c2819993c32dcbc79c7443fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Lukas?= Date: Wed, 24 Jun 2026 05:07:05 +0200 Subject: [PATCH] fix: support Google Cloud Gemini eu/us multipoint endpoints (#15990) fix: support Google Cloud Gemini eu/us multipoint endpoints (#15990) --- rag/llm/chat_model.py | 30 ++++++++++++++++++++++++++++-- rag/llm/cv_model.py | 29 +++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/rag/llm/chat_model.py b/rag/llm/chat_model.py index 8d616d7293..bc452b1bbe 100644 --- a/rag/llm/chat_model.py +++ b/rag/llm/chat_model.py @@ -1122,6 +1122,22 @@ class BaiduYiyanChat(Base): class GoogleChat(Base): _FACTORY_NAME = "Google Cloud" + @staticmethod + def _vertex_http_options(region: str): + region_norm = (region or "").strip().lower() + multipoint_hosts = { + "eu": "https://aiplatform.eu.rep.googleapis.com/", + "us": "https://aiplatform.us.rep.googleapis.com/", + } + base_url = multipoint_hosts.get(region_norm) + if base_url: + from google.genai.types import HttpOptions + + # Gemini 3.x multi-region endpoints require *.rep hostnames + # instead of region-aiplatform host synthesis. + return HttpOptions(base_url=base_url, api_version="v1") + return None + def __init__(self, key, model_name, base_url=None, **kwargs): super().__init__(key, model_name, base_url=base_url, **kwargs) @@ -1152,11 +1168,21 @@ class GoogleChat(Base): else: from google import genai + client_kwargs = { + "vertexai": True, + "project": project_id, + "location": region, + } + http_options = self._vertex_http_options(region) + if http_options is not None: + client_kwargs["http_options"] = http_options + if access_token: credits = service_account.Credentials.from_service_account_info(access_token, scopes=scopes) - self.client = genai.Client(vertexai=True, project=project_id, location=region, credentials=credits) + client_kwargs["credentials"] = credits + self.client = genai.Client(**client_kwargs) else: - self.client = genai.Client(vertexai=True, project=project_id, location=region) + self.client = genai.Client(**client_kwargs) def _clean_conf(self, gen_conf): if "claude" in self.model_name: diff --git a/rag/llm/cv_model.py b/rag/llm/cv_model.py index 9b083acca8..a832ad6c1a 100644 --- a/rag/llm/cv_model.py +++ b/rag/llm/cv_model.py @@ -1238,6 +1238,22 @@ class AnthropicCV(Base): class GoogleCV(AnthropicCV, GeminiCV): _FACTORY_NAME = "Google Cloud" + @staticmethod + def _vertex_http_options(region: str): + region_norm = (region or "").strip().lower() + multipoint_hosts = { + "eu": "https://aiplatform.eu.rep.googleapis.com/", + "us": "https://aiplatform.us.rep.googleapis.com/", + } + base_url = multipoint_hosts.get(region_norm) + if base_url: + from google.genai.types import HttpOptions + + # Gemini 3.x multi-region endpoints require *.rep hostnames + # instead of region-aiplatform host synthesis. + return HttpOptions(base_url=base_url, api_version="v1") + return None + def __init__(self, key, model_name, lang="Chinese", base_url=None, **kwargs): import base64 @@ -1266,11 +1282,20 @@ class GoogleCV(AnthropicCV, GeminiCV): self.client = AnthropicVertex(region=region, project_id=project_id) else: from google import genai + client_kwargs = { + "vertexai": True, + "project": project_id, + "location": region, + } + http_options = self._vertex_http_options(region) + if http_options is not None: + client_kwargs["http_options"] = http_options if access_token: credits = service_account.Credentials.from_service_account_info(access_token, scopes=scopes) - self.client = genai.Client(vertexai=True, project=project_id, location=region, credentials=credits) + client_kwargs["credentials"] = credits + self.client = genai.Client(**client_kwargs) else: - self.client = genai.Client(vertexai=True, project=project_id, location=region) + self.client = genai.Client(**client_kwargs) Base.__init__(self, **kwargs) def describe(self, image):