[Fix Azure AI Studio] drop_params_from_unprocessable_entity_error (#5936)

* fix drop_params_from_unprocessable_entity_error

* fix drop_params_from_unprocessable_entity_error for async azure ai requests

* fix extra body reading azure ai studio
This commit is contained in:
Ishaan Jaff 2024-09-27 07:58:52 -07:00 committed by GitHub
parent 9ec3365ba6
commit 93cf9abb88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 50 additions and 42 deletions

View file

@ -31,6 +31,7 @@ from litellm.utils import (
from ...types.llms.openai import *
from ..base import BaseLLM
from ..prompt_templates.factory import custom_prompt, prompt_factory
from .common_utils import drop_params_from_unprocessable_entity_error
class OpenAIError(Exception):
@ -831,27 +832,9 @@ class OpenAIChatCompletion(BaseLLM):
except openai.UnprocessableEntityError as e:
## check if body contains unprocessable params - related issue https://github.com/BerriAI/litellm/issues/4800
if litellm.drop_params is True or drop_params is True:
invalid_params: List[str] = []
if e.body is not None and isinstance(e.body, dict) and e.body.get("detail"): # type: ignore
detail = e.body.get("detail") # type: ignore
if (
isinstance(detail, List)
and len(detail) > 0
and isinstance(detail[0], dict)
):
for error_dict in detail:
if (
error_dict.get("loc")
and isinstance(error_dict.get("loc"), list)
and len(error_dict.get("loc")) == 2
):
invalid_params.append(error_dict["loc"][1])
new_data = {}
for k, v in optional_params.items():
if k not in invalid_params:
new_data[k] = v
optional_params = new_data
optional_params = drop_params_from_unprocessable_entity_error(
e, optional_params
)
else:
raise e
# e.message
@ -967,27 +950,7 @@ class OpenAIChatCompletion(BaseLLM):
except openai.UnprocessableEntityError as e:
## check if body contains unprocessable params - related issue https://github.com/BerriAI/litellm/issues/4800
if litellm.drop_params is True or drop_params is True:
invalid_params: List[str] = []
if e.body is not None and isinstance(e.body, dict) and e.body.get("detail"): # type: ignore
detail = e.body.get("detail") # type: ignore
if (
isinstance(detail, List)
and len(detail) > 0
and isinstance(detail[0], dict)
):
for error_dict in detail:
if (
error_dict.get("loc")
and isinstance(error_dict.get("loc"), list)
and len(error_dict.get("loc")) == 2
):
invalid_params.append(error_dict["loc"][1])
new_data = {}
for k, v in data.items():
if k not in invalid_params:
new_data[k] = v
data = new_data
data = drop_params_from_unprocessable_entity_error(e, data)
else:
raise e
# e.message