4
0 Comments

How to help colleagues query data using custom GPT in Slack

Yes, right. AI can write SQL queries for you. It can understand your database schema, generate SQL queries, and even interact with you to enhance them.

Let's create a bot that helps you write SQL queries, and invite the bot to your communication platforms, such as Slack or Microsoft Teams. It takes 20 minutes to create this without coding.

The image below shows how it works in Slack. Awesome, isn't it?

SQL Assistant Example

How to Create It

Don't worry. You don't need engineering knowledge to create yours.

Here are the simple steps:

  1. Extract database schema.
  2. Create an Assistant using OpenAI or Anthropic.
  3. Invite the Assistant to your communication platform using PlugBear.

Let's go through one by one.

1. Extracting database schema

This is the only step you may need help from engineers.

You can extract database schema in many ways. For example, you can extract PostgreSQL database schema using this command:

psql -c "\d *"

With proper parameters, you will get table descriptions like this:

                                  Table "public.User"
   Column   |              Type              | Collation | Nullable |      Default
------------+--------------------------------+-----------+----------+-------------------
 id         | uuid                           |           | not null |
 email      | text                           |           | not null |
 createdAt  | timestamp(6) with time zone    |           | not null | CURRENT_TIMESTAMP
 updatedAt  | timestamp(6) with time zone    |           | not null |
 firstName  | text                           |           |          |
 lastName   | text                           |           |          |
 orgId      | text                           |           | not null |

2. Creating an Assistant

If you are a PlugBear user, simply visit the "LLM Apps" page and click the "Create" button to create your Assistant that uses OpenAI or Anthropic.

All you need is to write simple instructions and attach the table descriptions. Here is an example:

You are the SQL Bot tasked with generating SQL queries based on user
requests. Utilize the provided table schema to retrieve the
information. Only use the specified tables and columns. Do not assume
the existence of any tables or columns not listed. If you are unable
to construct SQL for a given user query, acknowledge the limitation
rather than producing arbitrary SQL.

Table descriptions:

                                  Table "public.User"
   Column   |              Type              | Collation | Nullable |      Default
------------+--------------------------------+-----------+----------+-------------------
 id         | uuid                           |           | not null |
 email      | text                           |           | not null |
 createdAt  | timestamp(6) with time zone    |           | not null | CURRENT_TIMESTAMP
... 

3. Inviting the Assistant to your communication platform

Using PlugBear, this can be done with several clicks.

Click a button to integrate your communication platform, such as Slack or Microsoft Teams, connect the Assistant and the channel, and you're all set.

, Co-founder & CEO of Icon for Runbear
Runbear
on April 30, 2024
Trending on Indie Hackers
I shipped a productivity SaaS in 30 days as a solo dev — here's what AI actually changed (and what it didn't) User Avatar 257 comments Never hire an SEO Agency for your Saas Startup User Avatar 107 comments A simple way to keep AI automations from making bad decisions User Avatar 71 comments 85% of visitors leave our pricing page without buying. sharing our raw funnel data User Avatar 39 comments Are indie makers actually bad customers? User Avatar 39 comments We automated our business vetting with OpenClaw User Avatar 38 comments