From 83ad1a6636d92171a35bab5af5b2bdce7bd00d10 Mon Sep 17 00:00:00 2001 From: Dream Hunter Date: Sat, 15 Apr 2023 14:58:01 +0800 Subject: [PATCH] feat: add STOP_WORDS (#13) --- main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 1bc3d99..d28834e 100644 --- a/main.py +++ b/main.py @@ -33,7 +33,11 @@ level=logging.INFO ) _logger = logging.getLogger(__name__) -STOP_WORDS = ["忽略", "ignore"] +STOP_WORDS = [ + "忽略", "ignore", "指令", "命令", "command", "help", "帮助", "之前", + "幫助", "現在", "開始", "开始", "start", "restart", "重新开始", "重新開始", + "遵守", "遵循", "遵从", "遵從" +] def get_real_ipaddr(request: Request) -> str: @@ -76,7 +80,7 @@ async def chatgpt(request: Request, divination_body: DivinationBofy): _logger.info( f"Request from {get_real_ipaddr(request)}, prompt_type={divination_body.prompt_type}, prompt={divination_body.prompt}" ) - if any(w in divination_body.prompt for w in STOP_WORDS): + if any(w in divination_body.prompt.lower() for w in STOP_WORDS): raise HTTPException( status_code=403, detail="Prompt contains stop words"