mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
fix azure foundry phi error
This commit is contained in:
parent
5626e7f9c0
commit
44ddb21887
1 changed files with 52 additions and 0 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import enum
|
||||||
from typing import Any, List, Optional, Tuple, cast
|
from typing import Any, List, Optional, Tuple, cast
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
@ -19,6 +20,10 @@ from litellm.types.utils import ModelResponse, ProviderField
|
||||||
from litellm.utils import _add_path_to_api_base, supports_tool_choice
|
from litellm.utils import _add_path_to_api_base, supports_tool_choice
|
||||||
|
|
||||||
|
|
||||||
|
class AzureFoundryErrorStrings(str, enum.Enum):
|
||||||
|
SET_EXTRA_PARAMETERS_TO_PASS_THROUGH = "Set extra-parameters to 'pass-through'"
|
||||||
|
|
||||||
|
|
||||||
class AzureAIStudioConfig(OpenAIConfig):
|
class AzureAIStudioConfig(OpenAIConfig):
|
||||||
def get_supported_openai_params(self, model: str) -> List:
|
def get_supported_openai_params(self, model: str) -> List:
|
||||||
model_supports_tool_choice = True # azure ai supports this by default
|
model_supports_tool_choice = True # azure ai supports this by default
|
||||||
|
@ -240,12 +245,18 @@ class AzureAIStudioConfig(OpenAIConfig):
|
||||||
) -> bool:
|
) -> bool:
|
||||||
should_drop_params = litellm_params.get("drop_params") or litellm.drop_params
|
should_drop_params = litellm_params.get("drop_params") or litellm.drop_params
|
||||||
error_text = e.response.text
|
error_text = e.response.text
|
||||||
|
|
||||||
if should_drop_params and "Extra inputs are not permitted" in error_text:
|
if should_drop_params and "Extra inputs are not permitted" in error_text:
|
||||||
return True
|
return True
|
||||||
elif (
|
elif (
|
||||||
"unknown field: parameter index is not a valid field" in error_text
|
"unknown field: parameter index is not a valid field" in error_text
|
||||||
): # remove index from tool calls
|
): # remove index from tool calls
|
||||||
return True
|
return True
|
||||||
|
elif (
|
||||||
|
AzureFoundryErrorStrings.SET_EXTRA_PARAMETERS_TO_PASS_THROUGH.value
|
||||||
|
in error_text
|
||||||
|
): # remove extra-parameters from tool calls
|
||||||
|
return True
|
||||||
return super().should_retry_llm_api_inside_llm_translation_on_http_error(
|
return super().should_retry_llm_api_inside_llm_translation_on_http_error(
|
||||||
e=e, litellm_params=litellm_params
|
e=e, litellm_params=litellm_params
|
||||||
)
|
)
|
||||||
|
@ -265,5 +276,46 @@ class AzureAIStudioConfig(OpenAIConfig):
|
||||||
litellm.remove_index_from_tool_calls(
|
litellm.remove_index_from_tool_calls(
|
||||||
messages=_messages,
|
messages=_messages,
|
||||||
)
|
)
|
||||||
|
elif (
|
||||||
|
AzureFoundryErrorStrings.SET_EXTRA_PARAMETERS_TO_PASS_THROUGH.value
|
||||||
|
in e.response.text
|
||||||
|
):
|
||||||
|
request_data = self._drop_extra_params_from_request_data(
|
||||||
|
request_data, e.response.text
|
||||||
|
)
|
||||||
data = drop_params_from_unprocessable_entity_error(e=e, data=request_data)
|
data = drop_params_from_unprocessable_entity_error(e=e, data=request_data)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def _drop_extra_params_from_request_data(
|
||||||
|
self, request_data: dict, error_text: str
|
||||||
|
) -> dict:
|
||||||
|
params_to_drop = self._extract_params_to_drop_from_error_text(error_text)
|
||||||
|
if params_to_drop:
|
||||||
|
for param in params_to_drop:
|
||||||
|
if param in request_data:
|
||||||
|
request_data.pop(param, None)
|
||||||
|
return request_data
|
||||||
|
|
||||||
|
def _extract_params_to_drop_from_error_text(
|
||||||
|
self, error_text: str
|
||||||
|
) -> Optional[List[str]]:
|
||||||
|
"""
|
||||||
|
Error text looks like this"
|
||||||
|
"Extra parameters ['stream_options', 'extra-parameters'] are not allowed when extra-parameters is not set or set to be 'error'.
|
||||||
|
"""
|
||||||
|
import re
|
||||||
|
|
||||||
|
# Extract parameters within square brackets
|
||||||
|
match = re.search(r"\[(.*?)\]", error_text)
|
||||||
|
if not match:
|
||||||
|
return []
|
||||||
|
|
||||||
|
# Parse the extracted string into a list of parameter names
|
||||||
|
params_str = match.group(1)
|
||||||
|
params = []
|
||||||
|
for param in params_str.split(","):
|
||||||
|
# Clean up the parameter name (remove quotes, spaces)
|
||||||
|
clean_param = param.strip().strip("'").strip('"')
|
||||||
|
if clean_param:
|
||||||
|
params.append(clean_param)
|
||||||
|
return params
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue