From 9f257b4126d10aeac3b4f8acb41b4848a0ec03b3 Mon Sep 17 00:00:00 2001 From: Paillat Date: Wed, 16 Aug 2023 09:26:03 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(makeprompt.py):=20import=20M?= =?UTF-8?q?oderationError=20from=20src.utils.misc=20to=20handle=20moderati?= =?UTF-8?q?on=20errors=20in=20chatgpt=5Fprocess=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐛 fix(makeprompt.py): raise ModerationError with message "Too many recursive messages" when answering recursively in chatgpt_process function --- src/makeprompt.py | 3 ++- src/utils/misc.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/makeprompt.py b/src/makeprompt.py index 2444861..b838536 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 +from src.utils.misc import moderate, ModerationError from src.utils.openaicaller import openai_caller from src.functionscalls import ( call_function, @@ -159,6 +159,7 @@ async def chatgpt_process( await message.channel.send( "Oh uh, it seems like i am answering recursively. I will stop now." ) + raise ModerationError("Too many recursive messages") await chatgpt_process( self, msgs, message, api_key, prompt, model, error_call, depth ) diff --git a/src/utils/misc.py b/src/utils/misc.py index 13f1aa9..7e16edd 100644 --- a/src/utils/misc.py +++ b/src/utils/misc.py @@ -9,3 +9,7 @@ async def moderate(api_key, text, recall_func=None): input=text, ) return response["results"][0]["flagged"] # type: ignore + + +class ModerationError(Exception): + pass