Format Python code with psf/black push

github-actions 2 years ago
parent 06d6db0655
commit 0e87666617

@ -16,6 +16,7 @@ USER_INPUT_API_KEYS = EnvService.get_user_input_api_keys()
USER_KEY_DB = EnvService.get_api_db()
PRE_MODERATE = EnvService.get_premoderate()
class RedoSearchUser:
def __init__(self, ctx, query, search_scope, nodes):
self.ctx = ctx

@ -556,7 +556,6 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
if message.author == self.bot.user:
return
# Moderations service is done here.
if (
hasattr(message, "guild")
@ -580,7 +579,9 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
# Language check
if FORCE_ENGLISH and len(message.content.split(" ")) > 3:
if not await Moderation.force_english_and_respond(message.content, self.LANGUAGE_DETECT_STARTER_TEXT, message):
if not await Moderation.force_english_and_respond(
message.content, self.LANGUAGE_DETECT_STARTER_TEXT, message
):
await message.delete()
return
@ -1025,7 +1026,6 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
# Append the starter text for gpt3 to the user's history so it gets concatenated with the prompt later
if minimal or opener_file or opener:
self.conversation_threads[thread.id].history.append(
EmbeddedConversationItem(self.CONVERSATION_STARTER_TEXT_MINIMAL, 0)
)

@ -205,7 +205,7 @@ class Model:
)
print("Building language detector")
#self.detector = LanguageDetectorBuilder.from_languages(*Language.all()).build()
# self.detector = LanguageDetectorBuilder.from_languages(*Language.all()).build()
print("Language detector built")
def reset_settings(self):
@ -781,7 +781,9 @@ class Model:
prompt = f"{pretext}{text}\nOutput:"
max_tokens = Models.get_max_tokens(Models.DAVINCI) - self.usage_service.count_tokens(prompt)
max_tokens = Models.get_max_tokens(
Models.DAVINCI
) - self.usage_service.count_tokens(prompt)
print(f"Language detection request for {text}")
@ -791,11 +793,9 @@ class Model:
"prompt": prompt,
"temperature": 0,
"top_p": 1,
"max_tokens": max_tokens
}
headers = {
"Authorization": f"Bearer {self.openai_key}"
"max_tokens": max_tokens,
}
headers = {"Authorization": f"Bearer {self.openai_key}"}
async with session.post(
"https://api.openai.com/v1/completions", json=payload, headers=headers
) as resp:

@ -139,7 +139,7 @@ class Moderation:
@staticmethod
async def force_english_and_respond(text, pretext, ctx):
response = await model.send_language_detect_request(text, pretext)
response_text = response['choices'][0]['text']
response_text = response["choices"][0]["text"]
if "false" in response_text.lower().strip():
if isinstance(ctx, discord.Message):
@ -159,7 +159,14 @@ class Moderation:
response = await Moderation.simple_moderate(text)
print(response)
flagged = True if Moderation.determine_moderation_result(text, response, pre_mod_set, pre_mod_set) == ModerationResult.DELETE else False
flagged = (
True
if Moderation.determine_moderation_result(
text, response, pre_mod_set, pre_mod_set
)
== ModerationResult.DELETE
else False
)
if flagged:
if isinstance(ctx, discord.Message):

@ -263,7 +263,6 @@ class TextService:
await converser_cog.end_conversation(ctx)
return
# Send the request to the model
if from_edit_command:
response = await converser_cog.model.send_edit_request(
@ -538,7 +537,9 @@ class TextService:
if conversing:
# Pre-moderation check
if PRE_MODERATE:
if await Moderation.simple_moderate_and_respond(message.content, message):
if await Moderation.simple_moderate_and_respond(
message.content, message
):
await message.delete()
return

Loading…
Cancel
Save