diff --git a/litellm/main.py b/litellm/main.py index ad2566252..57d596bf8 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -1266,6 +1266,22 @@ def text_completion(*args, **kwargs): kwargs.pop("prompt") return completion(*args, **kwargs) +##### Moderation ####################### +def moderation(*args, **kwargs): + # only supports open ai for now + api_key = None + if "api_key" in kwargs: + api_key = kwargs["api_key"] + + api_key = ( + api_key or + litellm.api_key or + litellm.openai_key or + get_secret("OPENAI_API_KEY") + ) + openai.api_key = api_key + response = openai.Moderation.create(*args, **kwargs) + return response ####### HELPER FUNCTIONS ################ ## Set verbose to true -> ```litellm.set_verbose = True``` diff --git a/litellm/tests/test_completion.py b/litellm/tests/test_completion.py index fca0e550b..f7393f5e5 100644 --- a/litellm/tests/test_completion.py +++ b/litellm/tests/test_completion.py @@ -812,3 +812,12 @@ def test_completion_ai21(): # return # test_completion_together_ai_stream() + +def test_moderation(): + response = litellm.moderation(input="i'm ishaan cto of litellm") + print(response) + output = response["results"][0] + print(output) + return output + +# test_moderation()