DareAlly-Assistant / weather-time-data.py
Darrae's picture
Update weather-time-data.py
996865d verified
import requests
import os
WEATHER_API_KEY = os.environ.get('WEATHER_API_KEY')
def weather_api(location):
url = f"http://api.openweathermap.org/data/2.5/weather?q={location}&appid={WEATHER_API_KEY}"
response = requests.get(url)
return response.json()
def time_api(location):
url = f"http://worldtimeapi.org/api/timezone/{location}"
response = requests.get(url)
return response.json()
def date_api(location):
url = f"http://worldtimeapi.org/api/timezone/{location}"
response = requests.get(url)
return response.json()
def get_weather_details(text):
function_object = [
{
"type": "function",
"function": {
"name": "weather_details",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "the location for which the weather information is requested"
}
},
"required": ["location"]
},
"instructions": "Extract the location from the user's question and call the weather API."
}
}
]
response = chat_openai.function_call(text, function_object)
location = response['arguments']['location']
weather_info = weather_api(location)
return weather_info
def get_time_details(text):
function_object = [
{
"type": "function",
"function": {
"name": "time_details",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "the location for which the time information is requested"
}
},
"required": ["location"]
},
"instructions": "Extract the location from the user's question and call the time API."
}
}
]
response = chat_openai.function_call(text, function_object)
location = response['arguments']['location']
time_info = time_api(location)
return time_info
def get_date_details(text):
function_object = [
{
"type": "function",
"function": {
"name": "date_details",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "the location for which the date information is requested"
}
},
"required": ["location"]
},
"instructions": "Extract the location from the user's question and call the date API."
}
}
]
response = chat_openai.function_call(text, function_object)
location = response['arguments']['location']
date_info = date_api(location)
return date_info