Skip to content

Commit

Permalink
Merge pull request #14 from alkem-io/main
Browse files Browse the repository at this point in the history
Sync dev with main
  • Loading branch information
valentinyanakiev authored May 21, 2024
2 parents ebd9589 + e3c8779 commit dacc906
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions virtual_contributor_engine_expert.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ async def connect(self):
await self.channel.declare_queue(self.queue, auto_delete=False)


logger.info(config)
rabbitmq = RabbitMQ(
host=config["rabbitmq_host"],
login=config["rabbitmq_user"],
Expand All @@ -61,8 +60,7 @@ async def query(user_id, message_body, language_code):
r"\[@.*\d\d\)", "", message_body["question"]
).strip()

logger.info(
f"\nQuery from user {user_id}: {message_body['question']}\n")
logger.info(f"\nQuery from user {user_id}: {message_body['question']}\n")

if user_id not in user_data:
user_data[user_id] = {}
Expand Down Expand Up @@ -90,7 +88,7 @@ async def query(user_id, message_body, language_code):
doc["type"].replace("_", " ").lower().capitalize(),
doc["title"],
),
"url": doc["source"],
"uri": doc["source"],
}
for doc in llm_result["source_documents"]
]
Expand All @@ -108,8 +106,7 @@ async def query(user_id, message_body, language_code):
user_data[user_id]["chat_history"].save_context(
{"question": message_body["question"]}, {"answer": answer.content}
)
logger.debug(
f"new chat history {user_data[user_id]['chat_history']}\n")
logger.debug(f"new chat history {user_data[user_id]['chat_history']}\n")
response = json.dumps(
{
"question": message_body["question"],
Expand Down Expand Up @@ -151,8 +148,7 @@ async def on_request(message: aio_pika.abc.AbstractIncomingMessage):
f"existing task running for user id: {user_id}, waiting for it to finish first\n\n"
)
else:
logger.info(
f"no task running for user id: {user_id}, let's move!\n\n")
logger.info(f"no task running for user id: {user_id}, let's move!\n\n")

# Acquire the lock for this user
async with user_locks[user_id]:
Expand Down Expand Up @@ -202,17 +198,15 @@ async def process_message(message: aio_pika.abc.AbstractIncomingMessage):
),
routing_key=message.reply_to or "",
)
logger.info(
f"Response sent for correlation_id: {message.correlation_id}")
logger.info(f"Response sent for correlation_id: {message.correlation_id}")
logger.info(f"Response sent to: {message.reply_to}")
logger.debug(f"response: {response}")
except (
aio_pika.exceptions.AMQPError,
asyncio.exceptions.CancelledError,
aiormq.exceptions.ChannelInvalidStateError,
) as e:
logger.error(
f"Failed to publish message due to a RabbitMQ error: {e}")
logger.error(f"Failed to publish message due to a RabbitMQ error: {e}")


async def main():
Expand Down

0 comments on commit dacc906

Please sign in to comment.