diff --git a/src/makeprompt.py b/src/makeprompt.py index 3c02391..c726793 100644 --- a/src/makeprompt.py +++ b/src/makeprompt.py @@ -6,7 +6,7 @@ import datetime import json from src.config import curs_data, max_uses, curs_premium, gpt_3_5_turbo_prompt -from src.utils.misc import moderate, ModerationError +from src.utils.misc import moderate, ModerationError, Hasher from src.utils.openaicaller import openai_caller from src.functionscalls import ( call_function, @@ -131,6 +131,7 @@ async def chatgpt_process( messages=msgs, functions=called_functions, function_call="auto", + user=Hasher(str(message.author.id)), #for user banning in case of abuse ) response = response["choices"][0]["message"] # type: ignore if response.get("function_call"): diff --git a/src/utils/misc.py b/src/utils/misc.py index 7e16edd..bdb5a75 100644 --- a/src/utils/misc.py +++ b/src/utils/misc.py @@ -1,3 +1,5 @@ +import hashlib + from src.utils.openaicaller import openai_caller @@ -13,3 +15,13 @@ async def moderate(api_key, text, recall_func=None): class ModerationError(Exception): pass + +class hasher: + def __init__(self): + self.hashes = {} + def __call__(self, text: str) -> str: + if self.hashes.get(text, None) is None: + self.hashes[text] = hashlib.sha256(text.encode()).hexdigest() + return self.hashes[text] + +Hasher = hasher() \ No newline at end of file