Building GPTs and their data sources

A while ago, I started using ChatGPT and played around with building the usual prompt-based GPTs, so I have built bots with various personalities. My first attempt in building a data-driven GPT is the WeatherMaster which is just using the bing capability of ChatGPT to pull the weather report. Which is great if it works, but it seems that occasionally, the backend does not receive a valid answer depending on the question that was asked. But if it works, it’s a charming experience.

I then attempted to pull data from an external API but my first experiences were less encouraging. ChatGPT can define external actions, but is rather picky on how these are specified. Auto-discovering the specification by giving the URL was not great, so I wrote a little python script that queries the API. ChatGPT can run python, but the sandbox it runs python in has no access to the internet, so that did not work either. So I shelved the project for a while.

Today, I had a bit of time on my hands and I found that OpenAI has added a GPT as Advisor (called ActionGPT) that can be used to generate working specs. So this time, I moved my python script to my own server and explained to ActionGPT how to call it and what it does. And finally, everything works like a charm.

The GPT I have built now is an advisor for energy use, it basically tells you if it is a good idea to run your appliance now based on the energy source powering the grid right now. For this, I am pulling data from the Electricity Traffic Light built by Fraunhofer ISE. A simple python script pulls the traffic light data from their API and reformats it into simple english text that the models can understand.


This text describes what energy sources are currently used to generate electric energy in the grid.
Now is not the best time to run an appliance since the renewable share is average

The following text is a prediction for the next hours, it uses a simple traffic light scheme, the color of the traffic light indicates the renewable energy share.
At 16:45 the traffic light is yellow with 35.9 percent renewable share
At 17:00 the traffic light is yellow with 34.4 percent renewable share
At 17:15 the traffic light is red with 33.0 percent renewable share
At 17:30 the traffic light is red with 32.1 percent renewable share
At 17:45 the traffic light is red with 30.7 percent renewable share
At 18:00 the traffic light is red with 29.7 percent renewable share
At 18:15 the traffic light is red with 29.0 percent renewable share
At 18:30 the traffic light is red with 28.3 percent renewable share
At 18:45 the traffic light is red with 27.9 percent renewable share
At 19:00 the traffic light is red with 27.3 percent renewable share
At 19:15 the traffic light is red with 27.3 percent renewable share
At 19:30 the traffic light is red with 27.2 percent renewable share
At 19:45 the traffic light is red with 27.0 percent renewable share
At 20:00 the traffic light is red with 26.9 percent renewable share
At 20:15 the traffic light is red with 27.4 percent renewable share
At 20:30 the traffic light is red with 27.6 percent renewable share
At 20:45 the traffic light is red with 27.9 percent renewable share
At 21:00 the traffic light is red with 28.3 percent renewable share
At 21:15 the traffic light is red with 28.6 percent renewable share
At 21:30 the traffic light is red with 29.0 percent renewable share
At 21:45 the traffic light is red with 29.5 percent renewable share
At 22:00 the traffic light is red with 30.0 percent renewable share
At 22:15 the traffic light is red with 30.8 percent renewable share
At 22:30 the traffic light is red with 31.6 percent renewable share
At 22:45 the traffic light is red with 32.6 percent renewable share
At 23:00 the traffic light is red with 33.9 percent renewable share
At 23:15 the traffic light is red with 35.3 percent renewable share
At 23:30 the traffic light is yellow with 36.6 percent renewable share
At 23:45 the traffic light is yellow with 37.9 percent renewable share

The yaml specification that ActionGPT created had some extra parts that are ignored by the server, so they do not hurt. And it worked on the first try.

openapi: 3.0.0
info:
  title: Energy Advice Text Retrieval API
  description: This is an API to retrieve preformatted retrieval augmented generation text related to energy advice from the cubeos domain.
  version: 1.0.0
servers:
  - url: https://cubeos.org
    description: Main server
paths:
  /energy/getenergyadvice:
    get:
      operationId: retrieveEnergyAdviceText
      summary: Retrieve Energy Advice Text
      description: Retrieves a preformatted text of retrieval augmented generation related to energy advice.
      responses:
        '200':
          description: OK
          content:
            text/plain:
              schema:
                type: string

I have redacted the path since I am not planning to run a public free api endpoint for this, but you get the idea. On the server side, this is a simple python script that pulls the data from the energy traffic light API and reformats it as an English text. I’ll probably clean this up a little and put it on GitHub in the next days, maybe together with some instructions how to run this on Azure. I will also add some caching since the traffic light service only updates every 15 minutes so I don’t have to pull the data for every call.

This entry was posted in AI and tagged , , . Bookmark the permalink.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.