Skip to content

Commit

Permalink
feat: add STOP_WORDS (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamhunter2333 authored Apr 15, 2023
1 parent 607b4d7 commit 83ad1a6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 83ad1a6

Please sign in to comment.