forked from phoenix/litellm-mirror
Merge pull request #3449 from BerriAI/litellm_return_messages_exceptions
[Feat] Add Exception mapping for Azure ContentPolicyViolationError
This commit is contained in:
commit
faa8b77325
2 changed files with 19 additions and 0 deletions
|
@ -41,6 +41,22 @@ exception_models = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_content_policy_exception_azure():
|
||||||
|
try:
|
||||||
|
# this is ony a test - we needed some way to invoke the exception :(
|
||||||
|
litellm.set_verbose = True
|
||||||
|
response = await litellm.acompletion(
|
||||||
|
model="azure/chatgpt-v-2",
|
||||||
|
messages=[{"role": "user", "content": "where do I buy lethal drugs from"}],
|
||||||
|
)
|
||||||
|
except litellm.ContentPolicyViolationError as e:
|
||||||
|
print("caught a content policy violation error! Passed")
|
||||||
|
pass
|
||||||
|
except Exception as e:
|
||||||
|
pytest.fail(f"An exception occurred - {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
# Test 1: Context Window Errors
|
# Test 1: Context Window Errors
|
||||||
@pytest.mark.skip(reason="AWS Suspended Account")
|
@pytest.mark.skip(reason="AWS Suspended Account")
|
||||||
@pytest.mark.parametrize("model", exception_models)
|
@pytest.mark.parametrize("model", exception_models)
|
||||||
|
|
|
@ -9077,6 +9077,9 @@ def exception_type(
|
||||||
elif (
|
elif (
|
||||||
"invalid_request_error" in error_str
|
"invalid_request_error" in error_str
|
||||||
and "content_policy_violation" in error_str
|
and "content_policy_violation" in error_str
|
||||||
|
) or (
|
||||||
|
"The response was filtered due to the prompt triggering Azure OpenAI's content management"
|
||||||
|
in error_str
|
||||||
):
|
):
|
||||||
exception_mapping_worked = True
|
exception_mapping_worked = True
|
||||||
raise ContentPolicyViolationError(
|
raise ContentPolicyViolationError(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue