From eb79aaeee98461de3ccaa672cc2e3203633f1038 Mon Sep 17 00:00:00 2001 From: Luke R Date: Tue, 28 Jan 2025 12:30:07 -0800 Subject: [PATCH] Slice out the tags --- app/bot.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/bot.py b/app/bot.py index 10213d67..ae510ac0 100755 --- a/app/bot.py +++ b/app/bot.py @@ -118,6 +118,16 @@ async def fix_social_media_links(ctx): return +def remove_between(text, string1, string2): + start_index = text.find(string1) + end_index = text.find(string2, start_index + len(string1)) + + if start_index != -1 and end_index != -1: + return text[:start_index] + text[end_index + len(string2) :] + else: + return text # Return original text if delimiters not found + + @bot.event async def on_message(ctx): if str(bot.user.id) in ctx.content: @@ -170,11 +180,7 @@ async def on_message(ctx): response = requests.post(url, json=payload, headers=headers) answer = response.json()["message"]["content"] - if len(answer) > 2000: - await ctx.reply(answer[:2000].replace("<|end▁of▁sentence|>", "")) - await ctx.reply(answer[2000:].replace("<|end▁of▁sentence|>", "")) - else: - await ctx.reply(answer.replace("<|end▁of▁sentence|>", "")) + await ctx.reply(remove_between(answer, "", "")) except Exception as e: print(e) await ctx.reply("Somethings wrong, maybe the LLM crashed")