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
You don't need to write the same thing again User Avatar 27 comments I built something that helps founders turn user clicks into real change 🌱✨ User Avatar 26 comments I built an Image-to-3D SaaS using Tencent's Hunyuan 3D AI User Avatar 25 comments Let’s Talk: What’s Missing in Today’s App Builders? User Avatar 17 comments The Era of Malleable SaaS: Is This the End of "Opinionated Software"? User Avatar 15 comments 15 Years of Designmodo User Avatar 14 comments