Skip to content

Commit 9c395b9

Browse files
Apply suggestions from code review
Co-authored-by: Jordan Stephens <jordan@stephens.io>
1 parent 4571d1d commit 9c395b9

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/api/routers/test_vertex.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,23 @@ def test_from_anthropic_to_openai_response():
5353
assert result["choices"][0]["finish_reason"] == "stop"
5454
assert result["usage"]["prompt_tokens"] == 5
5555

56-
def test_get_gcp_target_env(monkeypatch):
56+
def test_get_proxy_target_env(monkeypatch):
5757
monkeypatch.setenv("PROXY_TARGET", "https://custom-proxy")
58-
result = vertex.get_gcp_target("any-model", "/v1/chat/completions")
58+
result = vertex.get_proxy_target("any-model", "/v1/chat/completions")
5959
assert result == "https://custom-proxy"
6060

61-
def test_get_gcp_target_known_chat(monkeypatch):
61+
def test_get_proxy_target_known_chat(monkeypatch):
6262
monkeypatch.delenv("PROXY_TARGET", raising=False)
6363
model = vertex.known_chat_models[0]
6464
path = "/v1/chat/completions"
65-
result = vertex.get_gcp_target(model, path)
65+
result = vertex.get_proxy_target(model, path)
6666
assert "endpoints/openapi/chat/completions" in result
6767

68-
def test_get_gcp_target_raw_predict(monkeypatch):
68+
def test_get_proxy_target_raw_predict(monkeypatch):
6969
monkeypatch.delenv("PROXY_TARGET", raising=False)
7070
model = "unknown-model"
7171
path = "/v1/other"
72-
result = vertex.get_gcp_target(model, path)
72+
result = vertex.get_proxy_target(model, path)
7373
assert ":rawPredict" in result
7474

7575
@patch("api.routers.vertex.get_access_token", return_value="dummy-token")
@@ -84,7 +84,7 @@ def test_get_header_removes_hop_headers(mock_token, dummy_request):
8484
})
8585
model = "test-model"
8686
path = "/v1/chat/completions"
87-
with patch("api.routers.vertex.get_gcp_target", return_value="http://target"):
87+
with patch("api.routers.vertex.get_proxy_target", return_value="http://target"):
8888
target_url, headers = vertex.get_header(model, req, path)
8989
assert target_url == "http://target"
9090
assert "Host" not in headers

src/api/routers/vertex.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,20 @@ def get_access_token():
7373
credentials.refresh(auth_request)
7474
return credentials.token
7575

76-
def get_gcp_target(model, path):
76+
def get_proxy_target(model, path):
7777
"""
7878
Check if the environment variable is set to use GCP.
7979
"""
8080
if os.getenv("PROXY_TARGET"):
8181
return os.getenv("PROXY_TARGET")
82-
elif model in known_chat_models and "chat/completions" in path:
82+
elif model in known_chat_models and path.endswith("/chat/completions")
8383
return f"https://{location}-aiplatform.googleapis.com/v1/projects/{project_id}/locations/{location}/endpoints/openapi/chat/completions"
8484
else:
8585
return f"https://{location}-aiplatform.googleapis.com/v1/projects/{project_id}/locations/{location}/{model}:rawPredict"
8686

8787
def get_header(model, request, path):
8888
path_no_prefix = f"/{path.lstrip('/')}".removeprefix(API_ROUTE_PREFIX)
89-
target_url = get_gcp_target(model, path_no_prefix)
89+
target_url = get_proxy_target(model, path_no_prefix)
9090

9191
# remove hop-by-hop headers
9292
headers = {
@@ -168,7 +168,7 @@ async def handle_proxy(request: Request, path: str):
168168
headers=headers,
169169
content=json.dumps(content_json),
170170
params=request.query_params,
171-
timeout=30.0,
171+
timeout=5.0,
172172
)
173173

174174
content = response.content

0 commit comments

Comments
 (0)