# weather-ai-agent **Repository Path**: toopoor/weather-ai-agent ## Basic Information - **Project Name**: weather-ai-agent - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-01 - **Last Updated**: 2026-03-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 智能天气播报AI Agent 基于Spring AI Alibaba + 通义千问的智能天气播报系统,能够根据实时天气数据生成个性化、专业的天气播报内容。 ## 🌟 项目特色 - **AI智能播报**: 基于通义千问大模型,生成个性化、专业的天气播报内容 - **实时天气数据**: 接入和风天气API,提供准确、及时的天气信息 - **多种播报风格**: 支持正式、轻松、幽默等多种播报风格 - **智能生活建议**: 提供穿衣、出行等生活建议,让天气播报更实用 - **缓存优化**: 使用Redis缓存,提升响应速度 - **现代化UI**: 响应式设计,支持多设备访问 ## 🛠️ 技术栈 - **后端框架**: Spring Boot 3.2.0 - **AI框架**: Spring AI Alibaba 1.0.0-M2 - **AI模型**: 通义千问 (qwen-turbo) - **天气API**: 和风天气API - **缓存**: Redis - **模板引擎**: Thymeleaf - **前端**: HTML5 + CSS3 + JavaScript - **构建工具**: Maven ## 📋 功能特性 ### 核心功能 - 🌤️ 实时天气数据获取 - 🤖 AI智能播报生成 - 🎨 多种播报风格选择 - 💡 智能生活建议 - 📱 响应式Web界面 ### 播报风格 - **正式专业**: 语言严谨准确,适合正式场合 - **轻松友好**: 语言亲切自然,适合日常使用 - **幽默风趣**: 语言生动有趣,增加趣味性 ### 生活建议 - 👔 穿衣建议 - 🚗 出行建议 - 🏃 运动建议 - 🌂 生活提醒 ## 🚀 快速开始 ### 环境要求 - Java 17+ - Maven 3.6+ - Redis 6.0+ - 通义千问API Key - 和风天气API Key ### 1. 克隆项目 ```bash git clone cd weather-ai-agent ``` ### 2. 配置API密钥 编辑 `src/main/resources/application.yml` 文件,配置以下信息: ```yaml spring: ai: tongyi: chat: options: api-key: YOUR_TONGYI_API_KEY # 替换为你的通义千问API Key weather: api: key: YOUR_HEFENG_API_KEY # 替换为你的和风天气API Key ``` ### 3. 启动Redis ```bash # 使用Docker启动Redis docker run -d --name redis -p 6379:6379 redis:latest # 或使用本地Redis服务 redis-server ``` ### 4. 运行项目 ```bash mvn spring-boot:run ``` ### 5. 访问应用 打开浏览器访问: http://localhost:8080 ## 📖 API文档 ### REST API接口 #### 获取天气播报 ```http POST /api/weather/report Content-Type: application/json { "city": "北京", "reportStyle": "casual", "includeAdvice": true, "includeDressing": true, "includeTravel": true } ``` **响应示例:** ```json { "success": true, "message": "获取天气播报成功", "weatherInfo": { "city": "北京", "updateTime": "2024-01-15T10:00+08:00", "now": { "temperature": "22", "feelsLike": "25", "weatherText": "晴", "windDirectionText": "东南风", "windScale": "3", "humidity": "65" } }, "aiReport": "大家好!现在为您播报北京的天气情况...", "timestamp": 1705287600000 } ``` #### 健康检查 ```http GET /api/health ``` ## 🔧 配置说明 ### application.yml 配置项 ```yaml server: port: 8080 spring: application: name: weather-ai-agent # Thymeleaf配置 thymeleaf: cache: false encoding: UTF-8 mode: HTML prefix: classpath:/templates/ suffix: .html # Redis配置 data: redis: host: localhost port: 6379 timeout: 2000ms lettuce: pool: max-active: 8 max-idle: 8 min-idle: 0 # Spring AI Alibaba配置 ai: dashscope: api-key: ${DASHSCOPE_API_KEY:your-api-key} chat: options: model: qwen-turbo temperature: 0.7 # 和风天气API配置 weather: api: key: ${HEFENG_API_KEY:your-api-key} base-url: https://devapi.qweather.com # 缓存配置 cache: ttl: 30m # 日志配置 logging: level: com.example.weather: INFO org.springframework.ai: DEBUG ``` ## 🏗️ 项目结构 ``` weather-ai-agent/ ├── src/main/java/com/example/weather/ │ ├── WeatherAiAgentApplication.java # 启动类 │ ├── config/ │ │ ├── AiConfig.java # AI配置 │ │ └── RedisConfig.java # Redis配置 │ ├── controller/ │ │ └── WeatherController.java # Web控制器 │ ├── service/ │ │ ├── WeatherService.java # 天气数据服务 │ │ └── AiWeatherReportService.java # AI播报服务 │ ├── model/ │ │ └── WeatherInfo.java # 天气信息模型 │ └── dto/ │ ├── WeatherReportRequest.java # 请求DTO │ └── WeatherReportResponse.java # 响应DTO ├── src/main/resources/ │ ├── application.yml # 应用配置 │ ├── templates/ │ │ ├── index.html # 首页模板 │ │ └── result.html # 结果页模板 │ └── static/ │ ├── css/style.css # 样式文件 │ └── js/main.js # JavaScript文件 ├── pom.xml # Maven配置 └── README.md # 项目文档 ``` ## 🔍 使用说明 ### 1. 基本使用 1. 在首页输入城市名称 2. 选择播报风格(正式、轻松、幽默) 3. 选择需要的建议类型 4. 点击"生成天气播报"按钮 5. 查看AI生成的个性化天气播报 ### 2. API调用 可以通过REST API接口集成到其他系统中,支持JSON格式的请求和响应。 ### 3. 缓存机制 - 天气数据缓存30分钟 - AI播报结果缓存30分钟 - 提升响应速度,减少API调用 ## 🛡️ 注意事项 ### API密钥安全 - 不要将API密钥提交到版本控制系统 - 建议使用环境变量或配置文件管理密钥 - 生产环境中使用加密存储 ### 错误处理 - 当天气API不可用时,系统会使用模拟数据 - 当AI服务不可用时,系统会使用备用播报模板 - 所有错误都会记录到日志中 ### 性能优化 - 使用Redis缓存减少API调用 - 实现了连接池优化 - 支持异步处理 ## 🤝 贡献指南 1. Fork 项目 2. 创建特性分支 (`git checkout -b feature/AmazingFeature`) 3. 提交更改 (`git commit -m 'Add some AmazingFeature'`) 4. 推送到分支 (`git push origin feature/AmazingFeature`) 5. 打开 Pull Request ## 📄 许可证 本项目采用 MIT 许可证 - 查看 [LICENSE](LICENSE) 文件了解详情。 ## 📞 联系方式 如有问题或建议,请通过以下方式联系: - 项目Issues: [GitHub Issues](https://github.com/your-repo/weather-ai-agent/issues) - 邮箱: your-email@example.com ## 🙏 致谢 - [Spring AI Alibaba](https://github.com/alibaba/spring-ai-alibaba) - AI集成框架 - [通义千问](https://tongyi.aliyun.com/) - AI大模型服务 - [和风天气](https://www.qweather.com/) - 天气数据API - [Spring Boot](https://spring.io/projects/spring-boot) - 应用框架 --- ⭐ 如果这个项目对你有帮助,请给它一个星标!