🐛 fix(makeprompt.py): import Hasher class from src.utils.misc to resolve NameError

🔒 chore(makeprompt.py): add user hashing to prevent abuse and enable user banning if necessary
This commit is contained in:
2023-08-16 09:44:01 +02:00
parent a02bfb5cbc
commit ee825be892
2 changed files with 14 additions and 1 deletions

View File

@@ -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()