From b906fe0fd70f7f3b36127a4e843c232c597a7c5a Mon Sep 17 00:00:00 2001 From: Mohammad Amin Date: Thu, 18 Jan 2024 15:43:40 +0330 Subject: [PATCH] fix: the rabbitMQ couldn't handle sending objects! The celery is using rabbitMQ as its broker and it couldn't support the objects! --- celery_app/tasks.py | 14 ++++++++++---- worker.py | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/celery_app/tasks.py b/celery_app/tasks.py index 4af7d9a..c43e35c 100644 --- a/celery_app/tasks.py +++ b/celery_app/tasks.py @@ -23,7 +23,7 @@ def ask_question_auto_search( question: str, community_id: str, - bot_given_info: ChatInputCommandInteraction, + bot_given_info: dict[str, Any], ) -> None: """ this task is for the case that the user asks a question @@ -38,12 +38,15 @@ def ask_question_auto_search( the community that the question was asked in bot_given_info : tc_messageBroker.rabbit_mq.payload.discord_bot.chat_input_interaction.ChatInputCommandInteraction the information data that needed to be sent back to the bot again. - This would be the `ChatInputCommandInteraction`. + This would be a dictionary representing the keys + - `event` + - `date` + - `content`: which is the `ChatInputCommandInteraction` as a dictionary """ prefix = f"COMMUNITY_ID: {community_id} | " logging.info(f"{prefix}Processing question!") create_interaction_content = Payload.DISCORD_BOT.INTERACTION_RESPONSE.Create( - interaction=bot_given_info.to_dict(), + interaction=bot_given_info, data=InteractionResponse( type=4, data=InteractionCallbackData( @@ -77,8 +80,11 @@ def ask_question_auto_search( "source_nodes": source_nodes_dict, } + interaction = json.loads(bot_given_info["content"]["interaction"]) + chat_input_interaction = ChatInputCommandInteraction.from_dict(interaction) + response_payload = Payload.DISCORD_BOT.INTERACTION_RESPONSE.Edit( - interaction=bot_given_info.to_dict(), + interaction=chat_input_interaction, data=InteractionCallbackData(content=json.dumps(results)), ).to_dict() diff --git a/worker.py b/worker.py index d13fdf7..328a423 100644 --- a/worker.py +++ b/worker.py @@ -34,7 +34,7 @@ def query_llm(recieved_data: dict[str, Any]): ask_question_auto_search.delay( question=user_input, community_id=community_id, - bot_given_info=recieved_input, + bot_given_info=recieved_data, )