LangChain Weather Assistant ๐ŸŒฆ๏ธ

LangChain aur OpenWeatherMap ke Saath ๐ŸŒค๏ธ

Pyaare Developers! Aaj hum ek cool Weather Assistant banayenge jo LangChain aur OpenWeatherMap API ka use karke real-time mausam ka data laata hai. Yeh project dikhata hai ki kaise AI aur open APIs milkar ek smart assistant create kar sakte hain!

๐Ÿงฉ Prerequisites

Step 1: Installation โš™๏ธ

Sabse pehle, zaruri libraries install karein:

pip install langchain pyowm

Step 2: API Key Setup ๐Ÿ”‘

OpenWeatherMap se API key lein:

Step 3: Code Implementation ๐Ÿ’ป

from langchain_community.document_loaders import WeatherDataLoader
from langchain_community.utilities import OpenWeatherMapAPIWrapper
import os

# API Key set karo
os.environ["OPENWEATHERMAP_API_KEY"] = "your_api_key_here"

# Weather Wrapper initialize karo
weather_wrapper = OpenWeatherMapAPIWrapper()

# Weather data retrieve karne ka function
def get_weather_info(city):
    try:
        # City ke liye weather data fetch karo
        weather_data = weather_wrapper.run(city)
        return weather_data
    except Exception as e:
        return f"Error: {str(e)}"

# Main function
def weather_assistant():
    print("๐ŸŒฆ๏ธ Namaste! Main aapka Mausam Assistant hoon!")
    
    while True:
        city = input("\nKis city ka mausam jaanna chahte hain? (Exit ke liye 'quit' type karein): ")
        
        if city.lower() == 'quit':
            print("Alvida! Phir milenge!")
            break
        
        weather_info = get_weather_info(city)
        print(f"\n{city} ka Mausam Report:\n{weather_info}")

# Assistant start karo
if __name__ == "__main__":
    weather_assistant()

๐Ÿง  Deep Dive: Code Explanation

get_weather_info(): city ke liye data fetch karta hai aur exceptions handle karta hai.

weather_assistant(): continuous user loop hai jisme city input liya jata hai aur result print hota hai.

๐Ÿš€ Advanced Features To Try

๐Ÿ’ก Best Practices

๐Ÿงฉ Challenges & Solutions

๐ŸŽฏ Conclusion

Bas itna sa effort lagake aapne ek powerful weather assistant bana liya! ๐ŸŒฆ๏ธ Yeh project dikhata hai ki kaise AI aur Open APIs ko combine karke practical, real-world solutions banaye ja sakte hain. Ab aap apna AI-based weather chatbot aur advanced bana sakte ho!

โ† Back to LangChain Tutorials