mirror of
https://github.com/BerriAI/litellm.git
synced 2026-08-28 05:25:59 +00:00
fix(azure): build responses input_items url with path before query string (#32270)
* fix(azure): build responses input_items url with path before query string * chore(azure): drop stale inline comment in responses url helper
This commit is contained in:
parent
24082bc07d
commit
e2df153bfb
2 changed files with 26 additions and 25 deletions
|
|
@ -205,7 +205,7 @@ class AzureOpenAIResponsesAPIConfig(OpenAIResponsesAPIConfig):
|
|||
#########################################################
|
||||
########## 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.
|
||||
"""
|
||||
|
|
@ -218,14 +218,14 @@ class AzureOpenAIResponsesAPIConfig(OpenAIResponsesAPIConfig):
|
|||
# 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
|
||||
|
|
@ -288,7 +288,9 @@ class AzureOpenAIResponsesAPIConfig(OpenAIResponsesAPIConfig):
|
|||
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
|
||||
|
|
@ -322,27 +324,8 @@ class AzureOpenAIResponsesAPIConfig(OpenAIResponsesAPIConfig):
|
|||
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 = {}
|
||||
|
|
|
|||
|
|
@ -337,6 +337,24 @@ class TestAzureResponsesAPIConfig:
|
|||
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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue