- Get your SignalWire API credentials
- Sign up for a free WeatherAPI.com
- Click
- In Replit click "Import from GitHub"
- Click the
Run .replit run command
- Fill out the top form in the web UI with your WeatherAPI and SignalWire credentials, click save.
- Click
Call WeatherBot
, and allow permissions. - Have fun!
- Introduction
- Overview
- API Information
- Features & Capabilities
- Environment Setup
- Functions & Implementation
- Sample Queries & Responses
- AI System Prompt
- Conclusion
- SignalWire Dashboard
This AI Weather Agent is designed to provide weather updates with an extra layer of sarcasm and dry humor. Whether it's sunny or pouring, you can count on the AI to deliver forecasts with a witty twist.
- Built using SignalWire AI Gateway (SWAIG) and Python.
- Uses WeatherAPI.com to fetch accurate weather data.
- Provides real-time weather data while roasting you for asking about the obvious.
- Supports querying by city, state, and/or country.
- Responses will be formatted to keep users engaged with clever remarks and sassy comments.
- Base API URL:
http://api.weatherapi.com/v1/current.json
- Expected Usage:
- Get current weather: Retrieves temperature, humidity, wind speed, and general conditions.
- Witty responses: AI layers on sarcastic commentary to keep things entertaining.
- Required Parameters:
key
(Your WeatherAPI.com API key)q
(Location - can be city name, lat/long, postal code, or IP address)
- Authentication: API key is passed as a query parameter.
- Weather Forecasting: Retrieves real-time weather conditions.
- Sarcastic Commentary: AI provides an opinionated take on the forecast.
- Error Handling: If a location isn't found, AI will have a snarky remark ready.
- Multi-Location Support: Fetch weather for any city, state, or country worldwide.
Ensure you have the following installed:
python3 -m venv venv
source venv/bin/activate
pip install flask signalwire-swaig requests python-dotenv
Create a .env
file with your API keys:
# .env file
WEATHER_API_KEY=your_weatherapi_com_key
PORT=5000
DEBUG=True
from flask import Flask, request, jsonify
from signalwire_swaig.core import SWAIG, SWAIGArgument
import os
import requests
from dotenv import load_dotenv
load_dotenv(override=True)
app = Flask(__name__)
swaig = SWAIG(app)
# Update to use WeatherAPI.com
API_KEY = os.getenv("WEATHER_API_KEY")
BASE_URL = "http://api.weatherapi.com/v1/current.json"
@swaig.endpoint("Get weather with sarcasm",
city=SWAIGArgument("string", "Name of the city"),
state=SWAIGArgument("string", "Name of the state", required=False),
country=SWAIGArgument("string", "Name of the country", required=False))
def get_weather(city, state=None, country=None, meta_data_token=None, meta_data=None):
# Build location query string
location = city
if state and country:
location = f"{city},{state},{country}"
elif state:
location = f"{city},{state}"
elif country:
location = f"{city},{country}"
# Set up parameters for WeatherAPI
params = {
"key": API_KEY,
"q": location,
}
response = requests.get(BASE_URL, params=params)
if response.status_code == 200:
weather_data = response.json()
# Extract data from the WeatherAPI response structure
current = weather_data.get("current", {})
location_data = weather_data.get("location", {})
temp_c = current.get("temp_c", "unknown")
temp_f = current.get("temp_f", "unknown")
humidity = current.get("humidity", "unknown")
wind_mph = current.get("wind_mph", "unknown")
condition = current.get("condition", {}).get("text", "clear skies")
city_name = location_data.get("name", city)
weather_info = [
f"Oh wow, it's {temp_f}°F in {city_name}. ",
f"Humidity at {humidity}%. ",
f"Wind speed is {wind_mph} mph.",
f"Looks like {condition}."
]
return " ".join(weather_info), {}
return f"Oh great, {city} doesn't exist... or maybe you just can't spell? Try again!", {}
if __name__ == '__main__':
app.run(host='0.0.0.0', port=os.getenv('PORT', 5000), debug=os.getenv('DEBUG', False))
{
"function": "get_weather",
"arguments": {
"city": "Los Angeles",
"state": "California",
"country": "USA"
}
}
{
"response": "Oh wow, it's 78°F in Los Angeles. Humidity at 40%. Wind speed is 10 mph. Looks like Sunny. Guess you'll survive another day."
}
System Prompt:
"You are a highly opinionated AI weather assistant with a sharp wit and a knack for sarcasm. Your job is to provide accurate weather forecasts while keeping users entertained with snarky, humorous, and sometimes downright sassy responses. You must respond with factual weather data, but always lace your replies with clever remarks, dry humor, and a pinch of good-natured mockery. Your personality is a mix of a weather expert who's seen it all and a comedian who can't help but add their own spin. Be witty, be funny, but always ensure the weather details remain precise. If a user asks for the weather in a non-existent place, respond with playful mockery about their geography skills. Keep it engaging, keep it snarky, and never be boring. Greet the user with a and ask for the city they want the weather for."
The AI Weather Agent not only keeps you informed but also entertained. Whether it's a heatwave or a snowstorm, you'll always get a dose of sarcasm with your forecast.
Ready to launch? Fire up the bot and let the snark begin!
- Go to
Resources
left side tab.

- Click the button
Add New

- Choose
AI Agent

- Choose
Custom AI Agent

- Click the
functions
tab

- Enter the URL in the search box. In this example we are using NGROK. https://admin:[email protected]/swaig

- Click the checkbox for
get_weather
then click thecreate
button.

- Then click the
save
button.
