mirror of
https://github.com/Paillat-dev/Botator.git
synced 2026-01-02 01:06:19 +00:00
🐛 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:
@@ -6,7 +6,7 @@ import datetime
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from src.config import curs_data, max_uses, curs_premium, gpt_3_5_turbo_prompt
|
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.utils.openaicaller import openai_caller
|
||||||
from src.functionscalls import (
|
from src.functionscalls import (
|
||||||
call_function,
|
call_function,
|
||||||
@@ -131,6 +131,7 @@ async def chatgpt_process(
|
|||||||
messages=msgs,
|
messages=msgs,
|
||||||
functions=called_functions,
|
functions=called_functions,
|
||||||
function_call="auto",
|
function_call="auto",
|
||||||
|
user=Hasher(str(message.author.id)), #for user banning in case of abuse
|
||||||
)
|
)
|
||||||
response = response["choices"][0]["message"] # type: ignore
|
response = response["choices"][0]["message"] # type: ignore
|
||||||
if response.get("function_call"):
|
if response.get("function_call"):
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import hashlib
|
||||||
|
|
||||||
from src.utils.openaicaller import openai_caller
|
from src.utils.openaicaller import openai_caller
|
||||||
|
|
||||||
|
|
||||||
@@ -13,3 +15,13 @@ async def moderate(api_key, text, recall_func=None):
|
|||||||
|
|
||||||
class ModerationError(Exception):
|
class ModerationError(Exception):
|
||||||
pass
|
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()
|
||||||
Reference in New Issue
Block a user