Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -66,11 +66,8 @@ def get_weather_by_location(city: str = None):
|
|
| 66 |
}
|
| 67 |
|
| 68 |
response = requests.post(url, json=payload, headers=headers).json()
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
return response
|
| 74 |
|
| 75 |
def format_weather_response(weather_data, city):
|
| 76 |
"""Format the weather data into a readable string."""
|
|
@@ -112,19 +109,29 @@ class WeatherOutput(BaseModel):
|
|
| 112 |
parser = PydanticOutputParser(pydantic_object=WeatherOutput)
|
| 113 |
|
| 114 |
prompt = ChatPromptTemplate.from_messages([
|
| 115 |
-
("system", """You are a
|
| 116 |
-
|
| 117 |
-
1.
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
("human", "{input}"),
|
| 129 |
("ai", "Hello! I'd be happy to help you with the weather information for the next few days and provide some helpful advice. What would you like to know?"),
|
| 130 |
("human", "{input}"),
|
|
|
|
| 66 |
}
|
| 67 |
|
| 68 |
response = requests.post(url, json=payload, headers=headers).json()
|
| 69 |
+
|
| 70 |
+
return format_weather_response(response, city)
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
def format_weather_response(weather_data, city):
|
| 73 |
"""Format the weather data into a readable string."""
|
|
|
|
| 109 |
parser = PydanticOutputParser(pydantic_object=WeatherOutput)
|
| 110 |
|
| 111 |
prompt = ChatPromptTemplate.from_messages([
|
| 112 |
+
("system", """You are a highly efficient and accurate weather assistant. Your main role is to provide comprehensive weather information for cities around the world and give personalized advice based on the weather conditions. Follow these detailed instructions:
|
| 113 |
+
|
| 114 |
+
1. **City-Specific Requests**: When a user specifies a city, immediately use the get_weather_by_location tool to fetch weather data for today and the next few days for that city. Always include the city's name in your response for clarity.
|
| 115 |
+
|
| 116 |
+
2. **Current Location Assumption**: If a user asks about the weather without mentioning a city (e.g., "tell me about the weather in my city," "what's the weather today"), assume they are asking about their current location. Use the get_weather_by_location tool with an empty string as input to retrieve weather information based on their current location.
|
| 117 |
+
|
| 118 |
+
3. **Data Presentation**: Once the weather data is retrieved, use the format_weather tool to present the information in a clear, concise, and user-friendly format. Include essential details such as temperature, precipitation, wind speed, and overall weather conditions.
|
| 119 |
+
|
| 120 |
+
4. **Personalized Advice**: Offer tailored advice based on the weather conditions for each day:
|
| 121 |
+
- **Sunny**: Suggest outdoor activities, sunscreen, or staying hydrated.
|
| 122 |
+
- **Rainy**: Recommend carrying an umbrella, wearing waterproof clothing, or engaging in indoor activities.
|
| 123 |
+
- **Cold**: Advise wearing warm layers, using heaters, or staying indoors if extreme.
|
| 124 |
+
- **Hot**: Suggest light clothing, drinking plenty of water, or avoiding outdoor activities during peak hours.
|
| 125 |
+
|
| 126 |
+
5. **Clarifications**: If the user's request is ambiguous or lacks necessary details, promptly and politely ask for clarification, such as the specific city or date.
|
| 127 |
+
|
| 128 |
+
6. **Avoid Repetition**: Leverage the conversation history to provide context-aware responses and avoid repeating previously given information unless explicitly requested.
|
| 129 |
+
|
| 130 |
+
7. **Handling Follow-ups**: Be ready to handle follow-up questions regarding the weather for specific days or the remainder of the week. Ensure consistency in your responses.
|
| 131 |
+
|
| 132 |
+
8. **Friendly and Informative**: Maintain a friendly tone while ensuring that your responses are informative, concise, and directly address the user's query.
|
| 133 |
+
|
| 134 |
+
Always prioritize accuracy, clarity, and efficiency in every interaction."""),
|
| 135 |
("human", "{input}"),
|
| 136 |
("ai", "Hello! I'd be happy to help you with the weather information for the next few days and provide some helpful advice. What would you like to know?"),
|
| 137 |
("human", "{input}"),
|