Open Weather API (and Chat GPT)

Unfortunately I still can’t seem to get this to work. For some reason the response from chatgpt is not being populated in my variable. The rule logs does not show anything in particular that could be causing this. But I tested the payload content in the API playground and the result was expected i.e. I got a weather report back so the message is being parsed over correctly. I also see the api key usage is being hit so the http call is making it there but for whatever reason the result is not making it back.

I’m going to try on postman to see if I get any errors back.

The HTTP Action Troubleshooting article has some helpful tips that you might be interested in:

Thanks Josh. I use http calls for other things but I’ll look into the article you sent. I’ll share a snippet of my rule as well just in case I’m doing something wrong.

Edit - So this is working with Postman but with Sharptools rule, I am unable to get the response into my variable.

Edit 2 - I got this working…silly mistake…I had no space between bearer and my token.

@josh - thanks for pointing me to that http troubleshooting guide. I created a new variable to catch the response.status which generated a 401 and led me to reviewing the auth headers…

So I discovered that ChatGPT is not looking at tomorrows weather data in the JSON response and instead is looking at todays data. Any idea how I can explain to ChatGPT that it needs to look at the data with tomorrows timestamp? Or maybe how I can exclude the current day in the open weather api call? I’m already excluding current, hourly and minutely in my call.

Here is the weather json, it is the second section under daily that is tomorrow:

  "daily": [
        {
            "dt": 1703005200,
            "sunrise": 1702992290,
            "sunset": 1703024180,
            "moonrise": 1703009220,
            "moonset": 0,
            "moon_phase": 0.25,
            "summary": "There will be clear sky until morning, then partly cloudy",
            "temp": {
                "day": 21.88,
                "min": 21.76,
                "max": 31.93,
                "night": 31.84,
                "eve": 31.23,
                "morn": 22.3
            },
            "feels_like": {
                "day": 9.28,
                "night": 23.29,
                "eve": 21,
                "morn": 14.32
            },
            "pressure": 1022,
            "humidity": 73,
            "dew_point": 15.39,
            "wind_speed": 14.52,
            "wind_deg": 221,
            "wind_gust": 31.36,
            "weather": [
                {
                    "id": 803,
                    "main": "Clouds",
                    "description": "broken clouds",
                    "icon": "04d"
                }
            ],
            "clouds": 75,
            "pop": 0,
            "uvi": 0.71
        },
        {
            "dt": 1703091600,
            "sunrise": 1703078724,
            "sunset": 1703110604,
            "moonrise": 1703096820,
            "moonset": 1703053080,
            "moon_phase": 0.28,
            "summary": "Expect a day of partly cloudy with clear spells",
            "temp": {
                "day": 35.31,
                "min": 30,
                "max": 37.31,
                "night": 31.53,
                "eve": 32.07,
                "morn": 30.22
            },
            "feels_like": {
                "day": 35.31,
                "night": 25.66,
                "eve": 25.39,
                "morn": 24.57
            },
            "pressure": 1025,
            "humidity": 51,
            "dew_point": 19.18,
            "wind_speed": 9.6,
            "wind_deg": 215,
            "wind_gust": 23.11,
            "weather": [
                {
                    "id": 802,
                    "main": "Clouds",
                    "description": "scattered clouds",
                    "icon": "03d"
                }
            ],
            "clouds": 34,
            "pop": 0,
            "uvi": 1
        },

Here is my chatgpt text:

message = "Can you put together a two sentence forecast with the most relevant information from the following Open Weather API JSON response for tomorrow's weather? The units are imperial. Please keep the response concise and only include information if it is relevant. Any numerical values should be rounded to the nearest whole number.\\n\\nBefore generating a response, take a moment to internally (silently) think about the steps you would take to determine what information is relevant to include in the forecast. Ignore the provided 'summary' if one is included as I want you to generate your own.\\n\\nMake sure you find the correct value for dt where the UTC is tomorrow.\\n~~~\\n __WEATHER_JSON__ \\n~~~"
stringJson = stringify(stringify($context.response.data.daily[0]))
stringJson = substring(stringJson, 1, size(stringJson)-1)
replace(message, "__WEATHER_JSON__", stringJson)

Thanks for your insights

The second line in your expression is determining which of the fields to reference from the weather response.

$context.response.data.daily[0] is basically saying ‘Give me the first entry from the “daily” section of the response.’ (eg. today)

So you could change that to $context.response.data.daily[1] if you wanted tomorrow’s data.

Yes! That worked. Thanks so much.