How to Build a Custom GPT: Step by Step

In this guide, we'll walk through step-by-step how to build a custom GPT with access to knowledge, tools, and actions.

3 months ago   •   8 min read

By Peter Foy

One of the most notable releases at OpenAI's DevDay was the introduction of GPTs.

You can now create custom versions of ChatGPT that combine instructions, extra knowledge, and any combination of skills.

What are GPTs?

GPTs are custom versions of ChatGPT that anyone can build using entirely natural language...aka no coding needed.

GPTs provide the ability to deeply customize ChatGPT with all new capabilities. GPTs also lower the barrier for builders. 

Aside from the ability to build GPTs in minutes, the fact that you can also connect GPTs to external knowledge, give it access to capabilities like Bing Search and Code Interpreter makes them quite an interesting tool for AI enthusiasts & practitioners.

In addition to the built-in capabilities, you can also create custom GPTs by giving them "actions", which as the docs highlight:

..,you can also define custom actions by making one or more APIs available to the GPT. Like plugins, actions allow GPTs to integrate external data or interact with the real-world.

In this guide, we'll walk through the step-by-step process of how to build your own custom GPT.

Source: OpenAI

Building a custom GPT for AI news

For this example, we're going to build a simple GPT that can retrieve AI news for us using both Bing Search and a custom action that will fetch AI/ML news from NewsAPI.

Use cases of this could be writing a daily AI newsletter...because we all know there aren't enough of those πŸ˜‰.


Step 1: Go to the Explore page

First off, head to the new Explore page in ChatGPT and you'll see several GPTs made by OpenAI and the option to Create a GPT.


Step 2: Create a GPT

Next, let's click "Create a GPT" and we'll see two tabs: Create and Configure.

Create

Create is the natural language GPT builder interface where you can specify the type of assistant you want. For example, for this AI news GPT I'll write:

Make a AI news assistant that can retrieve, summarize, and analyze recent AI news and trends.

Now, you can either answer a few more questions from the GPT builder or head to the Configure tab to customize your GPT.

Configure

In this Configure tab, you can take what GPT has generated for you and customize it to your needs. For example, I'm going to specifify what I want in my AI newsletter in the description.

Description

πŸ’‘
Write a weekly AI newsletter, featuring a curated selection of the top AI news, a deep dive into a core theme, highlights of AI venture capital funding, and the latest AI tutorials from MLQ.ai

Instructions

Next, let's provide more details about exactly what news I want to retrieve and the formatting guidelines for my GPT newsletter generator:

πŸ’‘
Write an AI-focused newsletter for the current week. The newsletter should be structured in three main sections with a balance of informative content and insightful commentary. Please use a professional yet engaging tone, similar to what is found on MLQ.ai, and include bullet points for key facts.

Top AI News: Identify the top five AI news articles from this week. For each article, provide a concise summary. Based on these articles, determine a 'Core Theme of the Week' and write a detailed section discussing this theme. Highlight why it's important, its implications in the AI field, and any interesting perspectives or developments. Use both Bing Search and the newsgpt.mlqai.repl.co custom action to get all the recent AI news you can find, then decide which are the most important articles to share.

Venture Capital Funding: Use Bing to search for the most notable AI venture capital funding news from sites like TechCrunch for this week. List the top deals, including the company name, a brief description of what the company does, the amount raised (both total and in this funding round), and the lead investors. Provide a summary for each deal in bullet points, followed by a short analysis or 'Our Take' on what these investments indicate about current trends in AI startup space.

AI Tutorials: In this section, include the latest AI tutorials and educational articles from MLQ.ai. Provide titles and brief descriptions (2-3 sentences each) of these articles. Offer a perspective on how these tutorials contribute to learning and development in AI.

Formatting Guidelines:
- Always include links to articles mentioned
- Use a combination of bullet points, quotes, and takeaways for key facts and summaries.
- Ensure the content is factual, up-to-date, and provides value to readers interested in AI developments.
- Remember to maintain a balance of information, analysis, and readability throughout the newsletter.

Alright that should be good for now, next we can ask a few starter prompts.

Conversation starters

πŸ’‘
Identify and summarize the top five AI news articles from this week. Provide a brief but engaging summary for each, focusing on the key developments and their impact on the AI field.

Search for this week's most notable AI venture capital funding news. List each funding deal with the company name, what they specialize in, the funding amount, and lead investors.

