Chat with your Database using Custom GPTs
Tags: gpt, database, sql, nlp
Published: 2024-01-26 17:10:28

---
title: Chat with your Database using Custom GPTs
published: true
description: Learn how to chat with your database in natural language by using DataLang’s API or using a custom GPT.
tags: gpt,database,SQL,nlp
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/peqxtppt03tiul3tdhlj.png
# Use a ratio of 100:42 for best results.
# published_at: 2024-01-26 17:01 +0000
---

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

Live on [ProductHunt](https://www.producthunt.com/posts/datalang)!

## 1. Set up your Data Source

Create a DataLang account ([50% off](https://datalang.io/pricing?coupon=launch) 12 months for the first 100 customers) and set up your connection string.

### Database Source
Select “Database” and add your connection string.

![New Database Source](https://cdn-images-1.medium.com/v2/resize:fit:1600/1*jKPFJ6cxYH8WNl5QywkJVQ.png)

### Custom Server Source
If you don’t want to share your password (although encrypted), download the [DataLang Custom server](https://datalang.io/download/datalang-server) to host it on your server ([see the code](https://github.com/AlexandroMtzG/datalang-db-to-api)).

![Custom Server Source](https://cdn-images-1.medium.com/max/1600/1*JQ9t1JwzM1IdMk0Y3_NVlg.png)

⚠️ 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.

![New Data View in SQL](https://cdn-images-1.medium.com/v2/resize:fit:1600/1*tCBU0e3-mInrX3_23mex5A.png)

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 via API](https://cdn-images-1.medium.com/v2/resize:fit:1600/1*QVkVGbFKwj8Q4PfhKI5ILQ.png)

## 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.

![Chat with the your custom Assistant](https://cdn-images-1.medium.com/v2/resize:fit:1600/1*5Ypr21Xnh9w3JcQzE-Na6g.png)

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](https://chat.openai.com/gpts), 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](https://datalang.io/) assistant, click “Custom GPT”, and follow the details instructions.

![Create a Custom GPT Instructions](https://cdn-images-1.medium.com/v2/resize:fit:1600/1*gEVswwb5JneJ03ti5HQjwQ.png)

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

![Chat with your Custom GPT in ChatGPT](https://miro.medium.com/v2/resize:fit:1400/format:webp/1*2nKBcHSyd_mvNBaxv7rQNw.png)

### 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](https://datalang.getrewardful.com/) to sign up as an affiliate.

---

## What’s next?

This was built using my Remix SaaS boilerplate [SaasRock](https://saasrock.com/?ref=datalang-launch), so tons of upcoming updates this year. I have many ideas specifically for DataLang:

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

[Follow me](https://twitter.com/AlexandroMtzG) to stay tuned, or subscribe to [DataLang’s newsletter](https://datalang.io/newsletter).