This is a weather chatbot that uses the LangChain library, the OpenAI API and the OpenWeatherMap API to generate responses to weather-related user queries. A user interface is provided by a Dash web application that allows users to chat with the chatbot intuitively without any manual installations. The chatbot has been deployed on Render and can be accessed online by visiting iu-weather-chatbot.onrender.com.
No manual installation is required, and you can start chatting immediately!
You can visit the online chatbot here: iu-weather-chatbot.onrender.com
Warning
When accessing the online chatbot after a longer period of inactivity, you may need to wait for the server to start up. This can take up to 3 minutes. Therefore, please be patient and wait for the website to load.
Tip
For the best experience, use the chatbot on a desktop or laptop. Even though the chatbot is mobile-friendly, the UI is optimized for larger screens and some features are disabled to fit the smaller screen size of mobile devices.
Download the contents of the chatbot repository or clone it using the following command:
git clone https://github.com/chris-official/chatbot.git
cd chatbotIt is recommended to use Python=3.12. However, Python>=3.10 may also work but has not been tested.
Create a new virtual environment and activate it:
python -m venv chatbot_env
chatbot_env/Scripts/activate.bat # Linux: source chatbot_env/bin/activateAlternatively, you can use conda to create a new environment:
conda create --name chatbot_env python=3.12.4
conda activate chatbot_envInstall the required dependencies:
pip install -r requirements.txtOpen the .env file and add your OpenAI and OpenWeatherMap API key. You can get your OpenAI key
here and your OpenWeatherMap key
here. Finally, the file should look like this:
OPENAI_API_KEY="your_openai_api_key"
OPENWEATHERMAP_API_KEY="your_openweathermap_api_key"To start the chatbot interface on your machine, run app.py by executing the following command:
python app.pyThis will initiate a local server at http://127.0.0.1:8050.
To start chatting with the chatbot, simply open this URL in your browser.
Warning
When no API keys are provided, the chatbot will automatically start in offline mode and will not make any API calls. Instead, a default response will be displayed. For the chatbot to work properly, you must provide the API keys or visit the online chatbot.
The chatbot provides following functionalities:
- Weather Information: The chatbot can provide the current weather information and the weather forecasts for the next 7 days for a specific city. This includes the temperature, humidity, wind speed, cloudiness, UV index, and precipitation. This information is retrieved in real-time from the OpenWeatherMap API.
- Weather-related Queries: The chatbot can also answer more general weather-related queries based on the LLMs foundational knowledge.
- Offline Mode: When the chatbot is set up locally and no API keys are provided, the chatbot will run in offline mode and will not make any API calls. However, chat functionality is still available for testing purposes.
- Conversation Memory: The chatbot remembers the last 4 chat messages and can use them to generate more contextually relevant responses.
The UI offers four features:
- Chat Interface: The chat interface (middle) allows users to interact with the chatbot and displays the chat history. The chatbot can be reset at any time by refreshing the page.
- Prompt Examples: The examples column (left) provides some example prompts that users can ask the chatbot by simply clicking on them and submitting the query. This column is hidden on mobile devices.
- Weather Information: The weather information column (right) summarizes the requested weather information for the specified location for the next 7 days. The information is updated automatically as soon as the user interacts with the chatbot. This column is hidden on mobile devices.
- Theme Switch: The theme switch button in the top right corner allows users to switch between light and dark mode.
Note
The Prompt Examples and Weather Information columns are hidden on mobile devices to provide a better user experience on smaller screens.
- Select a prompt from the examples column or type a query in the chat interface. Your prompt should be a general weather-related question or address the weather in a specific location determined by the city name. In case of an ambiguous city name, you may need to provide the country or state as well. Otherwise, the chatbot will choose one location. The selected location is displayed at the top of the weather information column as soon as the chatbot has made a successful API call.
- Press the "Send" button or hit "Enter" to submit your query.
- Wait for the chatbot to generate a response.
- Keep the conversation going by asking more questions!
If you encounter any server related issues (Error code: 5XX), please check the server status on the Render Status Page for any ongoing incidents and try again later.
This project was developed as part of the course "Project: AI Use Case" at the International University of Applied Sciences (IU) and is not intended for use other than educational purposes.
- Dash Bootstrap Components
- Dash Chatbot Example
- Google Fonts
- LangChain Custom Tools
- LangChain OpenWeatherMap Tool
- LangChain OpenWeatherMap Wrapper
- LangChain Tool Calling Agents
- OpenWeatherMap API Docs
- OpenWeatherMap Geocoding API
- OpenWeatherMap Weather Condition Icons
- PyOWM Docs
- PyOWM GitHub
- Render Dashboard
- Render Web Service
- Robot Icon