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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["uv_build>=0.9.10,<0.10.0"]
requires = ["uv_build>=0.9.10,<0.11.0"]
build-backend = "uv_build"

[project]
Expand Down
6 changes: 5 additions & 1 deletion src/typeagent/aitools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ def parse_azure_endpoint(
f"{endpoint_envvar}={azure_endpoint} doesn't contain valid api-version field"
)

return azure_endpoint, m.group(1)
# Strip query string — AsyncAzureOpenAI expects a clean base URL and
# receives api_version as a separate parameter.
clean_endpoint = azure_endpoint.split("?", 1)[0]

return clean_endpoint, m.group(1)


def get_azure_api_key(azure_api_key: str) -> str:
Expand Down
40 changes: 39 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_api_version_after_question_mark(
)
endpoint, version = utils.parse_azure_endpoint("TEST_ENDPOINT")
assert version == "2025-01-01-preview"
assert endpoint.startswith("https://")
assert endpoint == "https://myhost.openai.azure.com/openai/deployments/gpt-4"

def test_api_version_after_ampersand(self, monkeypatch: pytest.MonkeyPatch) -> None:
"""api-version preceded by & (not the first query parameter)."""
Expand All @@ -84,6 +84,44 @@ def test_missing_env_var_raises(self, monkeypatch: pytest.MonkeyPatch) -> None:
with pytest.raises(RuntimeError, match="not found"):
utils.parse_azure_endpoint("NONEXISTENT_ENDPOINT")

def test_query_string_stripped_from_endpoint(
self, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Returned endpoint should not contain query string parameters."""
monkeypatch.setenv(
"TEST_ENDPOINT",
"https://myhost.openai.azure.com?api-version=2024-06-01",
)
endpoint, version = utils.parse_azure_endpoint("TEST_ENDPOINT")
assert endpoint == "https://myhost.openai.azure.com"
assert version == "2024-06-01"

def test_query_string_stripped_with_path(
self, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Query string stripped even when endpoint includes a path."""
monkeypatch.setenv(
"TEST_ENDPOINT",
"https://myhost.openai.azure.com/openai/deployments/gpt-4?api-version=2025-01-01-preview",
)
endpoint, version = utils.parse_azure_endpoint("TEST_ENDPOINT")
assert endpoint == "https://myhost.openai.azure.com/openai/deployments/gpt-4"
assert "?" not in endpoint
assert version == "2025-01-01-preview"

def test_query_string_stripped_multiple_params(
self, monkeypatch: pytest.MonkeyPatch
) -> None:
"""All query parameters stripped, not just api-version."""
monkeypatch.setenv(
"TEST_ENDPOINT",
"https://myhost.openai.azure.com?foo=bar&api-version=2024-06-01",
)
endpoint, version = utils.parse_azure_endpoint("TEST_ENDPOINT")
assert endpoint == "https://myhost.openai.azure.com"
assert "foo" not in endpoint
assert version == "2024-06-01"

def test_no_api_version_raises(self, monkeypatch: pytest.MonkeyPatch) -> None:
"""RuntimeError when the endpoint has no api-version field."""
monkeypatch.setenv(
Expand Down
Loading