Building AdhkarAI - The Internals

Processes, Bottlenecks, Next Steps

ยท

6 min read

Building AdhkarAI - The Internals
๐Ÿ”Š
ADHKARAI IS NOW A SHAZAM FOR THE QURAN! - MORE ON THIS BELOW

As the curtains slowly drew to a close in the past year, one of my major resolutions as we ushered in the year 2023 was to build something worthwhile for the Muslim ummah with my software engineering skills. Amongst a small list of stuff I had in mind, AdhkarAI seemed like one that would require the minimum time and resources to realize. This article details the works behind the scenes (since March 2023) and the future I hope for AdhkarAI. But what even is AdhkarAI?

What Is AdhkarAI?

AdhkarAI is an AI-powered telegram chatbot that I built (still building) to serve as a digital companion for Muslims.

1.0

In its first iteration, I built this bot to provide Muslims with adhkars and Quran verses that align with how they are feeling or what they are experiencing. It's also the premise on which the name AdhkarAI came to be but I decided to keep it even when the capabilities of the bot had gone beyond the aforementioned scope.

The image above shows what a typical conversation with AdhkarAI v1.0 looked like, and while that's cool, there were some limitations. The bot didn't hold a chain of conversation (as it doesn't remember the last thing you asked it), and it also didn't answer general Islamic questions. With this, it quickly became clear that improvements needed to be made.

2.0

For the second iteration, I improved AdhkarAI to now have in-depth conversations with you about the verses of the Quran, the hadith and the sunnah of the Prophet Muhammad (S.A.W). You can also have conversations with the bot about Islamic history and geography and how it shapes Islamic practices today. Also, it can now remember the last 5 interactions (question + answer) that you have with it.

Shazam For Quran

The latest feature I have now added to AdhkarAI is the ability to shazam (audio-search) Quran verses. Simply send a voice note or short audio file of a Quran recitation and AdhkarAI will help you find the name of the Surah (chapter), the Arabic transliteration and the English translation of the verses, the theme of the Surah, where it was revealed to the Prophet (S.A.W) and the juz it falls under.

This feature was inspired by a conversation I had with a friend, but what actually pushed me to build it out was that I was scrolling through Twitter and saw this Quran recitation of Sheikh Noreen Muhammad Siddiq:

I had forgotten which surah this recitation was from and I didn't want to ask on Twitter or from anyone else, and that was the motivation I needed to build out the Quran audio-search feature. Below is a video demo of me using AdhkarAI to search for this tweet's recitation in the Quran:

I simply played the audio from my phone and sent it as a voice note to the bot and SHAZAM ๐Ÿ˜Ž! You can also send a pre-recorded audio file instead of a voice note.

I programmed the audio-search feature to extract only the first 30 seconds of any voice note or audio file of the recitation sent by a user. This is to prevent users from sending large audio files to the bot. Also, I believe that a 30-second (or less) recitation is enough data for AdhkarAI to work with.

I'm excited about this feature because I believe it is particularly game-changing for Muslims like me who haven't memorized the Quran. Sometimes, you randomly hear a recitation and you want more information on it but you can't unless you ask someone. I try to solve this problem for you with AdhkarAI's shazam feature โœจ.

Technologies Powering AdhkarAI

Telegram Bot API

I had to ask myself what would be the best user-facing technology for AdhkarAI. I had the option of a web and mobile app which is great but would have cost more time, financial and engineering resources to build. For the user, a mobile app would mean they need to download yet another app on their phone. They might need to update the app whenever there is a bug fix or feature update. To avoid this, I opted to layer AdhkarAI on top of Telegram (an existing chat application that most users already have on their phones) through the help of their Bot API. Ideally, I would have chosen WhatsApp for this but unlike the Telegram API, it isn't free to integrate.

LLMs

On the backend, AdhkarAI leverages a couple of OpenAI LLMs (Large Language Models) to power its knowledge base. Initially, I used the gpt-3.5-turbo model for chat completion but the issue with this model was that it prioritizes the user's prompt over the system role configuration I set for it. This means that it was answering questions outside the Islamic context it was meant for. For this reason, we switched to the gpt-4 model which will cost us approximately 25 times more than the cost of running on the gpt-3.5-turbo model, and that cost rises as more people use the service.

We use the whisper model for audio transcription which is also paid for. It is one of the services that power the Quran audio-search feature.

Render Cloud Service

For hosting, AdhkarAI lives on the Render cloud service. It was the most logical option due to its affordable cost and ease of use. I currently pay for two background workers ($7 monthly each). One to keep the bot socket running and the other to efficiently process user requests/actions. I also pay for a Postgres database service (also $7 monthly) for data persistence.

Keeping it Running

Running AdhkarAI costs some money which I have been solely responsible for covering. Hey, not that I am complaining ๐Ÿ˜„ as there isn't and never was any intention to monetize the bot. While the current running cost (a little less than 30 dollars monthly) is something that hasn't been difficult to bear (Alhamdulillah), it is important to note that it hinders AdhkarAI's growth. I have (with some intentionality) limited its usage to a handful of people (less than 500 with thousands of interactions) but I believe it's time for a larger audience to experience AdhkarAI. With that expansion, it will cost more to run and this is where I need your support (for Allah's sake) to keep the fire burning ๐Ÿ™๐Ÿพ. If you love what I'm doing with AdhkarAI and would love to aid financially, no matter how small, you can do so through the link below:

Next Steps

In the near future, I will be working on improving the Shazam feature to take video recitations and not just audio/voice notes. The reason for this is that users will have moments where the recitation they need to search for was screen recorded from their mobile phones (as they scroll through their social media pages). I want users to be able to send this screen recording directly to AdhkarAI and the bot will understand how to extract the audio from the video and still help them find the Surah and necessary details in the Quran.

Additionally, I have been looking at bringing AdhkarAI to WhatsApp (!) as it is the ultimate chat application but this will largely depend on how the donations come along. This is because available third-party APIs for WhatsApp integration cost money and they charge on a per-message basis.

It's been fun working on this over the last couple of months and the feedback has been exciting. If you have any suggestions or feedback for me about AdhkarAI, you can reach me on Twitter @mo_bello19 or via email: bellokeji19@gmail.com

If you'd like to give it a spin, then click on the link below:

Thank you for reading. Asalam Alaykum ๐Ÿ™๐Ÿพ