SyedHasanCronosPMC commited on
Commit
b3720e5
·
verified ·
1 Parent(s): 2bf2299

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -18
app.py CHANGED
@@ -11,24 +11,32 @@ load_dotenv()
11
  openai.api_key = os.getenv("OPENAI_API_KEY1")
12
 
13
  # Define function to get current weather
14
- def get_current_weather(location, unit='celsius'):
15
- weather_api_key = os.getenv("WEATHER_API_KEY")
16
- base_url = f"http://api.openweathermap.org/data/2.5/weather?q={location}&appid={weather_api_key}&units=metric"
17
- try:
18
- response = requests.get(base_url, timeout=10) # Increased timeout for the request
19
- response.raise_for_status() # Check if the request was successful
20
- data = response.json()
21
- weather_description = data['weather'][0]['description']
22
- return {
23
- "location": location,
24
- "temperature": data['main']['temp'],
25
- "weather": weather_description
26
- }
27
- except requests.exceptions.Timeout:
28
- return {"error": "Request timed out. Please try again later."}
29
- except requests.exceptions.RequestException as e:
30
- print(f"Request failed: {e}")
31
- return {"error": str(e)}
 
 
 
 
 
 
 
 
32
 
33
  # Function definition and initial message handling
34
  def weather_chat(user_message):
 
11
  openai.api_key = os.getenv("OPENAI_API_KEY1")
12
 
13
  # Define function to get current weather
14
+ {
15
+ "name": "get_weather",
16
+ "description": "Determine weather in my location",
17
+ "strict": true,
18
+ "parameters": {
19
+ "type": "object",
20
+ "properties": {
21
+ "location": {
22
+ "type": "string",
23
+ "description": "The city and state e.g. San Francisco, CA"
24
+ },
25
+ "unit": {
26
+ "type": "string",
27
+ "enum": [
28
+ "c",
29
+ "f"
30
+ ]
31
+ }
32
+ },
33
+ "additionalProperties": false,
34
+ "required": [
35
+ "location",
36
+ "unit"
37
+ ]
38
+ }
39
+ }
40
 
41
  # Function definition and initial message handling
42
  def weather_chat(user_message):