forked from phoenix/litellm-mirror
add moderation
This commit is contained in:
parent
a86ec0f916
commit
d15d876b02
2 changed files with 25 additions and 0 deletions
|
@ -1266,6 +1266,22 @@ def text_completion(*args, **kwargs):
|
||||||
kwargs.pop("prompt")
|
kwargs.pop("prompt")
|
||||||
return completion(*args, **kwargs)
|
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 ################
|
####### HELPER FUNCTIONS ################
|
||||||
## Set verbose to true -> ```litellm.set_verbose = True```
|
## Set verbose to true -> ```litellm.set_verbose = True```
|
||||||
|
|
|
@ -812,3 +812,12 @@ def test_completion_ai21():
|
||||||
# return
|
# return
|
||||||
|
|
||||||
# test_completion_together_ai_stream()
|
# 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()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue