<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aman Regu</title>
    <description>The latest articles on DEV Community by Aman Regu (@amanregu).</description>
    <link>https://dev.to/amanregu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1431340%2F22f5c924-a697-47a7-a958-9bd4036a0c55.jpeg</url>
      <title>DEV Community: Aman Regu</title>
      <link>https://dev.to/amanregu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amanregu"/>
    <language>en</language>
    <item>
      <title>Building a Regex Generator with Gemini AI and ToolJet ⚙️</title>
      <dc:creator>Aman Regu</dc:creator>
      <pubDate>Tue, 02 Jul 2024 13:02:20 +0000</pubDate>
      <link>https://dev.to/tooljet/building-a-regex-generator-with-gemini-ai-and-tooljet-43ng</link>
      <guid>https://dev.to/tooljet/building-a-regex-generator-with-gemini-ai-and-tooljet-43ng</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This tutorial will guide you through the process of building an AI-powered Regex Generator using &lt;a href="https://github.com/ToolJet/ToolJet" rel="noopener noreferrer"&gt;ToolJet&lt;/a&gt; , 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 Regular Expressions (Regex). 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 endpoint.&lt;/p&gt;




&lt;h2&gt;
  
  
  Prerequisites:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ToolJet&lt;/strong&gt; (&lt;a href="https://github.com/ToolJet/ToolJet" rel="noopener noreferrer"&gt;https://github.com/ToolJet/ToolJet&lt;/a&gt; ): An open-source, low-code business application builder. &lt;a href="https://www.tooljet.com/signup" rel="noopener noreferrer"&gt;Sign up&lt;/a&gt; for a free ToolJet cloud account or &lt;a href="https://docs.tooljet.com/docs/setup/try-tooljet/" rel="noopener noreferrer"&gt;run ToolJet on your local machine&lt;/a&gt; using Docker.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gemini API Key&lt;/strong&gt; : Log into &lt;a href="https://aistudio.google.com/app/apikey" rel="noopener noreferrer"&gt;Google AI Studio&lt;/a&gt; using your existing Google credentials. Within the AI Studio interface, you can locate and copy your API key.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is a quick preview of our final application:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0i4mm3nmx59f29efkj7z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0i4mm3nmx59f29efkj7z.png" alt=" " width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Login to your &lt;a href="https://app.tooljet.com/" rel="noopener noreferrer"&gt;ToolJet account&lt;/a&gt;. 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.&lt;/p&gt;




&lt;h2&gt;
  
  
  Assembling our UI
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Drag and drop the &lt;strong&gt;Container&lt;/strong&gt; component onto the canvas from the component library on the right side. Adjust the height and width of the &lt;strong&gt;Container&lt;/strong&gt; component appropriately.&lt;/li&gt;
&lt;li&gt;Similarly, drag-and-drop the &lt;strong&gt;Icon&lt;/strong&gt; and &lt;strong&gt;Text&lt;/strong&gt; component onto the canvas. We'll use them as our header.&lt;/li&gt;
&lt;li&gt;For the &lt;strong&gt;Icon&lt;/strong&gt; component, navigate to the properties panel on the right and select the appropriate icon under the &lt;strong&gt;Icon&lt;/strong&gt; property.&lt;/li&gt;
&lt;li&gt;Change the colour of the &lt;strong&gt;Icon&lt;/strong&gt; and &lt;strong&gt;Text&lt;/strong&gt; component according to your preference.&lt;/li&gt;
&lt;li&gt;Drag and drop one &lt;strong&gt;Text&lt;/strong&gt; component and one  &lt;strong&gt;Textarea&lt;/strong&gt; component inside your canvas. We'll use these components for the label and input for our text query. Rename the &lt;strong&gt;Textarea&lt;/strong&gt; component to &lt;em&gt;textQueryInput&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Again, drag-and-drop two &lt;strong&gt;Text&lt;/strong&gt; components and two &lt;strong&gt;Text Input&lt;/strong&gt; components inside your container. We'll use them for displaying the generated regex expressions and testing a string against the generated regex expression respectively.&lt;/li&gt;
&lt;li&gt;Rename the &lt;strong&gt;Text Input&lt;/strong&gt; components as &lt;em&gt;generatedRegex&lt;/em&gt; and &lt;em&gt;testString&lt;/em&gt; respectively.&lt;/li&gt;
&lt;li&gt;Lastly, drag and drop two &lt;strong&gt;Button&lt;/strong&gt; components inside your container. We'll use them for initiating the regex expression generation and adding a &lt;strong&gt;copy to clipboard&lt;/strong&gt; functionality respectively.&lt;/li&gt;
&lt;li&gt;Rename the added &lt;strong&gt;Button&lt;/strong&gt; components to &lt;em&gt;generateRegex&lt;/em&gt; and &lt;em&gt;copyToClipboard&lt;/em&gt; respectively.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frulz6yc960geeqvosxwq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frulz6yc960geeqvosxwq.png" alt=" " width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Setting up Queries
&lt;/h2&gt;

&lt;p&gt;ToolJet allows you to connect to various external data sources, including databases, external APIs, and services using its powerful low code query builder. For this tutorial, We'll be using the REST API query feature to connect with the &lt;strong&gt;Gemini&lt;/strong&gt; API endpoints.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using ToolJet's Workspace Constants feature, create a new constant named &lt;strong&gt;GEMINI_API_KEY&lt;/strong&gt; with your Gemini API key.&lt;/li&gt;
&lt;li&gt;In the query panel, click on the &lt;strong&gt;+ Add&lt;/strong&gt; button and choose the &lt;strong&gt;REST API&lt;/strong&gt; option.&lt;/li&gt;
&lt;li&gt;Rename the query to &lt;em&gt;getRegexPattern.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;In the Request parameter, choose &lt;strong&gt;POST&lt;/strong&gt; as the Method from the drop-down and paste the following URL.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent?key={{constants.GEMINI_API_KEY}}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Navigate to the Body section of &lt;em&gt;getRegexPattern&lt;/em&gt;. Toggle on &lt;strong&gt;Raw JSON&lt;/strong&gt; and enter the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{
  `{
   "contents": [{
     "parts": [{
       "text": "Text Prompt: Based on pattern, generate a regex without any code highlighting, formatting or backticks, Pattern: ${JSON.stringify(components.textQueryInput.value).replace(/\\?"/g, '\\"')}"
      },],
    },],
  }`
}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Binding Queries to the UI Components
&lt;/h2&gt;

&lt;p&gt;Now that we have successfully added our UI and the query, the next step is to integrate them.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select the &lt;em&gt;generateRegex&lt;/em&gt; &lt;strong&gt;Button&lt;/strong&gt; component and navigate to the properties panel on the right. Click on the &lt;strong&gt;+ New event handler&lt;/strong&gt; button. Change the &lt;strong&gt;Action&lt;/strong&gt; to &lt;strong&gt;Run query&lt;/strong&gt; and select the &lt;em&gt;getRegexPattern&lt;/em&gt; query. This will trigger the &lt;em&gt;getRegexPattern&lt;/em&gt; every time we click the &lt;em&gt;generateRegex&lt;/em&gt; button.&lt;/li&gt;
&lt;li&gt;Next, select the &lt;em&gt;generatedRegex&lt;/em&gt; &lt;strong&gt;Text Input&lt;/strong&gt; component and navigate to the properties panel on the right. Paste the following code into the &lt;strong&gt;Default value&lt;/strong&gt; field:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{queries.getRegexPattern.data.candidates[0].content.parts[0].text.trim()}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Select the &lt;em&gt;copyToClipboard&lt;/em&gt; &lt;strong&gt;Button&lt;/strong&gt; component and navigate to the properties panel on the right. Click on the &lt;strong&gt;+ New event handler&lt;/strong&gt; button. Change the &lt;strong&gt;Action&lt;/strong&gt; to &lt;strong&gt;Copy to clipboard&lt;/strong&gt;. Paste the following code in the Text field under the Action Options subsection:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{components.generatedRegex.value}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Similarly, select the &lt;em&gt;testString&lt;/em&gt; &lt;strong&gt;Text Input&lt;/strong&gt; component and navigate to the properties panel on the right. Paste the following code in the Regex field under the Validation subsection:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{queries.getRegexPattern.data.candidates[0].content.parts[0].text.trim()}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have successfully integrated everything together. Now let's test the application with the text query below:&lt;br&gt;
&lt;em&gt;Match any string that is at least 8 characters long, contains at least one lowercase letter, one uppercase letter, and one number&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fasm1eie2ygtxq2ikektt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fasm1eie2ygtxq2ikektt.png" alt=" " width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Congratulations on successfully creating an AI-powered Regex generator with ToolJet and the Gemini API. You can now input natural language prompts to generate Regular Expressions effortlessly.&lt;/p&gt;

&lt;p&gt;To learn and explore more about ToolJet, check out the &lt;a href="https://docs.tooljet.com/docs/" rel="noopener noreferrer"&gt;ToolJet docs&lt;/a&gt; or connect with us and post your queries on &lt;a href="https://join.slack.com/t/tooljet/shared_invite/zt-2ij7t3rzo-qV7WTUTyDVQkwVxTlpxQqw" rel="noopener noreferrer"&gt;Slack&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Building a Mock Data Generator with Google Sheets, Gemini AI &amp; ToolJet ⚙️</title>
      <dc:creator>Aman Regu</dc:creator>
      <pubDate>Tue, 25 Jun 2024 13:33:12 +0000</pubDate>
      <link>https://dev.to/tooljet/building-a-mock-data-generator-with-google-sheets-gemini-ai-tooljet-24f2</link>
      <guid>https://dev.to/tooljet/building-a-mock-data-generator-with-google-sheets-gemini-ai-tooljet-24f2</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This tutorial will guide you through the process of building an AI-driven Mock Data Generator using &lt;a href="https://github.com/ToolJet/ToolJet" rel="noopener noreferrer"&gt;ToolJet&lt;/a&gt;, a low-code visual app builder, and the Gemini API, a powerful natural language processing API. We'll also use ToolJet's build-in integration with Google Sheets to store our mock data. The resulting application will enable users to generate mock data based on the sample format data present in the spreadsheet. 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 Google Sheets data source.&lt;/p&gt;




&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ToolJet&lt;/strong&gt;(&lt;a href="https://github.com/ToolJet/ToolJet" rel="noopener noreferrer"&gt;https://github.com/ToolJet/ToolJet&lt;/a&gt;) : An open-source, low-code business application builder. &lt;a href="https://www.tooljet.com/signup" rel="noopener noreferrer"&gt;Sign up&lt;/a&gt; for a free ToolJet cloud account or &lt;a href="https://docs.tooljet.com/docs/setup/try-tooljet/" rel="noopener noreferrer"&gt;run ToolJet on your local machine&lt;/a&gt; using Docker.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gemini API Key&lt;/strong&gt; : The Gemini API is an advanced AI service provided by &lt;a href="https://aistudio.google.com/app/apikey" rel="noopener noreferrer"&gt;Google AI Studio&lt;/a&gt;. It enables developers to integrate powerful content generation capabilities into their applications.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Google account with access to Google Sheets&lt;/strong&gt;: Log into Google Sheets using your Google account and create a new spreadsheet. Add column names to define the structure of your data. Additionally, you can create at least one row of data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is a quick preview of our final application:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy4m7a4r6dnegk1jv9v4a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy4m7a4r6dnegk1jv9v4a.png" alt=" " width="800" height="453"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 1: Prepare your Google Sheets Document
&lt;/h2&gt;

&lt;p&gt;We will be starting this tutorial by setting up the Google Sheets document with the following data.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft7yoxcewyjsuqkm2m7n3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft7yoxcewyjsuqkm2m7n3.png" alt=" " width="800" height="181"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 2: Connecting Google Sheets to ToolJet
&lt;/h2&gt;

&lt;p&gt;Once the spreadsheet is ready, let’s connect our &lt;strong&gt;Google Sheet&lt;/strong&gt; to &lt;strong&gt;ToolJet&lt;/strong&gt;. Follow the steps mentioned below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On the ToolJet dashboard, locate the &lt;strong&gt;Data Sources&lt;/strong&gt; section on the left sidebar. Click on the &lt;strong&gt;+Add&lt;/strong&gt; button under the Google Sheets plugin.&lt;/li&gt;
&lt;li&gt;Choose the &lt;strong&gt;Read and write&lt;/strong&gt; option since we will be adding the mock data to our Google Sheet.&lt;/li&gt;
&lt;li&gt;Once you click on &lt;strong&gt;Connect Data source&lt;/strong&gt;, you will be redirected to grant access to ToolJet to your Google Sheets; grant the access and click &lt;strong&gt;Save data source&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Now that you have successfully connected Google Sheets to your ToolJet account, click the &lt;strong&gt;Apps&lt;/strong&gt; icon on the left sidebar and select &lt;strong&gt;Create an app&lt;/strong&gt;. Let’s name our app &lt;em&gt;Mock Data Generator&lt;/em&gt;.
Now that we’ve set up our App, it’s time to create the UI.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Step 3: Building the UI
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Drag and drop the &lt;strong&gt;Container&lt;/strong&gt; component onto the canvas from the component library on the right side. Adjust the height and width of the Container component appropriately.&lt;/li&gt;
&lt;li&gt;Similarly, drag and drop the &lt;strong&gt;Icon&lt;/strong&gt; and the &lt;strong&gt;Text&lt;/strong&gt; component onto your canvas. We'll use them as our logo and header.&lt;/li&gt;
&lt;li&gt;For the &lt;strong&gt;Icon&lt;/strong&gt; component, navigate to the properties panel on the right and select the appropriate icon under the &lt;strong&gt;Icon&lt;/strong&gt; property.&lt;/li&gt;
&lt;li&gt;Change the color of the Icon and Text component according to your preference.&lt;/li&gt;
&lt;li&gt;Drag and drop the &lt;strong&gt;Dropdown&lt;/strong&gt; component inside your container. We'll use this dropdown to choose between the available sheets. Rename this component to &lt;em&gt;selectSheet&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Similarly, drag and drop two &lt;strong&gt;Button&lt;/strong&gt; components inside the container. We'll use these buttons for generating mock data and saving the data to the Google Sheet.&lt;/li&gt;
&lt;li&gt;Next, add a &lt;strong&gt;Table&lt;/strong&gt; Component to display the generated mock data.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwy3ubx5ota81yl4qzrce.png" alt=" " width="800" height="453"&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Step 4: Setting up Queries
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Fetching the Sheets
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Expand the &lt;strong&gt;Query Panel&lt;/strong&gt; at the bottom and click the &lt;strong&gt;Add&lt;/strong&gt; button to create a query - rename this query to &lt;em&gt;getSheets&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Choose Data Source as &lt;strong&gt;googlesheets&lt;/strong&gt;, and &lt;strong&gt;Operation&lt;/strong&gt; as &lt;strong&gt;Get spreadsheet info&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Spreadsheet ID&lt;/strong&gt; section, enter the spreadsheet ID of your sheet. To access the spreadsheet ID, check your Google Sheet's URL, the format should be: &lt;code&gt;https://docs.google.com/spreadsheets/d/&amp;lt;SPREADHEET_ID&amp;gt;/edit#gid=0&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;To ensure that this query runs every time the application loads, toggle &lt;strong&gt;Run this query on application load?&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Enable the &lt;strong&gt;Transformations&lt;/strong&gt; toggle and enter the following code:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return data.sheets.map(item =&amp;gt; item.properties.title);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will return all the sheet names in an Array. We'll use this to populate the values in our dropdown component.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Fetching initial sample data
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Similarly, create another query and rename it to &lt;em&gt;getInitialData&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Choose the &lt;strong&gt;Operation&lt;/strong&gt; as &lt;strong&gt;Read data from a spreadsheet&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Enter the following code in the &lt;strong&gt;Sheet&lt;/strong&gt; field:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{components.selectSheet.value}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Generating Mock Data using Gemini API
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Using ToolJet's &lt;a href="https://docs.tooljet.com/docs/org-management/workspaces/workspace_constants/" rel="noopener noreferrer"&gt;Workspace Constants&lt;/a&gt; feature, create a new constant named &lt;code&gt;GEMINI_API_KEY&lt;/code&gt; with your Gemini API key.&lt;/li&gt;
&lt;li&gt;In the query panel, click on the &lt;strong&gt;+ Add **button and choose the **REST API&lt;/strong&gt; option.
Rename the query to &lt;em&gt;generateMockData&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;In the Request parameter, choose &lt;strong&gt;POST&lt;/strong&gt; as the &lt;strong&gt;Method&lt;/strong&gt; from the drop-down and paste the following URL.
&lt;code&gt;https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent?key={{constants.GEMINI_API_KEY}}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Navigate to the &lt;strong&gt;Body&lt;/strong&gt; section of &lt;em&gt;getSqlQuery&lt;/em&gt;. Toggle on Raw JSON and enter the following code:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; {{
  `{
   "contents": [{
     "parts": [{
       "text": "Sample Data: ${JSON.stringify(queries.getInitialData.data[0]).replace(/\\?"/g, '\\"')}, Text Prompt: Based on the sample data, only return an Array with 10 objects with same type of mock data without any code highlighting, formatting or backticks"
      },],
    },],
  }`
}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Inserting data into our Google Sheet
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Create another query and choose Data Source as googlesheets, and &lt;strong&gt;Operation&lt;/strong&gt; as &lt;strong&gt;Append data to a spreadsheet&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Enter the following code in the Sheet field:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{components.selectSheet.value}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Enter the following code in the Rows field:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{JSON.parse(queries.generateMockData.data.candidates[0].content.parts[0].text)}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 5: Binding Queries to the UI Components
&lt;/h2&gt;

&lt;p&gt;Now that we have successfully built our UI and queries, the next step is to integrate them.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select the Dropdown component, under the Properties section, and enter the following code for both &lt;strong&gt;Option values&lt;/strong&gt; and &lt;strong&gt;labels&lt;/strong&gt; fields:
&lt;code&gt;{{queries.getSheets.data}}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Select the &lt;em&gt;Generate Data Button&lt;/em&gt; component, under the Properties section, click the &lt;strong&gt;New event handler&lt;/strong&gt; button to create a new event.&lt;/li&gt;
&lt;li&gt;Choose &lt;strong&gt;On click&lt;/strong&gt; as the &lt;strong&gt;Event&lt;/strong&gt;, &lt;strong&gt;Run Query&lt;/strong&gt; as the &lt;strong&gt;Action&lt;/strong&gt;, and select &lt;em&gt;getInitialData&lt;/em&gt; as the Query.&lt;/li&gt;
&lt;li&gt;Select the &lt;em&gt;getInitialData&lt;/em&gt; query, and click the &lt;strong&gt;New event handler&lt;/strong&gt; button to create a new event.&lt;/li&gt;
&lt;li&gt;Choose &lt;strong&gt;Query Success&lt;/strong&gt; as the &lt;strong&gt;Event&lt;/strong&gt;, &lt;strong&gt;Run Query&lt;/strong&gt; as the &lt;strong&gt;Action&lt;/strong&gt;, and select &lt;em&gt;generateMockData&lt;/em&gt; as the Query.&lt;/li&gt;
&lt;li&gt;Next, Select the Table component. In the properties panel on the right, enter the following code in the Data field.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{JSON.parse(queries.generateMockData.data.candidates[0].content.parts[0].text)}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Select the &lt;em&gt;Save to Google Sheets&lt;/em&gt; Button component, under the Properties section, click the &lt;strong&gt;New event handler&lt;/strong&gt; button to create a new event.&lt;/li&gt;
&lt;li&gt;Choose &lt;strong&gt;On click&lt;/strong&gt; as the &lt;strong&gt;Event&lt;/strong&gt;, &lt;strong&gt;Run Query&lt;/strong&gt; as the &lt;strong&gt;Action&lt;/strong&gt;, and select &lt;em&gt;insertData&lt;/em&gt; as the &lt;strong&gt;Query&lt;/strong&gt;.
We have successfully integrated our queries into our UI.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now let's test the application with the following sample data format:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feek2o7qduujovg6hjwv0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feek2o7qduujovg6hjwv0.png" alt=" " width="800" height="278"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Table Preview&lt;/strong&gt;:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft1dg2h8s11umapq96ow5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft1dg2h8s11umapq96ow5.png" alt=" " width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the &lt;strong&gt;Save to Google Sheets&lt;/strong&gt; Button.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqr3r6t6b6v0b6znxykqx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqr3r6t6b6v0b6znxykqx.png" alt=" " width="800" height="388"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Congratulations on successfully building an AI-driven Mock Data Generator using ToolJet and Gemini API.&lt;/p&gt;

&lt;p&gt;To learn and explore more about ToolJet, check out the &lt;a href="https://docs.tooljet.com/docs/" rel="noopener noreferrer"&gt;ToolJet docs&lt;/a&gt; or connect with us and post your queries on &lt;a href="https://join.slack.com/t/tooljet/shared_invite/zt-2ij7t3rzo-qV7WTUTyDVQkwVxTlpxQqw" rel="noopener noreferrer"&gt;Slack&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>googlesheets</category>
      <category>ai</category>
      <category>javascript</category>
      <category>lowcode</category>
    </item>
    <item>
      <title>Building a SQL Report Generator using Gemini AI + ToolJet 📊</title>
      <dc:creator>Aman Regu</dc:creator>
      <pubDate>Tue, 18 Jun 2024 13:00:56 +0000</pubDate>
      <link>https://dev.to/tooljet/building-a-sql-report-generator-using-gemini-ai-tooljet-424p</link>
      <guid>https://dev.to/tooljet/building-a-sql-report-generator-using-gemini-ai-tooljet-424p</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This tutorial will guide you through the process of building an AI-driven SQL custom report generator using &lt;a href="https://github.com/ToolJet/ToolJet" rel="noopener noreferrer"&gt;ToolJet&lt;/a&gt;, 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.&lt;/p&gt;




&lt;h2&gt;
  
  
  Prerequisites:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ToolJet&lt;/strong&gt; (&lt;a href="https://github.com/ToolJet/ToolJet):" rel="noopener noreferrer"&gt;https://github.com/ToolJet/ToolJet):&lt;/a&gt; An open-source, low-code business application builder. &lt;a href="https://www.tooljet.com/signup" rel="noopener noreferrer"&gt;Sign up&lt;/a&gt; for a free ToolJet cloud account or &lt;a href="https://docs.tooljet.com/docs/setup/try-tooljet/" rel="noopener noreferrer"&gt;run ToolJet on your local machine&lt;/a&gt; using Docker.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gemini API Key&lt;/strong&gt; : Log into &lt;a href="https://aistudio.google.com/app/apikey" rel="noopener noreferrer"&gt;Google AI Studio&lt;/a&gt; using your existing Google credentials. Within the AI Studio interface, you can locate and copy your API key.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is a quick preview of our final application:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxb7brsesfnu9t6ny61h1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxb7brsesfnu9t6ny61h1.png" alt="SQL Report Builder Preview" width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Login to your &lt;a href="https://app.tooljet.com/" rel="noopener noreferrer"&gt;ToolJet account&lt;/a&gt;. 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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building our UI
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Drag and drop the &lt;strong&gt;Container&lt;/strong&gt; component onto the canvas from the component library on the right side. Adjust the height and width of the &lt;strong&gt;Container&lt;/strong&gt; component appropriately.&lt;/li&gt;
&lt;li&gt;Similarly, drag-and-drop the &lt;strong&gt;Icon&lt;/strong&gt; and three &lt;strong&gt;Text&lt;/strong&gt; components inside your Container. We'll use these &lt;strong&gt;Text&lt;/strong&gt; components for our header and label texts.&lt;/li&gt;
&lt;li&gt;For the &lt;strong&gt;Icon&lt;/strong&gt; component, navigate to the properties panel on the right and select the appropriate icon under the &lt;strong&gt;Icon&lt;/strong&gt; property.&lt;/li&gt;
&lt;li&gt;Change the colour of the &lt;strong&gt;Icon&lt;/strong&gt; and &lt;strong&gt;Text&lt;/strong&gt; component according to your preference.&lt;/li&gt;
&lt;li&gt;Change the font size and content of the &lt;strong&gt;Text&lt;/strong&gt; component appropriately.&lt;/li&gt;
&lt;li&gt;Drag and drop the &lt;strong&gt;Textarea&lt;/strong&gt; component inside your Container. We'll use this component as an input for our text query.&lt;/li&gt;
&lt;li&gt;Rename the &lt;strong&gt;Textarea&lt;/strong&gt; component to &lt;em&gt;textPrompt&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Next, drag and drop the &lt;strong&gt;Table&lt;/strong&gt; component onto the Container. We'll use this component to display a preview of our report. The &lt;strong&gt;Table&lt;/strong&gt; component comes built-in with the functionality to download the displayed data. This will allow us to download our generated report in PDF, Excel, or CSV formats.&lt;/li&gt;
&lt;li&gt;Now let's add a &lt;strong&gt;Button&lt;/strong&gt; component that initiates the report generation process. Change the colour, size and content appropriately.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5b1r1pifxlt1kj74xe0e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5b1r1pifxlt1kj74xe0e.png" alt="SQL Report Builder UI" width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Setting up Queries
&lt;/h2&gt;

&lt;p&gt;Apart 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.&lt;/p&gt;

&lt;p&gt;We'll also be using the REST API query feature to connect with the &lt;strong&gt;Gemini&lt;/strong&gt; API endpoints.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the query panel, click the + Add button and choose the Sample data source option.&lt;/li&gt;
&lt;li&gt;Rename the query to getDatabaseSchema.&lt;/li&gt;
&lt;li&gt;In the dropdown, choose the SQL mode and enter the code below. This will fetch all the table names in our database along with their column names.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT table_name, string_agg(column_name, ', ') AS columns
FROM information_schema.columns
WHERE table_schema = 'public'
GROUP BY table_name

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;To ensure that the query runs every time the application loads, enable the &lt;strong&gt;Run this query on application load?&lt;/strong&gt; toggle.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, let's create another query that will connect to the Gemini AI API and generate our custom SQL report query.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Using ToolJet's &lt;a href="https://docs.tooljet.com/docs/org-management/workspaces/workspace_constants/" rel="noopener noreferrer"&gt;Workspace Constants&lt;/a&gt; feature, create a new constant named &lt;strong&gt;GEMINI_API_KEY&lt;/strong&gt; with your Gemini API key.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the query panel, click on the &lt;strong&gt;+ Add&lt;/strong&gt; button and choose the &lt;strong&gt;REST API&lt;/strong&gt; option.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rename the query to &lt;em&gt;getSqlQuery&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the Request parameter, choose POST as the Method from the drop-down and paste the following URL.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent?key={{constants.GEMINI_API_KEY}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Navigate to the Body section of &lt;em&gt;getSqlQuery&lt;/em&gt;. Toggle on Raw JSON and enter the following code:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{
  `{
   "contents": [{
     "parts": [{
       "text": "Data Schema: ${JSON.stringify(queries.getTablesWithColumns.data.map(item =&amp;gt; ({ ...item, table_name: "public." + item.table_name }))).replace(/"([^"]+)":/g, '$1:').replace(/"/g, '\\"')}, Text Prompt: Write a standard SQL query for a custom SQL report that will ${components.textPrompt.value.replaceAll("\n"," ")}. Return without formatting and without any code highlighting and any backticks"
      },],
    },],
  }`
}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's add our final query which will retrieve the data from the sample data source that we need for our custom report.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Similarly, create another &lt;strong&gt;Sample data source&lt;/strong&gt; query, rename it to &lt;em&gt;getReportData&lt;/em&gt; and enter the code below:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{queries.getSqlQuery.data.candidates[0].content.parts[0].text}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Binding Queries to the UI Components
&lt;/h2&gt;

&lt;p&gt;Now that we have successfully built our UI and queries, the next step is to integrate them.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Select the &lt;strong&gt;Button&lt;/strong&gt; component and navigate to the properties panel on the right. Click on the &lt;strong&gt;+ New event handler&lt;/strong&gt; button. Change the &lt;strong&gt;Action&lt;/strong&gt; to &lt;strong&gt;Run query&lt;/strong&gt; and select the &lt;em&gt;getSqlQuery&lt;/em&gt; query.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next, navigate to the &lt;em&gt;getSqlQuery&lt;/em&gt; query and click on the &lt;strong&gt;+ New event handler&lt;/strong&gt; button. Change the &lt;strong&gt;Action&lt;/strong&gt; to &lt;strong&gt;Run query&lt;/strong&gt; and select the &lt;em&gt;getReportData&lt;/em&gt; query.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next, Select the &lt;strong&gt;Table&lt;/strong&gt; component. In the properties panel on the right, enter the following code in the Data field.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{queries.getReportData.data}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have successfully integrated our queries into our UI. Now let's test the application with the prompt below:&lt;br&gt;
&lt;em&gt;list the names of customers along with the products they have ordered, including the order date and the total quantity ordered for each product.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpbdvss1cd8b7mjucowym.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpbdvss1cd8b7mjucowym.png" alt="SQL Report Example" width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can click on the &lt;strong&gt;+&lt;/strong&gt; button on the &lt;strong&gt;Table&lt;/strong&gt; footer to download this report in PDF, Excel, or CSV formats.&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;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.&lt;br&gt;
To learn and explore more about ToolJet, check out the &lt;a href="https://docs.tooljet.com/docs/" rel="noopener noreferrer"&gt;ToolJet docs&lt;/a&gt; or connect with us and post your queries on &lt;a href="https://join.slack.com/t/tooljet/shared_invite/zt-2ij7t3rzo-qV7WTUTyDVQkwVxTlpxQqw" rel="noopener noreferrer"&gt;Slack&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>lowcode</category>
      <category>gemini</category>
      <category>javascript</category>
      <category>ai</category>
    </item>
    <item>
      <title>Building an Intelligent Reimbursement Tracking App using OCR with Gemini API + ToolJet 🚀</title>
      <dc:creator>Aman Regu</dc:creator>
      <pubDate>Thu, 06 Jun 2024 13:25:06 +0000</pubDate>
      <link>https://dev.to/tooljet/building-an-intelligent-reimbursement-tracking-app-using-ocr-with-tooljet-gemini-api-9kb</link>
      <guid>https://dev.to/tooljet/building-an-intelligent-reimbursement-tracking-app-using-ocr-with-tooljet-gemini-api-9kb</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This tutorial will guide you through building an intelligent reimbursement tracking app with OCR using &lt;a href="https://github.com/ToolJet/ToolJet" rel="noopener noreferrer"&gt;ToolJet&lt;/a&gt; and the Gemini API. The app will allow users to upload images of receipts, extract text from the images using OCR, and store the extracted information in a database. We'll also add an AWS S3 integration to store the receipt images.&lt;/p&gt;




&lt;h2&gt;
  
  
  Prerequisites:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ToolJet&lt;/strong&gt; (&lt;a href="https://github.com/ToolJet/ToolJet" rel="noopener noreferrer"&gt;https://github.com/ToolJet/ToolJet&lt;/a&gt;) : An open-source, low-code business application builder. &lt;a href="https://www.tooljet.com/signup" rel="noopener noreferrer"&gt;Sign up&lt;/a&gt; for a free ToolJet cloud account or &lt;a href="https://docs.tooljet.com/docs/setup/try-tooljet/" rel="noopener noreferrer"&gt;run ToolJet on your local machine&lt;/a&gt; using Docker.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gemini API Key&lt;/strong&gt; : Log into &lt;a href="https://aistudio.google.com/app/apikey" rel="noopener noreferrer"&gt;Google AI Studio&lt;/a&gt; using your existing Google credentials. Within the AI Studio interface, you'll be able to locate and copy your API key.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is a quick preview of our final application:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqim5qd042q11qq1pxtx3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqim5qd042q11qq1pxtx3.png" alt=" " width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F98cdkxof9nkg2opompzb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F98cdkxof9nkg2opompzb.png" alt=" " width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Building our UI
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Login to your &lt;a href="https://app.tooljet.com/" rel="noopener noreferrer"&gt;ToolJet account&lt;/a&gt;. Navigate to ToolJet dashboard and click on the &lt;strong&gt;Create new app&lt;/strong&gt; button on the top left corner. ToolJet comes with 45+ built-in components. This will let us set up our UI in no time.&lt;/li&gt;
&lt;li&gt;Drag and drop the &lt;strong&gt;Container&lt;/strong&gt; component onto the canvas from the component library on the right side. Adjust the height and width of the &lt;strong&gt;Container&lt;/strong&gt; component appropriately.&lt;/li&gt;
&lt;li&gt;Similarly, drag-and-drop the &lt;strong&gt;Icon&lt;/strong&gt; and two &lt;strong&gt;Text&lt;/strong&gt; components inside your container. We'll use these two &lt;strong&gt;Text&lt;/strong&gt; components for our header and instructional text.&lt;/li&gt;
&lt;li&gt;Select the &lt;strong&gt;Icon&lt;/strong&gt; component, navigate to its properties panel on the right and select the &lt;em&gt;ZoomMoney&lt;/em&gt; icon under its &lt;strong&gt;Icon&lt;/strong&gt; property.&lt;/li&gt;
&lt;li&gt;Change the font size and content of the &lt;strong&gt;Text&lt;/strong&gt; component appropriately.&lt;/li&gt;
&lt;li&gt;Drag and drop the &lt;strong&gt;File Picker&lt;/strong&gt; and the &lt;strong&gt;Button&lt;/strong&gt; component inside your container. We'll use the &lt;strong&gt;File Picker&lt;/strong&gt; component to allow users to upload images of their receipts. The &lt;strong&gt;Button&lt;/strong&gt; component will be used to trigger the &lt;strong&gt;OCR&lt;/strong&gt; process.&lt;/li&gt;
&lt;li&gt;Rename the &lt;strong&gt;File Picker&lt;/strong&gt; component to &lt;em&gt;fileUploader&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Adjust the width of the &lt;strong&gt;File Picker&lt;/strong&gt; component according to your preference.&lt;/li&gt;
&lt;li&gt;Change the colour and text of the &lt;strong&gt;Button&lt;/strong&gt; component according to your preference.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fslg0w97ly9httwd5py1r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fslg0w97ly9httwd5py1r.png" alt=" " width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have implemented the user interface for uploading receipts. The next step is to create the UI for administrators to approve or reject expense submissions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click on the &lt;strong&gt;Pages&lt;/strong&gt; icon on the left side of the screen. On the header of the Pages Panel, click on the &lt;strong&gt;+&lt;/strong&gt; button to create a new page.&lt;/li&gt;
&lt;li&gt;Drag and drop the &lt;strong&gt;Container&lt;/strong&gt; component onto the canvas. Adjust the height and width of the &lt;strong&gt;Container&lt;/strong&gt; component appropriately.&lt;/li&gt;
&lt;li&gt;Drag and drop the &lt;strong&gt;Icon&lt;/strong&gt; and a &lt;strong&gt;Text&lt;/strong&gt; component inside your container. We'll use these two components for our logo and header text.&lt;/li&gt;
&lt;li&gt;Drag and drop the &lt;strong&gt;Table&lt;/strong&gt; component inside the container. We'll use the &lt;strong&gt;Table&lt;/strong&gt; component to display the list of expense submissions. We'll later also add &lt;strong&gt;Action&lt;/strong&gt; Buttons to approve, reject, and view the receipt image for each submission.&lt;/li&gt;
&lt;li&gt;Drag and drop the &lt;strong&gt;Modal&lt;/strong&gt; component inside the container. Open the &lt;strong&gt;Modal&lt;/strong&gt; component and drag and drop the &lt;strong&gt;HTML&lt;/strong&gt; component inside the Modal. We'll use the &lt;strong&gt;HTML&lt;/strong&gt; component to display the receipt image.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbj5z6mg5jmeegfutpkgi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbj5z6mg5jmeegfutpkgi.png" alt=" " width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Creating Queries
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;ToolJet&lt;/strong&gt; allows connecting to third-party APIs using its REST API query feature. We'll use this to connect to the &lt;strong&gt;Gemini&lt;/strong&gt; API to extract the text from the uploaded receipt images. ToolJet comes with built-in integration with &lt;strong&gt;AWS S3&lt;/strong&gt;, we'll use this to store the receipt images.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using ToolJet's &lt;a href="https://docs.tooljet.com/docs/org-management/workspaces/workspace_constants/" rel="noopener noreferrer"&gt;Workspace Constants&lt;/a&gt; feature, create a new constant named &lt;strong&gt;GEMINI_API_KEY&lt;/strong&gt; with your Gemini API key.&lt;/li&gt;
&lt;li&gt;In the query panel, click the &lt;strong&gt;+ Add&lt;/strong&gt; button and choose the &lt;strong&gt;REST API&lt;/strong&gt; option.&lt;/li&gt;
&lt;li&gt;Rename the query to &lt;em&gt;extractTextFromImage&lt;/em&gt;.
In the Request parameter, choose &lt;strong&gt;POST&lt;/strong&gt; as the Method from the drop-down and paste the following URL.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent?key={{constants.GEMINI_API_KEY}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Navigate to the Body section of the extractTextFromImage. Toggle on &lt;strong&gt;Raw JSON&lt;/strong&gt; and enter the following code:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "contents": [
    {
      "parts": [
        {
          "text": "In this image of a receipt, analyze the receipt image and return the following information in JSON format without any formatting or syntax highlighting: total_amount, date."
        },
        {
          "inline_data": {
            "mime_type":"image/jpeg",
              "data": "{{components.fileUploader.file[0].base64Data}}"
          }
        }
      ]
    }
  ]
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Next, we'll create a query to save extracted text to the ToolJet database.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the &lt;strong&gt;ToolJet&lt;/strong&gt; logo on the top left corner and select the Database option.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the &lt;strong&gt;Create new table&lt;/strong&gt; button and name the table reimbursement_requests. Add the following columns to the table: &lt;em&gt;id&lt;/em&gt;, &lt;em&gt;name&lt;/em&gt;, &lt;em&gt;email&lt;/em&gt;, &lt;em&gt;total_amount&lt;/em&gt;, &lt;em&gt;status&lt;/em&gt; and &lt;em&gt;receipt_date&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F56abdgwm05sti36sct6d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F56abdgwm05sti36sct6d.png" alt=" " width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Navigate back to the Query panel and click on the &lt;strong&gt;+ Add&lt;/strong&gt; button. Choose the &lt;strong&gt;ToolJet Database&lt;/strong&gt; option.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rename the query to &lt;em&gt;addReceiptData&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select the &lt;em&gt;reimbursement_requests&lt;/em&gt; table name from the drop-down.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the Operation drop-down, choose &lt;strong&gt;Create row&lt;/strong&gt; and enter the following data for the columns.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Column Name&lt;/th&gt;
&lt;th&gt;Key&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;email&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{{globals.currentUser.email}}&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;name&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{{globals.currentUser.name}}&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;total_amount&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{{JSON.parse(queries.extractTextFromImage.data.candidates[0].content.parts[0].text).total_amount}}&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;receipt_date&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{{JSON.parse(queries.extractTextFromImage.data.candidates[0].content.parts[0].text).date}}&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Next, we'll create a query to store the receipt image in the AWS S3 bucket.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a new data source to connect to the AWS S3 using ToolJet's built-in &lt;a href="https://docs.tooljet.com/docs/data-sources/s3/" rel="noopener noreferrer"&gt;AWS S3 integration&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the &lt;strong&gt;+ Add&lt;/strong&gt; button in the Query panel and choose the newly created AWS S3 data source.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rename the query to &lt;em&gt;addToS3&lt;/em&gt; and select the operation as &lt;strong&gt;Upload object&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add the following data for the columns:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Column Name&lt;/th&gt;
&lt;th&gt;Key&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Bucket&lt;/td&gt;
&lt;td&gt;bucket name (should already exist)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Key&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{{"reimbursement_id" + "_" + queries.addReceiptData.data[0].id}}&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Content Type&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{{components.fileUploader.file[0].type}}&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Upload Data&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{{JSON.parse(queries.extractTextFromImage.data.candidates[0].content.parts[0].text).date}}&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Encoding&lt;/td&gt;
&lt;td&gt;base64&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Next, we'll create the query to fetch the list of expense submissions from the ToolJet database.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Click on the &lt;strong&gt;+ Add&lt;/strong&gt; button in the Query panel and choose the ToolJet Database option and rename the query to &lt;em&gt;getReimbursementRequests&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select the &lt;em&gt;reimbursement_requests&lt;/em&gt; table from the drop-down.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the Operation drop-down, choose &lt;strong&gt;List rows&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To ensure that the query runs every time the application loads, enable the &lt;strong&gt;Run this query on application load?&lt;/strong&gt; toggle.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next, create two more ToolJet database queries to approve and reject the expense submissions, named &lt;em&gt;approveRequest&lt;/em&gt; and &lt;em&gt;rejectRequest&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For both of these queries, select the &lt;em&gt;reimbursement_requests&lt;/em&gt; table and choose the &lt;strong&gt;Update row&lt;/strong&gt; operation and to use the filter field to match the id of the row to be updated using the &lt;code&gt;{{components.reimbursementRequestsTable.selectedRow.id}}&lt;/code&gt; variable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the columns field, update the Status column to approved for the &lt;em&gt;approveRequest&lt;/em&gt; query and rejected for the &lt;em&gt;rejectRequest&lt;/em&gt; query.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's add our last query to fetch the receipt image from the AWS S3 bucket.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click on the &lt;strong&gt;+ Add&lt;/strong&gt; button in the Query panel and choose the AWS S3 data source and rename the query to &lt;em&gt;getReceiptImage&lt;/em&gt; and enter the following data.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Column Name&lt;/th&gt;
&lt;th&gt;Key&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Operation&lt;/td&gt;
&lt;td&gt;Signed url for download&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bucket&lt;/td&gt;
&lt;td&gt;bucket name&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Key&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{{"reimbursement_id" + "_" + components.table1.selectedRow.id}}&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Expiries in&lt;/td&gt;
&lt;td&gt;3600&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Binding Queries to the UI Components
&lt;/h2&gt;

&lt;p&gt;Now that we have successfully built our UI and queries, the next step is to integrate them.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Select the &lt;strong&gt;Button&lt;/strong&gt; component and navigate to the properties panel on the right. Click on the &lt;strong&gt;+ New event handler&lt;/strong&gt; button. Change the &lt;strong&gt;Action&lt;/strong&gt; to &lt;strong&gt;Run query&lt;/strong&gt; and select the &lt;em&gt;extractTextFromImage&lt;/em&gt; query.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next, navigate to the &lt;em&gt;extractTextFromImage&lt;/em&gt; query and click on the &lt;strong&gt;+ New event handler&lt;/strong&gt; button. Change the &lt;strong&gt;Action&lt;/strong&gt; to &lt;strong&gt;Run query&lt;/strong&gt; and select the &lt;em&gt;addReceiptData&lt;/em&gt; query.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Navigate to the &lt;em&gt;addReceiptData&lt;/em&gt; query and click on the &lt;strong&gt;+ New event handler&lt;/strong&gt; button. Change the &lt;strong&gt;Action&lt;/strong&gt; to &lt;strong&gt;Run query&lt;/strong&gt; and select the &lt;em&gt;addToS3&lt;/em&gt; query.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Our upload receipts feature is now complete. You can test this out by uploading a receipt image and verify the extracted data in your ToolJet database.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next, we'll implement the admin approval feature.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Navigate to the Admin page and select the &lt;strong&gt;Table&lt;/strong&gt; component. In the properties panel on the right, enter &lt;code&gt;{{queries.getReimbursementRequests.data}}&lt;/code&gt; in the Data field.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the &lt;strong&gt;+ New action button&lt;/strong&gt; in the properties panel and create three new actions buttons: &lt;strong&gt;Approve&lt;/strong&gt;, &lt;strong&gt;Reject&lt;/strong&gt;, and &lt;strong&gt;View Receipt&lt;/strong&gt;. Bind the &lt;em&gt;approveRequest&lt;/em&gt; and &lt;em&gt;rejectRequest&lt;/em&gt; to the respective action buttons using Event Handlers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Change the background colour and text of the action buttons according to your preference.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the &lt;strong&gt;View Receipt&lt;/strong&gt; action button and Add a new event handler. Change the Action to Open Modal and select the &lt;em&gt;displayReceiptImage&lt;/em&gt; modal.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Navigate to the &lt;em&gt;displayReceiptImage&lt;/em&gt; modal and in the properties panel on the right, uncheck the Use &lt;strong&gt;default trigger button&lt;/strong&gt; toggle.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inside the modal, click on the &lt;strong&gt;HTML&lt;/strong&gt; component and enter &lt;code&gt;&amp;lt;img src={{queries.getReceiptFromS3.data.url}}&amp;gt;&lt;/code&gt; in the Raw HTML field. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Our admin approval feature is now complete. You can test this out by uploading a receipt image and verifying the extracted data in the Table component. You can click on the &lt;strong&gt;Approve&lt;/strong&gt; or &lt;strong&gt;Reject&lt;/strong&gt; buttons to approve or reject the expense submission. You can also view the receipt image by clicking on the &lt;strong&gt;View Receipt&lt;/strong&gt; button.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7chbcr4tutudc0iie5rs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7chbcr4tutudc0iie5rs.png" alt=" " width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Congratulations! You've successfully built a powerful reimbursement tracking app with OCR capabilities using ToolJet and the Gemini API. You can now track and manage expense submissions with ease. Feel free to customize the app further by adding more features and functionalities.&lt;br&gt;
To learn and explore more about ToolJet, check out the &lt;a href="https://docs.tooljet.com/docs/" rel="noopener noreferrer"&gt;ToolJet docs&lt;/a&gt; or connect with us and post your queries on &lt;a href="https://join.slack.com/t/tooljet/shared_invite/zt-2ij7t3rzo-qV7WTUTyDVQkwVxTlpxQqw" rel="noopener noreferrer"&gt;Slack&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>gemini</category>
      <category>ai</category>
      <category>lowcode</category>
      <category>tooljet</category>
    </item>
    <item>
      <title>Building a SQL Query Generator Using ToolJet + Gemini API</title>
      <dc:creator>Aman Regu</dc:creator>
      <pubDate>Thu, 30 May 2024 13:03:44 +0000</pubDate>
      <link>https://dev.to/tooljet/building-a-sql-query-generator-using-tooljet-gemini-api-4lo9</link>
      <guid>https://dev.to/tooljet/building-a-sql-query-generator-using-tooljet-gemini-api-4lo9</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This tutorial will guide you through the process of building an AI-driven SQL query generator using &lt;a href="https://github.com/ToolJet/ToolJet" rel="noopener noreferrer"&gt;ToolJet&lt;/a&gt;, a low-code visual app builder, and the Gemini API, a powerful natural language processing API. The resulting application will enable users to input prompts in plain English, which will then be translated into executable SQL queries. We'll be using 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.&lt;/p&gt;




&lt;h2&gt;
  
  
  Prerequisites:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ToolJet&lt;/strong&gt; (&lt;a href="https://github.com/ToolJet/ToolJet" rel="noopener noreferrer"&gt;https://github.com/ToolJet/ToolJet&lt;/a&gt;) : An open-source , low-code business application builder. &lt;a href="https://www.tooljet.com/signup" rel="noopener noreferrer"&gt;Sign up&lt;/a&gt; for a free ToolJet cloud account or &lt;a href="https://docs.tooljet.com/docs/setup/try-tooljet/" rel="noopener noreferrer"&gt;run ToolJet on your local machine&lt;/a&gt; using Docker.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gemini API Key&lt;/strong&gt; : Log into &lt;a href="https://aistudio.google.com/app/apikey" rel="noopener noreferrer"&gt;Google AI Studio&lt;/a&gt; using your existing Google credentials. Within the AI Studio interface, you'll be able to locate and copy your API key.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is a quick preview of our final application:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Famxvh44ue5inhf9cyoh8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Famxvh44ue5inhf9cyoh8.png" alt=" " width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Crafting our UI
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Login to your &lt;a href="https://app.tooljet.com/" rel="noopener noreferrer"&gt;ToolJet account&lt;/a&gt;. Navigate to ToolJet dashboard and click on the &lt;strong&gt;Create new app&lt;/strong&gt; button on the top left corner. ToolJet comes with 45+ built-in components. This will let us set up our UI in no time.&lt;/li&gt;
&lt;li&gt;Drag and drop the &lt;strong&gt;Container&lt;/strong&gt; component onto the canvas from the component library on the right side. Adjust the height and width of the &lt;strong&gt;Container&lt;/strong&gt; component appropriately.&lt;/li&gt;
&lt;li&gt;Similarly, drag-and-drop the &lt;strong&gt;Icon&lt;/strong&gt; and two &lt;strong&gt;Text&lt;/strong&gt; components inside your container. We'll use these two &lt;strong&gt;Text&lt;/strong&gt; components for our header and byline texts.&lt;/li&gt;
&lt;li&gt;Select the &lt;strong&gt;Icon&lt;/strong&gt; component, navigate to its properties panel on the right and select the database icon under its &lt;strong&gt;Icon&lt;/strong&gt; property.&lt;/li&gt;
&lt;li&gt;Change the colour of the &lt;strong&gt;Icon&lt;/strong&gt; and &lt;strong&gt;Text&lt;/strong&gt; components according to your preference. Here we'll use a shade of blue(HEX code: #4A7EE2).&lt;/li&gt;
&lt;li&gt;Change the font size and content of the &lt;strong&gt;Text&lt;/strong&gt; component appropriately.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2tezdxuu2q9zq5fpazaj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2tezdxuu2q9zq5fpazaj.png" alt=" " width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Drag and drop the &lt;strong&gt;Dropdown&lt;/strong&gt; component into the Container. We'll use this component for choosing between the models offered by the &lt;strong&gt;Gemini&lt;/strong&gt; API.&lt;/li&gt;
&lt;li&gt;Rename this component as &lt;em&gt;modelDropdown&lt;/em&gt;. Renaming the components will help quickly access their data during development.&lt;/li&gt;
&lt;li&gt;Similarly, drag-and-drop three &lt;strong&gt;Textarea&lt;/strong&gt; components into the Container. We'll use these components for our Data Schema input, Text Query input and the third one to display the generated SQL query.&lt;/li&gt;
&lt;li&gt;Rename the three &lt;strong&gt;Textarea&lt;/strong&gt; components as &lt;em&gt;databaseSchemaInput&lt;/em&gt;, &lt;em&gt;textPrompt&lt;/em&gt;, and &lt;em&gt;generatedQuery&lt;/em&gt; respectively.&lt;/li&gt;
&lt;li&gt;Adjust the height and width of the &lt;strong&gt;Textarea&lt;/strong&gt; components appropriately.&lt;/li&gt;
&lt;li&gt;Under the &lt;strong&gt;Properties&lt;/strong&gt; section, clear the Default value input and enter an appropriate Placeholder text.&lt;/li&gt;
&lt;li&gt;Drag and drop another &lt;strong&gt;Text&lt;/strong&gt; component. We'll use this as a label for our generated query &lt;strong&gt;Textarea&lt;/strong&gt; component. Change the colour, font size and content appropriately.&lt;/li&gt;
&lt;li&gt;Let's add our last component, drag-and-drop a &lt;strong&gt;Button&lt;/strong&gt; component. We'll use this to trigger the SQL query generation. Change the colour, size and content appropriately.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl1p7ggxevjpxwgviumtc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl1p7ggxevjpxwgviumtc.png" alt=" " width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Creating Queries
&lt;/h2&gt;

&lt;p&gt;ToolJet allows connecting to third-party APIs using its REST API query feature. We'll use this to integrate our UI with the Gemini API endpoints. We'll create two separate REST API queries:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The first query will fetch a list of all the AI models provided by the &lt;strong&gt;Gemini&lt;/strong&gt; API.&lt;/li&gt;
&lt;li&gt;The second query will be a POST request that sends user inputs to the &lt;strong&gt;Gemini&lt;/strong&gt; API endpoint. It will return the generated SQL query based on those inputs.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We'll also utilise ToolJet's &lt;strong&gt;Workspace Constants&lt;/strong&gt; to securely store our &lt;strong&gt;Gemini&lt;/strong&gt; API key. Workspace Constants are resolved server-side. This ensures the actual values of the constants are not sent with network payloads; instead, the server resolves these values, thereby keeping them secure from client-side exposure.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To create a &lt;strong&gt;Workspace constant&lt;/strong&gt;, click on the ToolJet logo in the top left corner. From the dropdown, select &lt;strong&gt;Workspace constants&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Click on the &lt;strong&gt;Create new constant&lt;/strong&gt; button. Set the name as &lt;em&gt;GEMINI_API_KEY&lt;/em&gt; and enter your &lt;strong&gt;Gemini&lt;/strong&gt; API key in the value input.&lt;/li&gt;
&lt;li&gt;Click on the &lt;strong&gt;Add constant&lt;/strong&gt; button. This constant will now be available across our workspace and can be accessed using &lt;code&gt;{{constants.GEMINI_API_KEY}}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Navigate back to your app and open the Query Manager.&lt;/li&gt;
&lt;li&gt;Click the &lt;strong&gt;+ Add&lt;/strong&gt; button and choose the &lt;strong&gt;REST API&lt;/strong&gt; option.&lt;/li&gt;
&lt;li&gt;Rename the query as &lt;em&gt;getModels&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Keep the Request Method as &lt;strong&gt;GET&lt;/strong&gt; and paste the following URL in the URL input. This is the Gemini API endpoint that will return the models available to us.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://generativelanguage.googleapis.com/v1beta/models?key={{constants.GEMINI_API_KEY}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;To ensure that the query runs every time the application loads, enable the &lt;strong&gt;Run this query on application load?&lt;/strong&gt; toggle.&lt;/li&gt;
&lt;li&gt;Similarly, create another query and name it as &lt;em&gt;getSqlQuery&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Request&lt;/strong&gt; parameter, choose &lt;strong&gt;POST&lt;/strong&gt; as the Method from the drop-down and paste the following URL.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://generativelanguage.googleapis.com/v1beta/{{components.modelDropdown.value}}:generateContent?key={{constants.GEMINI_API_KEY}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Navigate to the Body section of the &lt;em&gt;getSqlQuery&lt;/em&gt;. Toggle on &lt;strong&gt;Raw JSON&lt;/strong&gt; and enter the following code:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{
  `{
   "contents": [{
     "parts": [{
       "text": "Data Schema: ${components.databaseSchemaInput.value.replaceAll("\n"," ")}, Text Prompt: Write a standard SQL query that will ${components.textPrompt.value.replaceAll("\n"," ")}. Return with correct formatting but without any code highlighting and any backticks"
      },],
    },],
  }`
}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Integrating the UI with Queries
&lt;/h2&gt;

&lt;p&gt;Now that we have successfully built our UI and queries, the next step is to integrate them.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select the &lt;strong&gt;Button&lt;/strong&gt; component, under the &lt;strong&gt;Properties&lt;/strong&gt; section, and click the &lt;strong&gt;New event handler&lt;/strong&gt; button to create a new event.&lt;/li&gt;
&lt;li&gt;Choose &lt;strong&gt;On click&lt;/strong&gt; as the &lt;strong&gt;Event&lt;/strong&gt;, &lt;strong&gt;Run Query&lt;/strong&gt; as the &lt;strong&gt;Action&lt;/strong&gt;, and select &lt;em&gt;getSqlQuery&lt;/em&gt; as the &lt;strong&gt;Query&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Select the &lt;strong&gt;Dropdown&lt;/strong&gt; component, under the &lt;strong&gt;Properties&lt;/strong&gt; section, and enter the following code for the Option values and labels.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Option values&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{queries.getModels.data.models.map(item =&amp;gt; item.name)}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Option labels&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{queries.getModels.data.models.map(item =&amp;gt; item.displayName)}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Select the &lt;em&gt;generatedQuery&lt;/em&gt; &lt;strong&gt;Textarea&lt;/strong&gt; component, under the &lt;strong&gt;Properties&lt;/strong&gt; section, and enter the following code for the Default value input.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Default value&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{queries.getSqlQuery.data.candidates[0].content.parts[0].text}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our AI-powered SQL query generator is complete. Let's provide some sample data to test it out.&lt;/p&gt;

&lt;p&gt;Database Schema:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Orders (id, product_id, address, customer_name, is_paid)
Products (id, quantity, moq)
Customers (id, name, email, phone, addresses)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Text Prompt/Query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find all the prepaid orders from a customer named Alex JR
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Expected Output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1rjpn413n42hejyu2ofc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1rjpn413n42hejyu2ofc.png" alt=" " width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Congratulations on successfully building an AI-powered SQL query generator using ToolJet and the Gemini API. You can now input prompts in plain English which are then accurately translated into executable SQL statements.&lt;br&gt;
To learn and explore more about ToolJet, check out the &lt;a href="https://docs.tooljet.com/docs/" rel="noopener noreferrer"&gt;ToolJet docs&lt;/a&gt; or connect with us and post your queries on &lt;a href="https://join.slack.com/t/tooljet/shared_invite/zt-2ij7t3rzo-qV7WTUTyDVQkwVxTlpxQqw" rel="noopener noreferrer"&gt;Slack&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>tooljet</category>
      <category>lowcode</category>
      <category>ai</category>
      <category>gemini</category>
    </item>
  </channel>
</rss>
