chatgpt telegram bot
Posted on February 05, 2023 in tech • 3 min read
ChatGPT is the buzzword, and it is really good. I tried the playground a month ago and loved it.
For most it's a clever toy, for the ignorant it's just another bot, but for the tech industry it's a tipping point for AI. The model clearly shows how close machines are in communicating with humans without any help.
A huge step ahead towards Generative Artificial Intelligence.
OpenAI provides a ChatGPT playground to test out the bot however my major concern with the bot was there was no chat history and I need to go to a web client every time I wanted to use it.
Off with a new idea, build a telegram bot and use ChatGPT as the conversational backend!
I love telegram bots. I started working on them 2 years ago, during the COVID 19 pandemic. I had then wrote a telegram bot which can alert you (Indians) for vaccine availability. The bot was quite successful, I had close to 5000 users at the peak of the vaccination period. Since then I have been using telegram bots for lot of alerting needs, I have a bot which integrates with netdata monitoring system and alerts me on events with my 12 odd home and remote servers. Telegram bots are versatile, easy to build and best thing, knowledge of python is enough to build them. It took about a day to build the bot, but two more to understand the various models and parameters used in ChatGPT.
Try out the bot here and let me know what you think of it. The bot behaves almost the same as the online playground on web, however there are a few limitations as listed below.
- My bot uses the davinci 3 model, however the web version uses davinci 3.5. Version 3.5 is not yet available for general public usage over the API. Beyond my control to fix it.
- Emojis are not interpreted correctly as the ChatGPT model doesn't seem to respond in Unicode emoji format that Telegram uses. This is a low priority issue for me and I am not going to fix it.
- The bot does not understand contextual conversations. e.g. "What are we talking about?". If you ask this question on the web client it would tell you the topic of discussion, however the response on the bot would be incorrect. This is an issue with session handling. On the web client you login to use the bot, thus it keeps an in-memory track of the conversation, while the bot uses an API with no login session. With multiple users talking via the API there is no easy way to track the conversations. Again not a major concern for me and yes I won't fix it.
- I use a temperature setting of 0.9 (the highest) in the bots config file. That makes the responses more creative than the web client. It's a personal preference, so the bot would behave slightly different to the web client.
The bot is a written in pure python. It captures the users message and builds a payload with the message and the config parameters. It uses the OpenAI python module to deliver the payload to ChatGPT servers. The response is captured and delivered back by the bot. Pretty simple, infact the entire code base is just 97 lines of code with comments!
If you are interested do drop me an email will share the full code, sorry I don't write tutorials.