Trying to actually get the weather

The weather example Action in creating a GPT is confusing me and probably because I do not know enough about OpenAPI. Here is the documentation API that does not require.a credit card or authentication:

https://www.weather.gov/documentation/services-web-api

I tried this schema but to no avail. I tried the “Test” button but the JSON does not appear to be formatted correctly. Any clues?

{
“openapi”: “3.1.0”,
“info”: {
“title”: “Get weather data”,
“description”: “Retrieves current weather data for a location.”,
“version”: “v1.0.0”
},
“servers”: [
{
“url”: “https://api.weather.gov
}
],
“paths”: {
“/points”: {
“get”: {
“description”: “Get temperature for a specific location”,
“operationId”: “GetCurrentWeather”,
“parameters”: [
{
“name”: “latitude”,
“in”: “query”,
“description”: “latitude”,
“required”: true,
“schema”: {
“type”: “string”
}
},
{
“name”: “longitude”,
“in”: “query”,
“description”: “longitude”,
“required”: true,
“schema”: {
“type”: “string”
}
}

    ],
    "deprecated": false
  }
}

},
“components”: {
“schemas”: {}
}

In your case, this path needs to exist:
https://api.weather.gov/points?latitude=<string>&longitude=<string>

Have you checked if it’s not actually like this:
https://api.weather.gov/points{latitude}/{longitude}

Here a description for each field:

{
  "openapi": "3.1.0",
  "info": {
    "title": <Title for the server>,
    "description": <Description of the server>,
    "version": "v1.0.0"
  },
  "servers": [
    {
      "url": "<server domain>"
    }
  ],
  "paths": {
    "/<the path for the api in the server>": {
      "get": {
        "description": "<the description of the api>",
        "operationId": "<the name to reference to the AI>",
        "parameters": [
          {
            "name": "<parameter>",
            "in": <"query" or "path">,
            "description": "<description of the parameter>",
            "required": <true or false>,
            "schema": {
              "type": <"string", "int" or "float">
            }
          }
        ],
        "deprecated": false
      }
    },
    "/<another path>": {
...
      }
    }
  },
  "components": {
    "schemas": {}
  }
}

Asking the AI to write latitudes and longitudes is also a stretch.

A heuristic city-name-to-location service might be useful.

If coordinates are successfully obtained, two calls are needed to that API.

  1. https://api.weather.gov/points/45.7456,-122.0892

  2. from that, extract the properties->forecast which has a URL for another link with the correct “point”, which also must be parsed.

https://api.weather.gov/gridpoints/PQR/134,110/forecast

2 Likes

I’ll try that but I think I need to better understand the OpenAPI spec first.

Thanks. The end point is: https://api.weather.gov/points/{latitude},{longitude}

What you specify as a function tool to the API is actually provided (after being rewritten to a different form) directly to the AI model.

It is the AI that must understand your function, and the AI must have the cognitive abilities to construct the response parameters you want to take and then employ in your backend code for communicating with the various APIs you need to fulfill the request with a return value.

Easy for the AI to write:
tools.functions.weather_forecast(“city”: “Los Angeles, CA”)

Hard for the AI to write:
tools.functions.weather_noaa_gridpoint(“field_office”: “PQR”, “forecast_grid”: “134,110”)

@paul.fishwick I was actually doing the same thing and found the weather.gov api to be a bit challenging for the reasons @_j pointed out (primary making two calls).

I found another free (for non-commercial use) service called Open-Meteo on Vand. Here’s both the OpenAPI and a function spec you can use with OpenAI models. (Open-Meteo Weather API - Vand.io).

Note that it still uses lat long as an input but I’ve found GPT 3.5 is able to do this reliably, at least for the major cities I’ve tried it with. Might be less accurate for small towns.

Thanks. Good point. In some ways, I find it easier to use the library methods/functions in an Assistant as contrasted with the Action schema. More control.

That is great. I’ll try now. On these schemas, while I completely understand how to formulate a REST API via curl or web browser, the challenge for me is getting from understanding the REST API to translating this into a JSON schema. In some conversations online, they use ChatGPT to generate the schema. I tried this but got OpenAI parser errors.

This is great. You share a great knowledge. I’ll try now.

I would suggest to avoid the use of latitude and longitude unless you have no other choice.

I would like to suggest this site weatherapi, their free tier is sufficient for us to test things out.

Query parameter based on which data is sent back. It could be following:

* Latitude and Longitude (Decimal degree) e.g: q=48.8567,2.3508
* city name e.g.: q=Paris
* US zip e.g.: q=10001
* UK postcode e.g: q=SW1
* Canada postal code e.g: q=G2J
* metar:<metar code> e.g: q=metar:EGLL
* iata:<3 digit airport code> e.g: q=iata:DXB
* auto:ip IP lookup e.g: q=auto:ip
* IP address (IPv4 and IPv6 supported) e.g: q=100.0.0.1
* By ID returned from Search API. e.g: q=id:2801268
* bulk New

Good idea to move forward with weatherapi using the query parameter

1 Like