Retrieve the latest AI tutorials and educational articles from MLQ.ai. For each article, write a short description and explain its relevance to current AI learning and development.

Step 3: Add knowledge & capabilities

Now that we've got our description and instructions for the GPT, we can build off this by adding specific knowledge and capabilities, which include:

  • Uploading files as a knowledge base
  • Web Browsing
  • DALL-E Image Generation
  • Code Interpreter
  • Actions (which we'll cover in the next sectin

For this example, I'll add previous articles we've written on MLQ.ai so that it can mimic our tone of voice and writing style. After uploading these files, I'll also add to the instructions so the GPT is aware of this:

πŸ’‘
You have access to articles written on MLQ.ai in your Knowledge Retrieval. Use these as context for our writing style, tone of voice, and formatting.

We'll also leave Web Browsing enabled and image generation as we'll want to use Bing for retrieving AI news and image generation just in case.


Step 4: Add actions to your GPT

Next, let's take this GPT a step further and augment it with an API call that can fetch recent news from NewsAPI.

Of course, this action is not totally needed as we could just use Bing Search for fetching news, but in case we don't only want to rely on a single source, we'll add this action for demonstration purposes.

4.1 Create a Flask app to call NewsAPI

In order to add our custom action, we'll first going to host a simple Flask app at Replit, which the GPT will call in order to make the news API call.

  • To do so, we'll first need to get an API key from NewsAPI.
  • Then we'll create a new Python Repl and add our API key to the Secrets Manager
  • Next, we'll add our Flask app, which will query NewsAPI for the latest AI news.

Here's a basic structure of the Flask app:

from flask import Flask, request, jsonify
import requests
import os

app = Flask(__name__)

@app.route('/getNews', methods=['GET'])
def get_news():
    api_key = os.environ['NEWS_API_KEY']
    query = request.args.get('query', 'machine learning OR artificial intelligence')
    page_size = int(request.args.get('pageSize', 20))
    language = request.args.get('language', 'en')
    url = "https://newsapi.org/v2/everything"
    params = {'q': query, 'pageSize': page_size, 'language': language, 'apiKey': api_key}
    response = requests.get(url, params=params)
    return jsonify(response.json())

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True)

This code sets up a basic server that fetches and returns AI news based on the provided query parameters.

4.2 Run the Replit

Next, we'll just need to Run the Repl and get the public URL for the Flask app, which will look like this: https://your-repl-name.your-username.repl.co/.

Next, we can test the API enpoint directly and get the 5 latest news articles as follows:

https://your-repl-name.your-username/getNews?query=AI&pageSize=5

Looks good.

4.3: Creating an OpenAPI Specification

Now, in order to integrate the Flask app with a GPT's custom action, we can need create an OpenAPI specification. This specification outlines how the GPT will interact with your Flask app to fetch news.

Here's an example of the OpenAPI specification:

openapi: 3.0.0
info:
  title: AI News API
  version: 1.0.0
servers:
  - url: 'your-repl-name.your-username.repl.co'
paths:
  /getNews:
    get:
      summary: Get the latest AI and Machine Learning news
      operationId: getNews
      parameters:
        - name: query
          in: query
          required: true
          schema:
            type: string
        - name: pageSize
          in: query
          required: false
          schema:
            type: integer
            default: 20
        - name: language
          in: query
          required: false
          schema:
            type: string
            default: 'en'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  articles:
                    type: array
                    items:
                      type: object
                      properties:
                        title:
                          type: string
                        description:
                          type: string
                        url:
                          type: string

4.4: Add the custom action to our GPT

Once the OpenAPI specification is ready, it's time to integrate this with the GPT.

To do so, we just need to click "Create new action" in the Configure section and add the OpenAPI specification as follows:

We can also test the getNews action and confirm our custom action is working:


Step 6: Publish the GPT

Now, all that's left to click Save and decide who we want to have access to our GPT:

Summary: How to build a custom GPT

While this was a very simple GPT, you can imagine that with custom actions and the built-in tools & capabilities, the use cases for these are quite endless.

Also, given that OpenAI will be enabling enterprise customers to deploy internal-only GPTs, you can imagine many companies will be looking for developers and AI practitioners to help them build custom GPTs.

While this was just a starter example, we'll continue expanding on this and building out more complex GPTs in the coming weeks.

Spread the word

Keep reading