From f778b3ad5de8299269b0ad57c5c711857a22b234 Mon Sep 17 00:00:00 2001 From: Wenjing Yu Date: Mon, 4 Aug 2025 14:09:58 -0700 Subject: [PATCH] fix base url for vertex provider --- app/services/providers/vertex_adapter.py | 12 ++++++++++++ tests/unit_tests/test_vertex_adapter.py | 13 +++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/unit_tests/test_vertex_adapter.py diff --git a/app/services/providers/vertex_adapter.py b/app/services/providers/vertex_adapter.py index 089f966..61c2bff 100644 --- a/app/services/providers/vertex_adapter.py +++ b/app/services/providers/vertex_adapter.py @@ -46,6 +46,18 @@ def parse_config(self, config: dict[str, str] | None): self.validate_config(config) self.publisher = config.get("publisher", "anthropic").lower() self.location = config["location"].lower() + + # ------------------------------------------------------------------ + # Build the Vertex API endpoint based on the location. + # If the location is "global", use the default domain without the + # region prefix. Otherwise, prefix the domain with the region. + # global -> https://aiplatform.googleapis.com + # us-east1 -> https://us-east1-aiplatform.googleapis.com + # ------------------------------------------------------------------ + if self.location == "global": + self._base_url = "https://aiplatform.googleapis.com" + else: + self._base_url = f"https://{self.location}-aiplatform.googleapis.com" @staticmethod def validate_api_key(api_key: str): diff --git a/tests/unit_tests/test_vertex_adapter.py b/tests/unit_tests/test_vertex_adapter.py new file mode 100644 index 0000000..49ca2b1 --- /dev/null +++ b/tests/unit_tests/test_vertex_adapter.py @@ -0,0 +1,13 @@ +from app.services.providers.vertex_adapter import VertexAdapter + + +def test_vertex_adapter_base_url_global(): + config = {"publisher": "anthropic", "location": "global"} + adapter = VertexAdapter("vertex", None, config) + assert adapter._base_url == "https://aiplatform.googleapis.com" + + +def test_vertex_adapter_base_url_region(): + config = {"publisher": "anthropic", "location": "us-east1"} + adapter = VertexAdapter("vertex", None, config) + assert adapter._base_url == "https://us-east1-aiplatform.googleapis.com" \ No newline at end of file