Chat with your Database using ChatGPT and Assistants API

Alexandro Martinez
3 min readJan 23, 2024

--

Learn how to chat with your database in natural language by using DataLang’s API or using a custom GPT.

  1. Set up your Data Source
  2. Create Database Views
  3. Configure a GPT Assistant and chat with it
  4. Publish a Custom GPT and share it

1. Set up your Data Source

Create a DataLang account (50% off for 12 months for the first 100 customers) and set up your connection string.

Database Source

Select “Database” and add your connection string.

Set up your database connection

Custom Server Source

If you don’t want to share your password (although encrypted), download the DataLang Custom server to host it on your server (see the code).

Set up your custom server

⚠️ TIP: Only use database users with read-only access to the tables you want exposed, and never share your API Key.

2. Create Database Views

Write the SQL statement to retrieve the necessary information to facilitate chat interactions among your users, employees, or customers.

Add your Database Views

By doing this, you’re also exposing your data through the API by calling:

datalang.io/api/data-sources/{source-slug}/views/{view-slug}?sync=false

Get data view snapshot

3. Create an Assistant

An Assistant acts as a bridge, grouping various data sources for chat interaction. For instance, you could create a ‘Sales Assistant’ that only has access to the New York and Chicago branches' data sources, each with 2–3 specialized sales data views.

Sales Assistant conversation demo

This is great by itself, but the Assistant’s API can’t do what ChatGPT can so let’s leverage the new GPT store.

4. Create a Custom GPT

Head over to the GPT store, and click Create. You’d need to fill in the following details:

  • Name: Sales Assistant
  • Description: New York and Chicago sales assistant.
  • Actions: What your assistant can access (TLDR: all data views from the selected data sources).

Go to your DataLang assistant, click “Custom GPT”, and follow the details instructions.

Create your Custom GPT

Now, publish it and share it with your users, employees, or customers!

Your custom GPT

Become an Affiliate ✨

If you know a company or two that could benefit from this, earn up to 30% for each payment in the first year. Click here to sign up as an affiliate.

What’s next?

I have many ideas:

  • Support more data sources: Files, API…
  • Support more data views: Stored procedures, spreadsheets…
  • Add data formats: Table, Chart, PDF…

Follow me to stay tuned, or subscribe to DataLang’s newsletter.

DataLang

--

--

Alexandro Martinez
Alexandro Martinez

Written by Alexandro Martinez

Building SaasRock, The One-Man SaaS Framework built with Remix + Tailwind CSS

No responses yet