Innovative SQL Reporting: Leveraging Gemini AI and ToolJet for Custom Reports

Published On Wed Jun 19 2024
Innovative SQL Reporting: Leveraging Gemini AI and ToolJet for Custom Reports

Building a SQL Report Generator using Gemini AI + ToolJet - DEV ...

This tutorial will guide you through the process of building an AI-driven SQL custom report generator using ToolJet, a low-code visual app builder, and the Gemini API, a powerful natural language processing API. The resulting application will enable users to input requests in plain English, which will then be translated into custom reports. We'll use ToolJet's visual app builder to create a user-friendly UI, and ToolJet's low-code query builder to connect it to the Gemini API endpoints and our data sources. The final product will enable users to preview generated reports and download them in PDF, Excel, or CSV formats.

Here is a quick preview of our final application: SQL Report Builder Preview

Setting Up the UI with ToolJet

Login to your ToolJet account. Navigate to the ToolJet dashboard and click on the Create new app button on the top left corner. ToolJet comes with 45+ built-in components. This will let us set up our UI in no time.

Aside from its built-in database and data sources, ToolJet allows you to connect to various external data sources, including databases, external APIs, and services. For this tutorial, we'll be using ToolJet's built-in PostgreSQL sample data source. The queries we'll set up will be applicable to an external PostgreSQL data source as well. We'll also be using the REST API query feature to connect with the Gemini API endpoints.

Now that we have successfully built our UI and queries, the next step is to integrate them. Select the Button component and navigate to the properties panel on the right. Click on the + New event handler button. Change the Action to Run query and select the getSqlQuery query.

Let's create a query that will connect to the Gemini AI API and generate our custom SQL report query. Using ToolJet's Workspace Constants feature, create a new constant named GEMINI_API_KEY with your Gemini API key. In the query panel, click on the + Add button and choose the REST API option. Rename the query to getSqlQuery.

Next, navigate to the getSqlQuery query and click on the + New event handler button. Change the Action to Run query and select the getReportData query. Select the Table component and enter the necessary data in the properties panel to display the report.

Creating Queries and Integrating with Gemini API

Test the application with the prompt: list the names of customers along with the products they have ordered, including the order date and the total quantity ordered for each product.

You can click on the + button on the Table footer to download the report in PDF, Excel, or CSV formats.

Congratulations on successfully building an AI-powered SQL report generator using ToolJet and the Gemini API. You can now input prompts in plain English and generate reports across multiple tables in your PostgreSQL instance.

To learn more about ToolJet, check out the ToolJet docs or connect with the community on Slack.