From 20082ee8bcd71f2c02f58d9d1b1f1a5b2c9e8969 Mon Sep 17 00:00:00 2001 From: Binay Mann <82080713+Binay-tech1608@users.noreply.github.com> Date: Mon, 26 Aug 2024 23:39:31 +0530 Subject: [PATCH] Update discord_app.py I have to implement multithreading in the application so that it can handle tasks concurrently. --- discord_app.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/discord_app.py b/discord_app.py index 02dd724..266c612 100644 --- a/discord_app.py +++ b/discord_app.py @@ -116,19 +116,35 @@ async def build_prompt_and_reply(executor, user_name, user_id): break prompt = await build_prompt(ppm, win_size=user_args["max-windows"]) + prompt = async build_prompt(ppm, win_size=user_args["max_windows"]) + if tgi_server_addr is None: response = await loop.run_in_executor(executor, gen_method, prompt, user_args) response = post.clean(response) else: response = await gen_method(prompt, user_args) + + threads = [] + import threading + def handle_request(request):] + response = f"**{model_name}** 💬\n{response.strip()}" + if len(response) >= max_response_length: + response = response[:max_response_length] + if other_job_on_progress is True: + await progress_msg.delete() + await msg.reply(response, mention_author=False) + except IndexError: + await msg.channel.send("Index error") + except HTTPException: + pass + pass + for request in requests: + t = threading.Thread(target=handle_request, args=(request,)) + t.start() + threads.append(t) - response = f"**{model_name}** 💬\n{response.strip()}" - if len(response) >= max_response_length: - response = response[:max_response_length] - - if other_job_on_progress is True: - await progress_msg.delete() - + for t in threads: + t.join() await msg.reply(response, mention_author=False) except IndexError: await msg.channel.send("Index error")