Weather Man
This example shows how to build a simple weather assistant that uses Pine to get current weather information and OpenAI to generate natural responses.
How It Works
-
User Question The assistant receives a natural language weather question like “Should I take a jacket in London today?”
-
Get Weather Context Pine’s API analyzes the question and returns relevant real-time weather information formatted as LLM-ready context.
-
Combine with LLM The weather context is passed along with the original question to OpenAI’s API, which generates a natural language response.
Step 1: Set API Keys
For this example you will need both a Pine API Key and an OpenAI API Key. After getting the keys, put them into environment variables or directly into your python code.
Step 2: Install Dependencies
For this example we will need openai
and requests
package.
Step 3: Get Context from Pine
We write a function which calles the Pine Context API, and returns the context:
Step 4: Ask OpenAI with Context
We write a function which promps OpenAI to answer our query with Pine’s weather context:
Step 5: Putting Together
We now combine our functions,
Final Script
The script should look like,
You can now run the script via:
Sample Responses
“What days this should I wear a jacket in NYC?”
“How much snow did Mammoth get in the past couple days?”