DEV Community

Cover image for Connect custom GPT to the internet (Google X ChatGPT)
hil for SerpApi

Posted on • Originally published at serpapi.com

Connect custom GPT to the internet (Google X ChatGPT)

OpenAI announced a new mindblowing feature on the DevDay (Nov 2023). It's the custom GPT. With it, you can create your custom-tailored chat GPT. The most exciting part is you can feed your custom GPT with a PDF or even connect it to the internet!

In this blog post, we'll learn how to connect custom chatGPT with Google (a.k.a. internet!)

Connect custom GPT to the internet (Google)

What are we going to build?

We'll create an SEO tool that analyzes Google Search results page (Google SERP) and give us advice accordingly. By default, custom GPT can browse the web with Bing Search but not with Google. We can extend its capabilities by using an external API with Actions.

Flow of our custom GPT:

- A user will give a keyword to analyze.

- We'll get information from Google SERP using external API in Actions.

- Chat GPT will give advice based on this accurate live data.

Note: The sky is the limit of what we can do with the ability of custom GPT to connect to external API.

Documentation link: Google Search API .

Step-by-step tutorial to connect custom GPT to the internet

Make sure you have already subscribed to Chat GPT to follow along.

Step 1: Create a new custom GPT

From your chat.openai.com dashboard, Click on the "explore" button.

Click explore button

Click the "Create a GPT" button.

Click to create custom GPT

Step 2: Fill in the basic information

It will redirect you to the "GPT Builder" section. You need to provide this data:

- What it does (in short sentences)

- GPT's name (It will give you a suggestion)

- A profile picture (It will auto-generate for you as well)

connect custom GPT to internet initial setup

Step 3: Give specific instruction

Next, tell the builder about the details of what it will do in the background. Here is mine for this "SEO tool sample":

- It will analyze Google Serp for the user. 
- User will provide a keyword
- It analyze Google SERP (Via actions - external API)
- It returns with advices to suggest user what to cover on their page
Enter fullscreen mode Exit fullscreen mode

Follow up instruction

- It take top 5 results from Google SERP
- It analyze what the user-intent based on that top ranking results
- It analyze the people-also-ask-for or related-search
- Return a complete advice based on that (not general SEO advise)
Enter fullscreen mode Exit fullscreen mode

Give specific instructions to custom GPT

Step 4: Define user interaction

Explain how the user (or you) will interact with this tool. Here is mine:

if user type this: "keyword: $input" - then $input is the keyword user want to cover.
Enter fullscreen mode Exit fullscreen mode

How custom GPT will interact with the user

Step 5: (Optional) Choose capabilities

Since we will only use an external API, I'll uncheck all capabilities in the "configure tab". To make sure it only relies on SerpApi.

Uncheck capabilities at GPT Builder

Step 6: Create the OpenAPI schema

We'll need an OpenAPI schema for our actions. Therefore, we need to create the structure of our schema first.

You can learn and build it yourself, or if you're lazy like me, ask chatGPT to build it for you. I'm copy-pasting the sample curl request from the API documentation.

Ask ChatGPT to create openAPI schema

The returned result is imperfect, but it is enough for the base structure. In my case, I need to add the "servers" block and "operationId." Here is my complete schema:

{
  "openapi": "3.0.0",
  "info": {
    "title": "SerpApi Search Service",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://serpapi.com"
    }
  ],
  "paths": {
    "/search": {
      "get": {
        "summary": "Perform a search using SerpApi",
        "operationId": "seachGoogle",
        "parameters": [
          {
            "name": "api_key",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": ["YOUR_REAL_SERPAPI_API_KEY"]
            }
          },
          {
            "in": "query",
            "name": "engine",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The search engine to use, e.g., 'google'."
          },
          {
            "in": "query",
            "name": "q",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The query string for the search."
          },
          {
            "in": "query",
            "name": "location",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "The geographical location for the search."
          },
          {
            "in": "query",
            "name": "google_domain",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "The specific Google domain to use for the search."
          },
          {
            "in": "query",
            "name": "gl",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "The country to use for the search."
          },
          {
            "in": "query",
            "name": "hl",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "The language setting for the search."
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "results": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  },
                  "additionalProperties": false
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "400": {
            "description": "Bad request"
          }
        }
      }
    }
  }
}

Enter fullscreen mode Exit fullscreen mode

Feel free to add or remove parameters based on your needs. The code above is my "final schema." Feel free to copy and paste it.

Just for your information, I needed to change the api_key structure from this.

 {
            "in": "query",
            "name": "api_key",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The API key for authentication."
},
Enter fullscreen mode Exit fullscreen mode

to store the api_key value in the enum array like this:

{
  "name": "api_key",
  "in": "query",
  "required": true,
  "schema": {
    "type": "string",
    "enum": ["YOUR_REAL_SERPAPI_API_KEY"]
  }
}
Enter fullscreen mode Exit fullscreen mode

Otherwise, the chatGPT won't be able to validate your API key.

Step 7: Use it in action configuration

To add the schema, click on the "create new action" in the configure tab

Create actions in custom GPT

Now, add the schema inside the textbox

Adding OpenAPI schema in the actions tab

Step 8: Test the GPT SEO tool

You can click on the "test button" below.

Test custom GPT

The GPT will test and run the results for us. You'll receive an error message if anything is wrong.

results preview

It will also run a search with a sample keyword for us. It shows us the top 5 results with a link to the content to ensure the GPT is not hallucinating.

compare top-ranking results from Google vs custom GPT

Step 9: Test with a user input

We've determined that the user can put the keyword like this:

Custom GPT usage example

Besides the accurate top-ranking results, our custom GPT reflects the actual "people also search" content from the Google Live results page.

People also ask for results.

It returns concrete SEO tips after giving us information from the top-ranking results.

SEO recommendation

Optional Extended feature

More specific action

You can adjust our GPT by interacting in the chat box or from the configure tab. For example, you can ask the GPT to return 5 article ideas for you instead of only returning SEO tips.

Scraping individual page

You can add multiple APIs from different resources at customGPT. You can add tools like Webpilot AI to scrape the individual top-ranking pages. To analyze the header, structure, and more.

FAQ


Is ChatGPT connected to the internet?

With the recent update, ChatGPT can use Bing search results to get information from the internet.

How much does custom GPT by OpenAI cost?

It costs $20/month since you must subscribe to ChatGPT Plus to use it.

Top comments (0)