myspace134v / modules /context_enhancer.py
rdune71's picture
Update with enhanced AI Research Assistant - streaming output, 8192 tokens, improved UI
001a1f0
import aiohttp
import os
from datetime import datetime
async def add_weather_context(location="London"):
try:
api_key = os.getenv("OPENWEATHER_API_KEY")
if not api_key:
return "Weather data unavailable (API key not configured)"
url = f"http://api.openweathermap.org/data/2.5/weather?q={location}&appid={api_key}&units=metric"
async with aiohttp.ClientSession() as session:
async with session.get(url, timeout=5) as response:
response.raise_for_status()
data = await response.json()
return f"Current weather in {location}: {data['weather'][0]['description']}, {data['main']['temp']}°C"
except Exception as e:
return f"Weather data unavailable: {str(e)}"
async def add_space_weather_context():
try:
api_key = os.getenv("NASA_API_KEY")
if not api_key:
return "Space weather data unavailable (API key not configured)"
url = f"https://api.nasa.gov/planetary/apod?api_key={api_key}"
async with aiohttp.ClientSession() as session:
async with session.get(url, timeout=5) as response:
response.raise_for_status()
data = await response.json()
return f"Space context: Astronomy Picture of the Day - {data.get('title', 'N/A')}"
except Exception as e:
return f"Space weather data unavailable: {str(e)}"
def add_time_context():
now = datetime.now()
return f"Current date and time: {now.strftime('%Y-%m-%d %H:%M:%S %Z')}"