Check if a text contains at least one word from a list

Hello,

My app sends requests to the GPT-4 API, and to avoid conflicts with the usage policy, I’d like to check whether a text contains at least one element from a list before sending the request. If it does, I won’t send the request.

The text could be “Text to send to OpenAI’s API”, and the list of forbidden words could be: [“a”, “list”, “of”, “forbidden”, “words”, etc.]. What would be the simplest and most efficient way to do this? Both for storing the list of forbidden words and checking for the presence of a word (not in a backend workflow preferably).

Thank you in advance.

OpenAI has a moderations endpoint that’s i’ll tell you if a request is inappropriate, and it’s free :slight_smile:

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.