From f79bdd2086098f7562c5466c53c063543cf39a64 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 15 Aug 2023 14:15:35 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(makeprompt.py):=20import=20F?= =?UTF-8?q?untionCallError=20from=20src.functionscalls=20to=20fix=20NameEr?= =?UTF-8?q?ror=20=E2=9C=A8=20feat(makeprompt.py):=20add=20depth=20paramete?= =?UTF-8?q?r=20to=20chatgpt=5Fprocess=20function=20to=20limit=20recursive?= =?UTF-8?q?=20function=20calls=20and=20raise=20FuntionCallError=20if=20exc?= =?UTF-8?q?eeded?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/makeprompt.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/makeprompt.py b/src/makeprompt.py index adc90fa..67fd98f 100644 --- a/src/makeprompt.py +++ b/src/makeprompt.py @@ -8,7 +8,7 @@ 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.openaicaller import openai_caller -from src.functionscalls import call_function, functions, server_normal_channel_functions +from src.functionscalls import call_function, functions, server_normal_channel_functions, FuntionCallError async def replace_mentions(content, bot): @@ -117,7 +117,7 @@ async def prepare_messages(self, messages, message: discord.Message, api_key, pr return msgs -async def chatgpt_process(self, msgs, message: discord.Message, api_key, prompt, model): +async def chatgpt_process(self, msgs, message: discord.Message, api_key, prompt, model, depth=0): async def error_call(error=""): try: if error != "": @@ -155,6 +155,12 @@ async def chatgpt_process(self, msgs, message: discord.Message, api_key, prompt, "name": function_call.get("name"), } ) + depth += 1 + if depth > 2: + await message.channel.send( + "Oh uh, it seems like i am calling functions recursively. I will stop now." + ) + raise FuntionCallError("Too many recursive function calls") await chatgpt_process(self, msgs, message, api_key, prompt, model) else: content = response.get("content", "")