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
33 changes: 8 additions & 25 deletions litellm/llms/azure/responses/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def model_in_websocket_url(self) -> bool:
#########################################################
########## DELETE RESPONSE API TRANSFORMATION ##############
#########################################################
def _construct_url_for_response_id_in_path(self, api_base: str, response_id: str) -> str:
def _construct_url_for_response_id_in_path(self, api_base: str, response_id: str, path_suffix: str = "") -> str:
"""
Constructs a URL for the API request with the response_id in the path.
"""
Expand All @@ -218,14 +218,14 @@ def _construct_url_for_response_id_in_path(self, api_base: str, response_id: str
# Remove trailing slash if present to avoid double slashes
path = parsed_url.path.rstrip("/")
encoded_response_id = encode_url_path_segment(response_id, field_name="response_id")
new_path = f"{path}/{encoded_response_id}"
new_path = f"{path}/{encoded_response_id}{path_suffix}"

# Reconstruct the URL with all original components but with the modified path
constructed_url = urlunparse(
(
parsed_url.scheme, # http, https
parsed_url.netloc, # domain name, port
new_path, # path with response_id added
new_path,
parsed_url.params, # parameters
parsed_url.query, # query string
parsed_url.fragment, # fragment
Expand Down Expand Up @@ -288,7 +288,9 @@ def transform_list_input_items_request(
limit: int = 20,
order: Literal["asc", "desc"] = "desc",
) -> Tuple[str, Dict]:
url = self._construct_url_for_response_id_in_path(api_base=api_base, response_id=response_id) + "/input_items"
url = self._construct_url_for_response_id_in_path(
api_base=api_base, response_id=response_id, path_suffix="/input_items"
)
params: Dict[str, Any] = {}
if after is not None:
params["after"] = after
Expand Down Expand Up @@ -322,27 +324,8 @@ def transform_cancel_response_api_request(
This function handles URLs with query parameters by inserting the response_id
at the correct location (before any query parameters).
"""
from urllib.parse import urlparse, urlunparse

# Parse the URL to separate its components
parsed_url = urlparse(api_base)

# Insert the response_id and /cancel at the end of the path component
# Remove trailing slash if present to avoid double slashes
path = parsed_url.path.rstrip("/")
encoded_response_id = encode_url_path_segment(response_id, field_name="response_id")
new_path = f"{path}/{encoded_response_id}/cancel"

# Reconstruct the URL with all original components but with the modified path
cancel_url = urlunparse(
(
parsed_url.scheme, # http, https
parsed_url.netloc, # domain name, port
new_path, # path with response_id and /cancel added
parsed_url.params, # parameters
parsed_url.query, # query string
parsed_url.fragment, # fragment
)
cancel_url = self._construct_url_for_response_id_in_path(
api_base=api_base, response_id=response_id, path_suffix="/cancel"
)

data: Dict = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,24 @@ def test_azure_cancel_response_api_request(self):
assert url == expected_url
assert data == {}

def test_azure_list_input_items_request_url_path_before_query(self):
from litellm.types.router import GenericLiteLLMParams

api_base = "https://test.openai.azure.com/openai/responses?api-version=2025-03-01-preview"

url, params = self.config.transform_list_input_items_request(
response_id="resp_test123",
api_base=api_base,
litellm_params=GenericLiteLLMParams(api_version="2025-03-01-preview"),
headers={},
)

assert (
url
== "https://test.openai.azure.com/openai/responses/resp_test123/input_items?api-version=2025-03-01-preview"
)
assert params == {"limit": 20, "order": "desc"}

def test_azure_cancel_response_api_response(self):
"""Test Azure cancel response API response transformation"""
from unittest.mock import Mock
Expand Down
Loading