nova-api/api/moderation.py

19 lines
379 B
Python
Raw Normal View History

2023-08-04 03:30:56 +02:00
import os
import asyncio
import openai as closedai
from typing import Union
from dotenv import load_dotenv
load_dotenv()
closedai.api_key = os.getenv('LEGIT_CLOSEDAI_KEY')
async def is_safe(text: Union[str, list]) -> bool:
return closedai.Moderation.create(
input=text,
)['results'][0]['flagged']
if __name__ == '__main__':
asyncio.run(is_safe('Hello'))