hibobmaster / matrix_chatgpt_bot

A simple matrix bot that supports image generation and chatting using ChatGPT, Langchain
https://matrix.to/#/#public:matrix.qqs.tw
MIT License
75 stars 13 forks source link

feature request: bot message limit warning message #52

Closed seshubonam closed 1 month ago

seshubonam commented 1 month ago

Hi, we have used this matrix bot in a chat application. Where, users can use publicly available ai bot for upto 10 messages and post this, it will send a message to user about "10 message limit reached, resume in 1 hour or add your own API key"

We tried to implement this but ran into issues where the bot stopped responding after message limit is reached.

More context of our implementation: User can add own API key by using a !key command. but in our implementation, after the 10 message warning the bot stops to respond.

Any ideas how we could implement this?

thanks !

hibobmaster commented 1 month ago

after the 10 message warning the bot stops to respond

Can you tell me how you guy implement message limit.

f1delius commented 1 month ago

We implemented it using simple dict as it resets every 3 hours,it triggers the condition just doesn't send the message.

https://github.com/pixxels-team/matrix_chatgpt_bot/blob/93456a21c2a6e3f67b38f8b13f08c9444a297cfe/src/bot.py#L187-L198

seshubonam commented 1 month ago

the required flow is:.

after 10 messages are sent by the ai/bot it should send a message that 10 message limit has exceeded ,

at present it doesnt send the message

and it works after set time limit (3 hours in our case) is over.

hibobmaster commented 1 month ago

it triggers the condition just doesn't send the message.

I recommend creating a breakpoint here and then step into to see what happen in details. https://github.com/pixxels-team/matrix_chatgpt_bot/blob/93456a21c2a6e3f67b38f8b13f08c9444a297cfe/src/bot.py#L189

Besides, i guess this function will only execute once. https://github.com/pixxels-team/matrix_chatgpt_bot/blob/93456a21c2a6e3f67b38f8b13f08c9444a297cfe/src/main.py#L91-L95 https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.call_later

To make thing easier, you can use apschuduler library: https://apscheduler.readthedocs.io/en/3.x/ Create a background scheduler when matrix bot iniitialize.

seshubonam commented 1 month ago

will try this. thanks

seshubonam commented 1 month ago

took all week to solve this. but your suggestion helped 🔥 thanks. the dev also found a solution but he finally implemented yours.