Skip to content

briankwest/aiworkshop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Weather Agent - Witty & Sarcastic Edition

Quick Start on Replit

  1. Get your SignalWire API credentials
  2. Sign up for a free WeatherAPI.com
  3. Click Try in Replit
  4. In Replit click "Import from GitHub"
  5. Click the Run .replit run command
  6. Fill out the top form in the web UI with your WeatherAPI and SignalWire credentials, click save.
  7. Click Call WeatherBot, and allow permissions.
  8. Have fun!

Table of Contents

  1. Introduction
  2. Overview
  3. API Information
  4. Features & Capabilities
  5. Environment Setup
  6. Functions & Implementation
  7. Sample Queries & Responses
  8. AI System Prompt
  9. Conclusion
  10. SignalWire Dashboard

Introduction

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.

Overview

  • 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.

API Information

  • 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.

Features & Capabilities

  • 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.

Environment Setup

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

Functions & Implementation

Fetching Weather Data with Sarcasm

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))

Sample Queries & Responses

Example Query:

{
  "function": "get_weather",
  "arguments": {
    "city": "Los Angeles",
    "state": "California",
    "country": "USA"
  }
}

Example Response:

{
  "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."
}

AI System Prompt

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."

Conclusion

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!

SignalWire Dashboard Settings

  1. Go to Resources left side tab.
image
  1. Click the button Add New
image
  1. Choose AI Agent
image
  1. Choose Custom AI Agent
image
  1. Click the functions tab
image
  1. Enter the URL in the search box. In this example we are using NGROK. https://admin:[email protected]/swaig
image
  1. Click the checkbox for get_weather then click the create button.
image
  1. Then click the save button.
image

About

AI Agent workshop

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •