Skip to content

Commit

Permalink
feat: add sample genai_agent notebook and tool
Browse files Browse the repository at this point in the history
  • Loading branch information
kmaphoenix committed Jul 10, 2024
1 parent 3511d12 commit 926d3fb
Show file tree
Hide file tree
Showing 2 changed files with 859 additions and 0 deletions.
54 changes: 54 additions & 0 deletions data/get_weather_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import logging
import requests
from google.auth import default as google_default_auth
from google.auth.transport.requests import Request as GoogleRequest
from flask import Flask, request
from firebase_admin import initialize_app
from firebase_functions import https_fn


initialize_app()
app = Flask(__name__)

# Set up logging
logging.basicConfig(level=logging.INFO)

# Google Auth
creds, project = google_default_auth()
auth_req = GoogleRequest()

def get_request_params(param, default=None):
request_json = request.get_json(silent=True)
request_args = request.args

return (request_json or {}).get(param, default) or request_args.get(param, default)

@app.route("/get_weather_grid", methods=["GET", "POST"])
def get_weather_grid():
lat = get_request_params("latitude")
long = get_request_params("longitude")

url = f"https://api.weather.gov/points/{lat},{long}"
response = requests.get(url)
logging.info(f"FIRST RESPONSE: {response}")
if response.status_code == 200:
data = response.json()
logging.info(f"FIRST RESPONSE DATA: {data}")

response = requests.get(data["properties"]["forecast"])
logging.info(f"SECOND RESPONSE: {response}")
if response.status_code == 200:
data = response.json()
logging.info(f"SECOND RESPONSE DATA: {data}")

# just take the weather from the current period
period = data["properties"]["periods"][0]
return {"temperature": period["temperature"], "temperatureUnit": period["temperatureUnit"]}

return {}

@https_fn.on_request()
def main(req: https_fn.Request) -> https_fn.Response:
creds.refresh(auth_req)
with app.request_context(req.environ):
return app.full_dispatch_request()
Loading

0 comments on commit 926d3fb

Please sign in to comment.