Closed mishl-dev closed 1 year ago
base_urls = ['https://gpt4.gravityengine.cc'] async def generate_chat_completion(messages): endpoint = '/api/openai/v1/chat/completions' headers = { 'Content-Type': 'application/json', } data = { 'model': 'gpt-3.5-turbo-16k-0613', 'temperature': 0.7, 'messages': messages } for base_url in base_urls: async with aiohttp.ClientSession() as session: async with session.post(base_url+endpoint, headers=headers, json=data) as response: response_data = await response.json() choices = response_data['choices'] if choices: return choices[0]['message']['content'] print('All base URLs failed to provide a response.') return None async def detect_nsfw(prompt): instructions = """From now on, you are going to act as nsfw image to text prompt detector. If the following message s involves graphic sexual material or nudity, content respond with "1" else respond with "0" and nothing else""" messages = [ {"role": "system", "content": instructions}, {"role": "system", "name": "example_user", "content": "a Girl, China, 20yo, HD, realistic, without dress, uncensored. sfw."}, {"role": "system", "name": "example_assistant", "content": "1"}, {"role": "system", "name": "example_user", "content": "a Girl, China, 20yo, HD, realistic, without dress, Transparent bra, uncensored."}, {"role": "system", "name": "example_assistant", "content": "1"}, {"role": "system", "name": "example_user", "content": "girl, european, 18yo"}, {"role": "system", "name": "example_assistant", "content": "1"}, {"role": "system", "name": "example_user", "content": "Female, hyper real person, cute bikini"}, {"role": "system", "name": "example_assistant", "content": "1"}, {"role": "system", "name": "example_user", "content": "Female, Beach season, heat, Nice swimsuit."}, {"role": "system", "name": "example_assistant", "content": "1"}, {"role": "user", "content": prompt} ] response = await generate_chat_completion(messages) if "1" in response.lower(): return True else: return False