Chatbot which answers user questions based on data...
# 📖tutorials
w
When creating a bot, you might need to fetch data from the database to answer users’ questions. There are two ways to accomplish this. The first is to use a traditional database connection and run predefined SQL queries. This approach works as follows: a user asks a question, and somewhere in your code, you have logic that maps the user’s question to one of the predefined SQL queries. While this solution is relatively easy to implement and can be robust, it lacks flexibility, as there are many ways to ask for the same data. Covering all possible variations is impractical, given the sheer number of ways a user might phrase a question. The second approach is to use a “text-to-SQL” solution, where SQL queries are generated by AI based on the user’s question and the database schema. Using text-to-SQL adds flexibility, allowing users to ask an unlimited number of questions in any phrasing, which cannot be achieved with traditional hardcoded logic. In Botpress, I found a couple of integrations that allow connection to a database, but there was no existing text-to-SQL integration, so I decided to create my own and share it with the community. This integration is a lightweight wrapper around the SmartDBConnector API. To use it, you’ll need to create an account and obtain an API key. The code is available on GitHub, and I am also attaching a video on how to install it from the source code. I plan to publish it soon after testing with a small group of 8–10 users. Please get in touch with me in the comments below this post or send me a private message if you’re interested. I hope this integration will be of interest to some of you. Thanks and regards. Integration code in github https://github.com/smartdbconnector/botpress-sqlchat Quick demo on youtube

https://www.youtube.com/watch?v=8mcGtyrbbX4&t=2sâ–Ÿ

Text2SQL AP provider https://smartdbconnector.com/ https://cdn.discordapp.com/attachments/1306226843199995935/1306226844294582332/image.png?ex=6735e60c&is=6734948c&hm=13e4c3d39b3dbbddae9cc0e76e3e891b4dfbea9847eec84f9786a0580b613153& https://cdn.discordapp.com/attachments/1306226843199995935/1306226844629991424/image.png?ex=6735e60c&is=6734948c&hm=aa2b711158b3bbffa93e096f9d78151c4409eeee3b4640a3146f8dcd4d8ab04c&
b
How can I get test access to your service?
w
Hi @breezy-piano-23067 you can either install the integration from source code from github. You can find all instalation steps there, or just PM me and I will help you to get it sorted.
w
What’s the difference between: 1. Using this method 2. Connecting to Microsoft SQL Server (e.g., via integration) and providing the database schema within the prompt to the autonomous node?
w
Good question @wooden-student-97999 and you are right, you can implement the simplest version as following 1. make LLM call passing DB schema and getting back the SQL 2. Executing SQL on database and get results The advantage of using the smartdbconnector integration is that you get bunch of features out of the box 1. SQL repairing which means when an LLM generates a wrong query there will be multiple LLM calls to fix this query till it is correct or max tries limit is reached 2. History of requests users made 3. LLM learns from user history 4. on smartdbconnector website, you can provide LLM with sample queries which it uses to learn the details of your db 5. supporting context of previous questions asked 6. using different roles so every user can access to different tables based on his rold 7. you can use export to CSV [api is there but the integration doesn't cover it yet] 8. using multiple different sources not just db but excel, csv [this is work in progress]
The integration has been published and now available for everyone 🎉
18 Views