When sending a message to a chat via GetChatCompletions as a response, I get a RequestFailedException. In the exception, I get an answer for which category content filter triggered, but nothing for how many tokens were used.
So my questions is: Do messages or responses that triggered the Content Filter not use tokens? If they do use tokens, how many are they using, and where can I get this information? Is the Azure OpenAI Service using Content Safety?
I tried to parse the message from the exception, but it just doesn't have that kind of information.
To send a request to the OpenAI API to check whether a given message is likely to trigger the Content Filter.
Here is the code:
Output
Message: "The message did not trigger the Content Filter," it means that the content filter did not detect any issues with the provided message, and the message is considered safe.
When you use a message like Senstive Information, the content filter is likely to trigger, and the code will then report the number of tokens used.
Answer you questions
Yes, messages or responses that triggered the Content Filter will still use tokens. For example, a simple message like "This is a message that is likely to trigger the Content Filter." will use fewer tokens than a more complex message like "I am writing a blog post about the OpenAI Content Filter and I am wondering if you can provide me with more information about how it works."
To get the number of tokens used in a message, you can use the
GetContentFilteredMessageTokenUsage
. This Method will calculate the number of tokens used in the message by splitting the message content on whitespace.Yes, the Azure OpenAI Service is using Content Safety. Please refer to this Azure AI Content Safety MSDoc