Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
42da921
Add AI weather explanations spec
Orinks Dec 8, 2025
6713fe5
feat: Implement AI weather explanations with OpenRouter integration
Orinks Dec 11, 2025
353b9dd
feat: integrate AI explanation button into weather display
Orinks Dec 11, 2025
83d71e2
fix: require OpenRouter API key for all requests including free models
Orinks Dec 11, 2025
f4cb91f
feat: add OpenRouter API key validation button
Orinks Dec 11, 2025
fe3f466
fix: use /api/v1/key endpoint for OpenRouter API key validation
Orinks Dec 11, 2025
0025553
fix: add openrouter_api_key to secure storage
Orinks Dec 11, 2025
30156bd
fix: apply AI settings to UI when settings dialog opens
Orinks Dec 11, 2025
4dca945
Fix: Explicitly pass API keys to update_settings in settings dialog
Orinks Dec 11, 2025
c365eef
Improve AI explanation error messages to include API response details
Orinks Dec 11, 2025
2c0bef9
Fix explanation dialog text not displaying
Orinks Dec 11, 2025
9da9601
Add detailed logging to diagnose empty explanation text issue
Orinks Dec 11, 2025
92c679e
Fix logging to write to ~/AccessiWeather_logs instead of cwd
Orinks Dec 11, 2025
453e753
Save logs to config_dir/logs instead of home directory
Orinks Dec 11, 2025
76aa745
Fix OpenRouter API: use reliable free models and increase max_tokens
Orinks Dec 11, 2025
107ebbe
Add Explain button to Area Forecast Discussion dialog
Orinks Dec 11, 2025
e1e094c
Include forecast data in weather explanation context
Orinks Dec 11, 2025
54d7511
Merge dev into feature/ai-weather-explanations, resolve conflicts
Orinks Dec 11, 2025
d08c50d
Fix SIM108 linting error - use ternary operator instead of if-else block
Orinks Dec 11, 2025
69ff2fe
feat(docs): Add complete project documentation suite
Orinks Dec 11, 2025
431b2e7
Add comprehensive tests for AI weather explanations feature
Orinks Dec 12, 2025
5ea4898
Improve LoadingDialog with ActivityIndicator
Orinks Dec 12, 2025
2290aa7
Add cancel button to LoadingDialog and clean up debug logging
Orinks Dec 12, 2025
47f1b23
Use built-in error dialogs, expand steering guide, update spec requir…
Orinks Dec 12, 2025
14b6051
Add initial accessibility focus to LoadingDialog
Orinks Dec 12, 2025
300f1b9
Fix AI explanations: update to working free models, add local time co…
Orinks Dec 12, 2025
49f2aa6
feat: Add AI prompt customization support (tasks 1-3)
Orinks Dec 12, 2025
03fad28
feat: Add prompt customization UI and wiring (tasks 4-6)
Orinks Dec 12, 2025
5e32e4b
docs: Update tasks.md to reflect completed implementation
Orinks Dec 12, 2025
6868f02
fix: Update AI explainer tests for new model name and proper mocking
Orinks Dec 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Include forecast data in weather explanation context
  • Loading branch information
Orinks committed Dec 11, 2025
commit e1e094cc0a61f40c8694bdf133fe47f05b427062
33 changes: 28 additions & 5 deletions src/accessiweather/ai_explainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,36 @@ def _build_prompt(
forecast_summary=weather_data.get("forecast_summary"),
)

return (
f"Please explain the following weather conditions:\n\n"
f"{context.to_prompt_text()}\n\n"
f"Provide a natural language explanation of what this weather means "
f"for someone planning their day."
prompt_parts = [
"Please explain the following weather conditions:\n",
context.to_prompt_text(),
]

# Add forecast periods if available
forecast_periods = weather_data.get("forecast_periods", [])
if forecast_periods:
prompt_parts.append("\n\nUpcoming Forecast:")
for period in forecast_periods:
period_text = f"\n- {period.get('name', 'Unknown')}: "
period_text += (
f"{period.get('temperature', 'N/A')}°{period.get('temperature_unit', 'F')}"
)
if period.get("short_forecast"):
period_text += f", {period['short_forecast']}"
if period.get("wind_speed"):
period_text += f" (Wind: {period['wind_speed']}"
if period.get("wind_direction"):
period_text += f" {period['wind_direction']}"
period_text += ")"
prompt_parts.append(period_text)

prompt_parts.append(
"\n\nProvide a natural language explanation of the current conditions "
"and what to expect over the coming days for someone planning their activities."
)

return "".join(prompt_parts)

def _format_response(self, response_text: str, preserve_markdown: bool) -> str:
"""
Format AI response based on HTML rendering setting.
Expand Down
17 changes: 17 additions & 0 deletions src/accessiweather/handlers/ai_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ async def on_explain_weather_pressed(app: AccessiWeatherApp, widget) -> None:
"visibility": current.visibility_miles,
"pressure": current.pressure_in,
"alerts": [],
"forecast_periods": [],
}

# Add alerts if present
Expand All @@ -94,6 +95,22 @@ async def on_explain_weather_pressed(app: AccessiWeatherApp, widget) -> None:
for alert in weather_data.alerts.alerts
]

# Add forecast periods if available (first 4-6 periods for context)
if weather_data.forecast and weather_data.forecast.periods:
forecast_periods = []
for period in weather_data.forecast.periods[:6]:
forecast_periods.append(
{
"name": period.name,
"temperature": period.temperature,
"temperature_unit": period.temperature_unit,
"short_forecast": period.short_forecast,
"wind_speed": period.wind_speed,
"wind_direction": period.wind_direction,
}
)
weather_dict["forecast_periods"] = forecast_periods

# Determine explanation style
style_map = {
"brief": ExplanationStyle.BRIEF,
Expand Down