Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/services/providers/vertex_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
13 changes: 13 additions & 0 deletions tests/unit_tests/test_vertex_adapter.py
Original file line number Diff line number Diff line change
@@ -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"
Loading