Skip to content

add specific exception for content policy #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kristapratico
Copy link
Owner

@kristapratico kristapratico commented Jun 7, 2023

Catching exception experience:

import openai

try:
    openai.Completion.create(
        prompt="How do I rob a bank?",
        deployment_id="text-davinci-003",
    )
except openai.error.InvalidRequestError as e:
    if e.error.code == "content_filter" and e.error.innererror:
        content_filter_result = e.error.innererror.content_filter_result

        for category, details in content_filter_result.items():
            print(f"{category}:\n filtered={details['filtered']}\n severity={details['severity']}")

vs.

try:
    openai.Completion.create(
        prompt="How do I rob a bank?",
        deployment_id="text-davinci-003",
    )
except openai.error.ContentPolicyError as e:
    for category, details in e.content_filter_result.items():
        print(f"{category}:\n filtered={details['filtered']}\n severity={details['severity']}")

Un-caught exception experience:

openai.error.InvalidRequestError: The response was filtered due to the prompt triggering Azure OpenAI’s content management policy. Please modify your prompt and retry. To learn more about our content filtering policies please read our documentation: https://go.microsoft.com/fwlink/?linkid=2198766

vs.

openai.error.ContentPolicyError: The response was filtered due to the prompt triggering Azure OpenAI’s content management policy. Please modify your prompt and retry. To learn more about our content filtering policies please read our documentation: https://go.microsoft.com/fwlink/?linkid=2198766
Inner error: {
    "code": "ResponsibleAIPolicyViolation",
    "content_filter_result": {
        "hate": {
            "filtered": false,
            "severity": "safe"
        },
        "self_harm": {
            "filtered": false,
            "severity": "safe"
        },
        "sexual": {
            "filtered": false,
            "severity": "safe"
        },
        "violence": {
            "filtered": true,
            "severity": "medium"
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant