How to build your own Chat GPT-powered application

How to build your own Chat GPT-powered application
Photo by D koi / Unsplash

LLMs (large-language models) have gone mainstream. Even the teachers at the school where my wife works are extoling their virtues.

How do you build an application with them?

That's the question I've been trying to answer over the past week.

Here's what I've found.

You can connect to chat GPT (and other LLMs through an API connection)

You can get ChatGPT to answer your questions through an API connection. Here's the webpage on OpenAIs website.

import openai
from dotenv import load_dotenv, find_dotenv

load_dotenv(find_dotenv())

messages = [{'role':'user', 'content': 'What is the capital of France?'}]
response = openai.ChatCompletion.create(
    model = 'gpt-3.5-turbo',
    messages = messages, 
    temperature = 0
    )
output = response.choices[0].message['content']

Now that you have, you can integrate ChatGPT into any application. However, by itself, it will just like a version of ChatGPT, if ChatGPT couldn't remember anything you'd previously said to it. Given that ChatGPT already exists and is free, you're going to need to do more to make it useful.

Have Chat-GPT interact with your user's data (using vector databases)

It's easy to have Chat GPT interact with your own data. Just copy and paste a document into the interface, and ask it to do something, such as edit it.

Think of this as a manual process. You have to do the searching and the copy-and-pasting, and the prompting.

But what if there was a way to have software do all the heavy lifting for you?

There is.

But what exactly is the heavy lifting here?

The time and energy spent searching your own data, and copying and pasting into chat.

To get around this, you can upload your data to a special database called a vector store. You present your document to a machine-learning model, and that model turns that document into a vector (of around 1000 numbers).

Then, when you have a particular question you want to ask, you look on the database to the vector that is closest to the one you entered and pull that document. Then, you can feed that into a prompt and have ChatGPT answer questions from your documents directly (without having to do anything complicated like retraining the model).

There are several vector databases, but the one I've been using is called Pinecone.

Here's a basic workflow to achieve this:

Once you have the data saved, here's how you can retrieve it:

This allows users to ask ChatGPT-type questions about their own data.

What about a front and back end?

I like simple things. So, when I discovered Bubble, I was a happy man.

Bubble is a no-code software development platform that's pretty easy to understand.

I recently worked through a tutorial combining all of these technologies together, as well as developing a front and back end. Here's the video:

It takes a couple of hours, and, by the time you've finished, you'll have put all of these techniques into practice.

From this video, I managed to create software where the user puts in the name of the website, and a web scraper grabs text from that website and saves it into a vector database. Then, the user can ask questions directly based on the data they've received.

What to do with all of this information?

The number of tasks you can automate with these tools is mind-boggling. But, at the end of the day, all of these technologies are just tools. They're only useful when they solve a real-life problem.

To any aspiring software developer/data scientist/entrepreneur,  my advice is to tinker with these tools, and then find someone with a problem, and  help them solve that problem.

p.s.

I'm keen to talk to people who are also interested in large language models and their applications. Whether that's from an engineering perspective or from a product perspective, please leave a comment or reach out if any of this is helpful–I'd love to start a conversation.