Forráskód Böngészése

feat: 添加allen2000毕业设计项目

allen2000 7 hónapja
szülő
commit
e640b169c5

+ 10 - 0
Co-creation-projects/allen2000-FashionDailyDress/.env.example

@@ -0,0 +1,10 @@
+# LLM配置
+LLM_API_KEY=xxxxx
+LLM_MODEL=Qwen/Qwen3-235B-A22B-Instruct-2507
+LLM_BASE_URL=https://api-inference.modelscope.cn/v1/
+
+# 天气API
+OPENWEATHER_API_KEY=
+
+# 搜索API
+SERPAPI_API_KEY=xxxxx

+ 161 - 0
Co-creation-projects/allen2000-FashionDailyDress/README.md

@@ -0,0 +1,161 @@
+# 🌤️ 多智能体天气穿衣建议系统
+
+一个基于多智能体协作的天气查询和穿衣建议系统,使用Python和Gradio构建。
+
+## 🎯 项目简介
+
+本项目实现了一个智能的天气穿衣建议系统,通过多个智能体协作处理用户查询:
+- **天气查询智能体**:负责获取实时天气数据
+- **穿衣建议智能体**:基于天气信息生成专业的穿衣建议
+- **协调器智能体**:管理智能体间的协作和任务分配
+
+## ✨ 核心功能
+
+- 🌤️ **实时天气查询**:支持全球主要城市的天气查询
+- 🤖 **AI智能建议**:基于天气数据生成专业的穿衣建议
+- 🔄 **多智能体协作**:智能体间高效协作处理复杂任务
+- 🌐 **Web界面**:友好的Gradio图形界面
+
+## 📁 项目结构
+
+```
+bill-FashionDailyDress/
+├── fashion_agent.py          # 穿衣建议智能体
+├── gradio_app.py            # Gradio Web界面
+├── multi_agent_coordinator.py # 多智能体协调器
+├── simple_multi_agent.py    # 简化版多智能体系统
+├── weather.py               # 天气查询功能
+├── weather_mcp.py           # MCP天气服务器
+├── requirements.txt         # 项目依赖
+└── README.md               # 项目说明文档
+```
+
+## 🚀 快速开始
+
+### 1. 环境准备
+
+```bash
+# 克隆项目
+git clone <repository-url>
+cd bill-FashionDailyDress
+
+# 安装依赖
+pip install -r requirements.txt
+```
+
+### 2. 环境变量配置
+
+创建 `.env` 文件并配置必要的API密钥:
+
+```env
+# LLM配置(必需)
+LLM_API_KEY=your_llm_api_key
+LLM_BASE_URL=your_llm_base_url
+LLM_MODEL_ID=your_llm_model_id
+
+# 天气API配置(可选,用于真实天气数据)
+OPENWEATHER_API_KEY=your_openweather_api_key
+```
+
+### 3. 运行系统
+
+#### 方式一:使用Gradio Web界面(推荐)
+python版本3.12.10
+```bash
+python gradio_app.py
+```
+访问 http://localhost:8899 使用图形界面
+
+#### 方式二:命令行交互
+```bash
+python simple_multi_agent.py
+```
+
+## 🔧 核心模块说明
+
+### fashion_agent.py
+- **功能**:专业的穿衣建议智能体
+- **特点**:基于温度、湿度、风速等天气因素提供详细建议
+- **输出**:包含服装搭配、配饰建议、注意事项等
+
+### multi_agent_coordinator.py
+- **功能**:多智能体协调器
+- **特点**:管理天气查询和穿衣建议智能体的协作
+- **流程**:接收查询 → 获取天气 → 生成建议 → 整合结果
+
+### gradio_app.py
+- **功能**:Web图形界面
+- **特点**:用户友好的交互界面,支持示例快速体验
+- **端口**:8899
+
+### weather.py
+- **功能**:天气查询封装
+- **特点**:支持真实API和演示模式
+- **API**:OpenWeatherMap API集成
+
+## 📋 使用示例
+
+### 输入示例
+- Beijing
+- Shanghai
+- Tokyo
+- London
+
+### 输出示例
+```
+🏙️ 查询城市: 北京
+🌡️ 温度: 25°C
+📝 天气: 晴朗
+💧 湿度: 60%
+🌬️ 风速: 3 m/s
+
+👗 穿衣建议:
+基于当前天气状况,建议穿着轻薄透气的衣物...
+```
+
+## ⚙️ 配置说明
+
+### 必需配置
+- LLM API密钥和端点(用于智能体推理)
+
+### 可选配置
+- OpenWeatherMap API密钥(用于真实天气数据)
+- 如不配置,系统将使用演示模式提供模拟数据
+
+## 🛠️ 技术栈
+
+- **框架**:hello-agents, fastmcp
+- **Web界面**:Gradio
+- **HTTP请求**:requests
+- **配置管理**:python-dotenv
+- **天气API**:OpenWeatherMap
+
+## 🔍 开发指南
+
+### 添加新的智能体
+1. 创建新的智能体类(参考fashion_agent.py)
+2. 在协调器中注册智能体
+3. 更新系统提示词和协作逻辑
+
+### 扩展功能
+- 支持更多天气数据源
+- 添加历史天气分析
+- 集成更多穿衣风格建议
+
+## 🤝 贡献指南
+
+欢迎提交Issue和Pull Request来改进项目!
+
+## 📄 许可证
+
+本项目采用MIT许可证。
+
+## 📞 联系方式
+
+如有问题或建议,请通过以下方式联系:
+- GitHub Issues
+- 项目维护者邮箱
+
+---
+
+**享受智能穿衣建议!** 👗✨

+ 134 - 0
Co-creation-projects/allen2000-FashionDailyDress/fashion_agent.py

@@ -0,0 +1,134 @@
+"""
+穿衣建议智能体
+专门处理基于天气信息的穿衣建议
+"""
+from hello_agents import SimpleAgent, HelloAgentsLLM
+import os
+from dotenv import load_dotenv
+
+load_dotenv()
+
+class FashionAgent:
+    """穿衣建议智能体"""
+    
+    def __init__(self, name="时尚顾问"):
+        """初始化穿衣建议智能体"""
+        self.name = name
+        self.agent = SimpleAgent(
+            name=name, 
+            llm=HelloAgentsLLM(
+                api_key=os.environ.get("LLM_API_KEY"),
+                base_url=os.environ.get("LLM_BASE_URL"),
+                model=os.environ.get("LLM_MODEL_ID")
+            )
+        )
+        
+        # 设置智能体的系统提示词
+        self._setup_prompt()
+    
+    def _setup_prompt(self):
+        """设置智能体的系统提示词"""
+        system_prompt = """你是一个专业的时尚顾问,专门根据天气信息提供穿衣建议。
+
+你的职责:
+1. 根据天气信息(温度、湿度、风速、天气状况)提供合适的穿衣建议
+2. 考虑不同季节、场合和人群的穿衣需求
+3. 提供具体的服装搭配建议,包括上衣、裤子、外套、鞋子等
+4. 考虑保暖、防晒、防雨等实际需求
+5. 给出时尚且实用的建议
+
+穿衣建议指南:
+- 高温天气(>30°C):建议轻薄透气的衣物,注意防晒
+- 温暖天气(20-30°C):建议舒适的单层衣物
+- 凉爽天气(10-20°C):建议长袖衣物,可搭配薄外套
+- 寒冷天气(<10°C):建议保暖衣物,如毛衣、羽绒服等
+- 雨天:建议防水外套和雨具
+- 大风天气:建议防风衣物
+
+请根据具体的天气信息提供详细、实用的穿衣建议。"""
+        
+        self.agent.system_prompt = system_prompt
+    
+    def get_fashion_advice(self, weather_info):
+        """
+        基于天气信息获取穿衣建议
+        
+        Args:
+            weather_info: 天气信息字符串或字典
+            
+        Returns:
+            穿衣建议字符串
+        """
+        # 构建查询提示
+        query = f"""请根据以下天气信息提供穿衣建议:
+
+天气信息:
+{weather_info}
+
+请提供详细的穿衣建议,包括:
+1. 适合的服装类型
+2. 具体的搭配建议
+3. 注意事项
+4. 时尚建议"""
+        
+        # 使用智能体获取建议
+        response = self.agent.run(query)
+        return response
+    
+    def get_detailed_fashion_advice(self, weather_data):
+        """
+        基于结构化天气数据获取更详细的穿衣建议
+        
+        Args:
+            weather_data: 包含天气信息的字典
+            
+        Returns:
+            详细的穿衣建议字符串
+        """
+        if isinstance(weather_data, dict):
+            # 从字典中提取关键信息
+            temperature = weather_data.get('temperature', '未知')
+            description = weather_data.get('description', '未知')
+            humidity = weather_data.get('humidity', '未知')
+            wind_speed = weather_data.get('wind_speed', '未知')
+            
+            query = f"""请根据以下详细的天气数据提供专业的穿衣建议:
+
+详细天气信息:
+- 温度: {temperature}°C
+- 天气状况: {description}
+- 湿度: {humidity}%
+- 风速: {wind_speed} m/s
+
+请提供:
+1. 适合的服装材质和类型
+2. 分层穿衣建议(适合不同温度变化)
+3. 配饰建议(帽子、围巾、手套等)
+4. 特殊天气条件下的注意事项
+5. 时尚搭配技巧"""
+        else:
+            query = f"请根据以下天气信息提供穿衣建议:\n\n{weather_data}"
+        
+        response = self.agent.run(query)
+        return response
+
+
+def main():
+    """测试函数"""
+    # 创建穿衣建议智能体
+    fashion_agent = FashionAgent()
+    
+    # 测试数据
+    test_weather = """🏙️ 城市: Shanghai
+🌡️ 温度: 25°C
+📝 天气: 晴朗
+💧 湿度: 60%
+🌬️ 风速: 3 m/s"""
+    
+    print("=== 穿衣建议智能体测试 ===")
+    advice = fashion_agent.get_fashion_advice(test_weather)
+    print(advice)
+
+
+if __name__ == "__main__":
+    main()

+ 228 - 0
Co-creation-projects/allen2000-FashionDailyDress/gradio_app.py

@@ -0,0 +1,228 @@
+"""
+Gradio前端界面 - 多智能体天气穿衣建议系统
+在本地8899端口提供服务
+"""
+import gradio as gr
+import sys
+import os
+
+# 添加当前目录到Python路径
+sys.path.append(os.path.dirname(os.path.abspath(__file__)))
+
+def get_weather_and_fashion_advice(city_name):
+    """
+    获取指定城市的天气和穿衣建议
+    :param city_name: 城市名称
+    :return: 完整的响应文本
+    """
+    try:
+        # 导入多智能体协调器
+        from multi_agent_coordinator import MultiAgentCoordinator
+        
+        # 创建协调器实例
+        coordinator = MultiAgentCoordinator()
+        
+        # 构建查询
+        query = f"查询{city_name}的天气并给出穿衣建议"
+        
+        # 处理查询
+        result = coordinator.process_query(query)
+        
+        # 返回完整的响应文本
+        response_text = f"""
+🏙️ **查询城市**: {city_name}
+🔍 **查询内容**: {query}
+
+📊 **多智能体协作结果**:
+{result}
+
+💡 **系统说明**:
+- 本系统使用多智能体协作架构
+- 天气查询智能体负责获取天气数据
+- 穿衣建议智能体基于天气数据生成专业建议
+- 协调器负责智能体间的通信和任务分配
+"""
+        
+        return response_text
+        
+    except Exception as e:
+        # 如果多智能体系统不可用,使用简化版本
+        try:
+            from simple_multi_agent import get_real_weather, get_llm_fashion_advice
+            
+            # 获取天气信息
+            weather_info, weather_details = get_real_weather(city_name)
+            
+            # 获取LLM穿衣建议
+            fashion_advice = get_llm_fashion_advice(weather_details, city_name)
+            
+            response_text = f"""
+🏙️ **查询城市**: {city_name}
+
+📊 **天气信息**:
+{weather_info}
+
+🤖 **LLM智能穿衣建议**:
+{fashion_advice}
+
+💡 **系统说明**:
+- 使用简化版多智能体系统
+- 基于真实天气数据生成建议
+- LLM智能处理穿衣建议
+"""
+            return response_text
+            
+        except Exception as e2:
+            # 如果所有方法都失败,返回错误信息
+            error_text = f"""
+❌ **系统错误**: 无法获取{city_name}的天气和穿衣建议
+
+**错误信息**:
+- 主要错误: {str(e)}
+- 备用错误: {str(e2)}
+
+💡 **解决方案**:
+1. 检查网络连接
+2. 确保天气API服务可用
+3. 检查系统依赖是否完整安装
+
+🔧 **备用建议**:
+您可以尝试以下城市:北京、上海、广州、深圳、杭州、成都等
+"""
+            return error_text
+
+def create_gradio_interface():
+    """创建Gradio界面"""
+    
+    # 界面描述
+    description = """
+    # 🌤️ 多智能体天气穿衣建议系统
+    
+    输入您想查询的城市名称,系统将为您提供:
+    - 📊 实时天气信息
+    - 🤖 LLM智能穿衣建议
+    - 💡 专业穿搭指导
+    
+    **支持功能**:
+    - 多智能体协作处理
+    - 真实天气数据查询
+    - AI智能穿衣建议
+    - 多轮对话支持
+    """
+    
+    # 创建界面
+    with gr.Blocks(
+        title="多智能体天气穿衣建议系统",
+        theme=gr.themes.Soft(),
+        css="""
+        .gradio-container {
+            max-width: 900px !important;
+        }
+        .output-text {
+            font-size: 14px;
+            line-height: 1.6;
+        }
+        """
+    ) as demo:
+        
+        gr.Markdown(description)
+        
+        with gr.Row():
+            with gr.Column(scale=1):
+                city_input = gr.Textbox(
+                    label="🌍 请输入城市名称",
+                    placeholder="例如:北京、上海、广州、深圳...",
+                    info="支持中文和英文城市名"
+                )
+                
+                submit_btn = gr.Button(
+                    "🚀 获取穿衣建议",
+                    variant="primary",
+                    size="lg"
+                )
+                
+                clear_btn = gr.Button("🗑️ 清空", variant="secondary")
+                
+            with gr.Column(scale=2):
+                output_text = gr.Textbox(
+                    label="📋 完整响应结果",
+                    lines=20,
+                    max_lines=30,
+                    show_copy_button=True,
+                    elem_classes="output-text"
+                )
+        
+        # 示例城市
+        examples = gr.Examples(
+            examples=[["beijing"], ["tokoy"], ["london"], ["new york"], ["paris"], ["seoul"], ["bangkok"], ["harbin"]],
+            inputs=city_input,
+            label="💡 点击示例快速体验"
+        )
+        
+        # 按钮事件
+        submit_btn.click(
+            fn=get_weather_and_fashion_advice,
+            inputs=city_input,
+            outputs=output_text
+        )
+        
+        clear_btn.click(
+            fn=lambda: "",
+            inputs=[],
+            outputs=output_text
+        )
+        
+        # 回车键提交
+        city_input.submit(
+            fn=get_weather_and_fashion_advice,
+            inputs=city_input,
+            outputs=output_text
+        )
+        
+        # 页脚信息
+        gr.Markdown("""
+        ---
+        
+        ### 🔧 系统信息
+        - **版本**: v1.0.0
+        - **架构**: 多智能体协作系统
+        - **技术栈**: Python + Gradio + 多智能体框架
+        - **端口**: 8899
+        
+        ### 📖 使用说明
+        1. 在左侧输入框输入城市名称
+        2. 点击"获取穿衣建议"按钮或按回车键
+        3. 查看右侧的完整响应结果
+        4. 可以点击示例快速体验不同城市
+        
+        ### 🎯 功能特点
+        - 🌤️ 实时天气数据查询
+        - 🤖 AI智能穿衣建议
+        - 🔄 多智能体协作处理
+        - 📱 响应式Web界面
+        - 🎨 美观的用户体验
+        """)
+    
+    return demo
+
+def main():
+    """启动Gradio应用"""
+    print("🚀 启动多智能体天气穿衣建议系统 - Gradio前端")
+    print("🌐 服务地址: http://localhost:8899")
+    print("⏳ 正在启动服务...")
+    
+    # 创建界面
+    demo = create_gradio_interface()
+    
+    # 启动服务
+    demo.launch(
+        server_name="0.0.0.0",
+        server_port=8899,
+        share=False,
+        show_error=True,
+        debug=True,
+        quiet=False
+    )
+
+if __name__ == "__main__":
+    main()

+ 181 - 0
Co-creation-projects/allen2000-FashionDailyDress/multi_agent_coordinator.py

@@ -0,0 +1,181 @@
+"""
+多智能体协调器
+管理天气查询智能体和穿衣建议智能体的协作
+"""
+from hello_agents import SimpleAgent, HelloAgentsLLM
+from hello_agents.tools import MCPTool
+from fashion_agent import FashionAgent
+import os
+from dotenv import load_dotenv
+
+load_dotenv()
+
+class MultiAgentCoordinator:
+    """多智能体协调器"""
+    
+    def __init__(self):
+        """初始化协调器"""
+        # 创建主协调智能体
+        self.coordinator = SimpleAgent(
+            name="智能体协调器",
+            llm=HelloAgentsLLM(
+                api_key=os.environ.get("LLM_API_KEY"),
+                base_url=os.environ.get("LLM_BASE_URL"),
+                model=os.environ.get("LLM_MODEL_ID")
+            )
+        )
+        
+        # 创建天气查询智能体
+        self.weather_agent = self._create_weather_agent()
+        
+        # 创建穿衣建议智能体
+        self.fashion_agent = FashionAgent()
+        
+        # 设置协调器的系统提示词
+        self._setup_coordinator_prompt()
+    
+    def _create_weather_agent(self):
+        """创建天气查询智能体"""
+        weather_agent = SimpleAgent(
+            name="天气查询助手",
+            llm=HelloAgentsLLM(
+                api_key=os.environ.get("LLM_API_KEY"),
+                base_url=os.environ.get("LLM_BASE_URL"),
+                model=os.environ.get("LLM_MODEL_ID")
+            )
+        )
+        
+        # 配置MCP工具使用本地的weather_mcp.py服务器
+        mcp_tool = MCPTool(
+            name="query_weather",
+            server_command=["python", "weather_mcp.py"]
+        )
+        
+        weather_agent.add_tool(mcp_tool)
+        
+        # 设置天气智能体的系统提示词
+        weather_agent.system_prompt = """你是一个天气查询助手。你可以使用query_weather工具查询指定城市的天气信息。
+
+请根据用户提供的城市名称查询天气,并返回详细的天气信息。"""
+        
+        return weather_agent
+    
+    def _setup_coordinator_prompt(self):
+        """设置协调器的系统提示词"""
+        system_prompt = """你是一个智能体协调器,负责管理天气查询智能体和穿衣建议智能体的协作。
+
+你的工作流程:
+1. 接收用户关于天气和穿衣建议的查询
+2. 调用天气查询智能体获取指定城市的天气信息
+3. 将天气信息传递给穿衣建议智能体
+4. 整合两个智能体的结果,提供完整的天气和穿衣建议
+
+协作规则:
+- 首先获取准确的天气信息
+- 然后基于天气信息提供专业的穿衣建议
+- 确保信息的准确性和实用性
+- 提供清晰、完整的最终结果
+
+请按照这个流程处理用户的查询。"""
+        
+        self.coordinator.system_prompt = system_prompt
+    
+    def process_query(self, query):
+        """
+        处理用户查询,协调多个智能体完成任务
+        
+        Args:
+            query: 用户查询字符串
+            
+        Returns:
+            包含天气信息和穿衣建议的完整结果
+        """
+        print("=== 开始处理查询 ===")
+        print(f"用户查询: {query}")
+        print()
+        
+        # 步骤1: 使用天气智能体查询天气
+        print("步骤1: 查询天气信息...")
+        weather_response = self.weather_agent.run(query)
+        print(f"天气查询结果: {weather_response}")
+        print()
+        
+        # 步骤2: 使用穿衣建议智能体提供建议
+        print("步骤2: 生成穿衣建议...")
+        fashion_advice = self.fashion_agent.get_fashion_advice(weather_response)
+        print(f"穿衣建议: {fashion_advice}")
+        print()
+        
+        # 步骤3: 整合结果
+        print("步骤3: 整合最终结果...")
+        final_result = self._format_final_result(weather_response, fashion_advice)
+        
+        return final_result
+    
+    def _format_final_result(self, weather_info, fashion_advice):
+        """
+        格式化最终结果
+        
+        Args:
+            weather_info: 天气信息
+            fashion_advice: 穿衣建议
+            
+        Returns:
+            格式化的完整结果
+        """
+        result = f"""🎯 智能体协作完成!以下是您的完整天气和穿衣建议:
+
+🌤️ 天气信息:
+{weather_info}
+
+👗 穿衣建议:
+{fashion_advice}
+
+💡 温馨提示:
+- 请根据实际体感温度调整穿着
+- 考虑当天的具体活动安排
+- 如有特殊需求,可进一步咨询"""
+        
+        return result
+    
+    def get_weather_only(self, city_name):
+        """
+        仅获取天气信息(不包含穿衣建议)
+        
+        Args:
+            city_name: 城市名称
+            
+        Returns:
+            天气信息
+        """
+        query = f"查询{city_name}的天气"
+        return self.weather_agent.run(query)
+    
+    def get_fashion_advice_only(self, weather_info):
+        """
+        基于现有天气信息获取穿衣建议
+        
+        Args:
+            weather_info: 天气信息字符串
+            
+        Returns:
+            穿衣建议
+        """
+        return self.fashion_agent.get_fashion_advice(weather_info)
+
+
+def main():
+    """测试函数"""
+    # 创建多智能体协调器
+    coordinator = MultiAgentCoordinator()
+    
+    # 测试查询
+    test_query = "查询上海的天气并给出穿衣建议"
+    
+    print("=== 多智能体协调器测试 ===")
+    result = coordinator.process_query(test_query)
+    print(result)
+
+
+if __name__ == "__main__":
+    main()

+ 12 - 0
Co-creation-projects/allen2000-FashionDailyDress/requirements.txt

@@ -0,0 +1,12 @@
+# 多智能体天气穿衣建议系统依赖
+
+# 核心框架
+hello-agents[all]==0.2.8
+fastmcp==2.13.1
+
+# Web界面
+requests==2.32.5
+gradio==4.44.1
+
+# 环境变量管理
+dotenv==0.9.9

+ 257 - 0
Co-creation-projects/allen2000-FashionDailyDress/simple_multi_agent.py

@@ -0,0 +1,257 @@
+"""
+简单多智能体天气穿衣建议系统
+提供直接的城市输入功能,使用真实天气数据,穿衣建议由LLM处理
+"""
+import sys
+import os
+import json
+import random
+
+def get_city_input():
+    """获取用户输入的城市名称"""
+    print("💬 欢迎使用多智能体天气穿衣建议系统!")
+    print("💡 请输入您想查询天气的城市名称")
+    print("💡 支持中文和英文城市名")
+    print("💡 输入 'quit' 或 '退出' 可以退出程序\n")
+    
+    while True:
+        city = input("🌍 请输入城市名称: ").strip()
+        if not city:
+            print("❌ 请输入有效的城市名称")
+            continue
+            
+        return city
+
+def get_real_weather(city_name):
+    """获取真实天气数据"""
+    try:
+        # 导入Weather类
+        from weather import Weather
+        
+        # 创建天气查询实例
+        weather = Weather()
+        
+        # 查询天气信息
+        weather_info = weather.get_weather(city_name)
+        
+        # 获取详细天气数据用于穿衣建议
+        weather_details = weather.get_weather_details(city_name)
+        
+        return weather_info, weather_details
+        
+    except Exception as e:
+        print(f"❌ 天气查询失败: {e}")
+        # 返回模拟数据作为备用
+        return f"🏙️ 城市: {city_name}\n🌡️ 温度: 20°C\n📝 天气: 晴朗\n💧 湿度: 50%\n🌬️ 风速: 3 m/s", None
+
+def get_llm_fashion_advice(weather_details, city_name):
+    """使用LLM基于真实天气数据生成穿衣建议"""
+    if weather_details and "error" not in weather_details:
+        # 使用真实天气数据
+        temp = weather_details.get('temperature', 20)
+        description = weather_details.get('description', '晴朗')
+        humidity = weather_details.get('humidity', 50)
+        wind_speed = weather_details.get('wind_speed', 3)
+        
+        # 构建LLM提示词
+        prompt = f"""
+请根据以下天气信息为{city_name}提供专业的穿衣建议:
+- 温度: {temp}°C
+- 天气状况: {description}
+- 湿度: {humidity}%
+- 风速: {wind_speed} m/s
+
+请提供详细、实用的穿衣建议,包括:
+1. 上衣选择
+2. 下装选择  
+3. 鞋子建议
+4. 外套/配饰
+5. 特别注意事项
+
+请用中文回复,格式要清晰易读。"""
+        
+        # 模拟LLM响应(在实际应用中,这里会调用真实的LLM API)
+        llm_response = simulate_llm_response(prompt, temp, description)
+        
+        return f"🤖 LLM智能穿衣建议(基于{city_name}的真实天气数据):\n\n{llm_response}"
+    else:
+        # 使用模拟数据
+        prompt = f"""
+请根据以下天气信息为{city_name}提供专业的穿衣建议:
+- 温度: 20°C
+- 天气状况: 晴朗
+- 湿度: 50%
+- 风速: 3 m/s
+
+请提供详细、实用的穿衣建议。"""
+        
+        llm_response = simulate_llm_response(prompt, 20, '晴朗')
+        return f"🤖 LLM智能穿衣建议(基于{city_name}的天气数据):\n\n{llm_response}"
+
+def simulate_llm_response(prompt, temperature, weather_condition):
+    """模拟LLM响应,根据温度生成智能穿衣建议"""
+    
+    # 基于温度生成不同的建议模板
+    if temperature > 30:
+        base_advice = {
+            "上衣": ["短袖T恤", "透气衬衫", "背心", "轻薄材质上衣"],
+            "下装": ["短裤", "轻薄长裤", "透气材质的裤子"],
+            "鞋子": ["凉鞋", "透气运动鞋", "帆布鞋"],
+            "外套": ["防晒衣", "轻薄外套备用"],
+            "配饰": ["太阳镜", "遮阳帽", "防晒霜"],
+            "建议": "选择浅色、透气的面料,注意防晒和补水"
+        }
+    elif temperature > 25:
+        base_advice = {
+            "上衣": ["短袖T恤", "轻薄长袖", "透气衬衫"],
+            "下装": ["休闲裤", "牛仔裤", "轻薄材质的裤子"],
+            "鞋子": ["运动鞋", "休闲鞋", "帆布鞋"],
+            "外套": ["薄外套备用", "防风衣"],
+            "配饰": ["帽子", "太阳镜"],
+            "建议": "可分层穿着,便于根据温度变化调整"
+        }
+    elif temperature > 20:
+        base_advice = {
+            "上衣": ["长袖T恤", "薄款卫衣", "衬衫"],
+            "下装": ["休闲裤", "牛仔裤", "卡其裤"],
+            "鞋子": ["休闲鞋", "运动鞋", "皮鞋"],
+            "外套": ["夹克", "薄外套", "风衣"],
+            "配饰": ["围巾备用", "帽子"],
+            "建议": "温度适宜,适合户外活动"
+        }
+    elif temperature > 15:
+        base_advice = {
+            "上衣": ["长袖衬衫", "薄毛衣", "卫衣"],
+            "下装": ["长裤", "牛仔裤", "休闲裤"],
+            "鞋子": ["运动鞋", "皮鞋", "休闲鞋"],
+            "外套": ["夹克", "风衣", "薄外套"],
+            "配饰": ["围巾", "帽子"],
+            "建议": "注意保暖,可搭配薄外套"
+        }
+    elif temperature > 10:
+        base_advice = {
+            "上衣": ["毛衣", "厚衬衫", "保暖内衣"],
+            "下装": ["厚裤子", "牛仔裤", "保暖裤"],
+            "鞋子": ["运动鞋", "皮鞋", "保暖鞋"],
+            "外套": ["夹克", "风衣", "薄羽绒服"],
+            "配饰": ["围巾", "手套", "帽子"],
+            "建议": "注意保暖,可搭配围巾"
+        }
+    else:
+        base_advice = {
+            "上衣": ["保暖内衣", "厚毛衣", "羽绒内胆"],
+            "下装": ["厚裤子", "保暖裤", "羽绒裤"],
+            "鞋子": ["保暖靴子", "雪地靴", "防水鞋"],
+            "外套": ["羽绒服", "厚外套", "防风衣"],
+            "配饰": ["围巾", "手套", "帽子", "耳罩"],
+            "建议": "多层穿着,注意防寒保暖"
+        }
+    
+    # 根据天气状况调整建议
+    weather_adjustments = {
+        "雨": {
+            "鞋子": ["雨靴", "防水鞋"],
+            "配饰": ["雨伞", "雨衣"],
+            "建议": "选择防水面料,注意防滑"
+        },
+        "雪": {
+            "鞋子": ["防滑靴", "雪地靴"],
+            "配饰": ["手套", "帽子", "围巾"],
+            "建议": "注意防滑保暖,选择防水材质"
+        },
+        "风": {
+            "外套": ["防风衣", "风衣"],
+            "配饰": ["帽子", "围巾"],
+            "建议": "选择防风面料,注意保暖"
+        }
+    }
+    
+    # 应用天气调整
+    for weather_key, adjustment in weather_adjustments.items():
+        if weather_key in weather_condition:
+            for category, items in adjustment.items():
+                if category in base_advice:
+                    if category == "建议":
+                        base_advice[category] += f",{items}"
+                    else:
+                        base_advice[category].extend(items)
+    
+    # 构建响应文本
+    response = f"基于当前天气状况({temperature}°C,{weather_condition}),为您提供以下穿衣建议:\n\n"
+    
+    response += f"👕 **上衣选择**: {', '.join(base_advice['上衣'][:3])}\n"
+    response += f"👖 **下装选择**: {', '.join(base_advice['下装'][:3])}\n"
+    response += f"👟 **鞋子建议**: {', '.join(base_advice['鞋子'][:3])}\n"
+    response += f"🧥 **外套配饰**: {', '.join(base_advice['外套'][:2])}"
+    
+    if base_advice['配饰']:
+        response += f",配饰: {', '.join(base_advice['配饰'][:3])}\n"
+    else:
+        response += "\n"
+    
+    response += f"💡 **特别建议**: {base_advice['建议']}\n"
+    
+    # 添加个性化建议
+    if temperature > 25:
+        response += "🌞 **温馨提示**: 天气较热,建议选择透气材质,注意防晒补水"
+    elif temperature < 10:
+        response += "❄️ **温馨提示**: 天气较冷,建议多层穿着,注意保暖防寒"
+    else:
+        response += "🌤️ **温馨提示**: 天气舒适,适合各种户外活动"
+    
+    return response
+
+def main():
+    """主函数"""
+    try:
+        # 获取城市输入
+        city = get_city_input()
+        
+        print(f"\n🔍 正在查询 {city} 的真实天气信息...")
+        
+        # 获取真实天气数据
+        weather_info, weather_details = get_real_weather(city)
+        
+        # 生成穿衣建议(使用LLM处理)
+        print("🤖 正在使用LLM生成智能穿衣建议...")
+        fashion_advice = get_llm_fashion_advice(weather_details, city)
+        
+        # 显示结果
+        print("\n" + "="*50)
+        print("📊 天气信息")
+        print("="*50)
+        print(weather_info)
+        
+        print("\n" + "="*50)
+        print("👗 穿衣建议")
+        print("="*50)
+        print(fashion_advice)
+        
+        print("\n" + "="*50)
+        
+        # 询问是否继续查询
+        while True:
+            continue_query = input("\n🔍 是否继续查询其他城市?(y/n): ").strip().lower()
+            
+            if continue_query in ['y', 'yes', '是', '继续']:
+                print("\n" + "-"*50)
+                # 递归调用主函数继续查询
+                main()
+                return
+            elif continue_query in ['n', 'no', '否', '退出']:
+                print("👋 感谢使用,再见!")
+                return
+            else:
+                print("❌ 请输入 y/是 或 n/否")
+                
+    except KeyboardInterrupt:
+        print("\n\n👋 用户中断,程序退出")
+        sys.exit(0)
+    except Exception as e:
+        print(f"\n❌ 发生错误: {e}")
+        print("💡 请稍后重试")
+        sys.exit(1)
+
+
+if __name__ == "__main__":
+    main()

+ 163 - 0
Co-creation-projects/allen2000-FashionDailyDress/weather.py

@@ -0,0 +1,163 @@
+import requests
+import os
+from dotenv import load_dotenv
+
+load_dotenv()
+
+class Weather:
+    """天气查询类,封装OpenWeatherMap API功能"""
+    
+    def __init__(self, api_key=None, unit='metric'):
+        """
+        初始化Weather类
+        :param api_key: OpenWeatherMap API密钥,默认为环境变量中的OPENWEATHER_API_KEY
+        :param unit: 温度单位(metric=摄氏,imperial=华氏)
+        """
+        self.api_key = api_key or os.environ.get("OPENWEATHER_API_KEY")
+        self.unit = unit
+        self.base_url = "http://api.openweathermap.org/data/2.5/weather"
+
+        # 如果没有API密钥,使用模拟数据
+        self.demo_mode = not self.api_key
+        if self.demo_mode:
+            print("⚠️  警告: 未设置API密钥,使用演示模式")
+            print("   请设置OPENWEATHER_API_KEY环境变量以获得真实天气数据")
+    
+    def get_weather(self, city_name):
+        """
+        查询指定城市的天气信息
+        :param city_name: 城市名称(英文)
+        :return: 格式化后的天气信息字符串
+        """
+        # 如果是演示模式,使用模拟数据
+        if self.demo_mode:
+            return self._get_demo_weather()
+        
+        params = {
+            "q": city_name,
+            "appid": self.api_key,
+            "units": self.unit
+        }
+
+        try:
+            response = requests.get(self.base_url, params=params)
+            data = response.json()
+
+            if response.status_code == 200:
+                return self._format_weather_data(data)
+            else:
+                return f"错误 {data['cod']}: {data['message']}"
+
+        except Exception as e:
+            return f"请求失败: {str(e)}"
+    
+    def get_weather_details(self, city_name):
+        """
+        获取详细的天气数据(字典格式)
+        :param city_name: 城市名称(英文)
+        :return: 包含详细天气数据的字典
+        """
+        # 如果是演示模式,使用模拟数据
+        if self.demo_mode:
+            return self._get_demo_weather()
+        
+        params = {
+            "q": city_name,
+            "appid": self.api_key,
+            "units": self.unit
+        }
+
+        try:
+            response = requests.get(self.base_url, params=params)
+            data = response.json()
+
+            if response.status_code == 200:
+                return self._parse_weather_data(data)
+            else:
+                return {"error": f"错误 {data['cod']}: {data['message']}"}
+
+        except Exception as e:
+            return {"error": f"请求失败: {str(e)}"}
+
+    def _get_demo_weather(self):
+        return {
+            "city": 'shanghai',
+            "temperature": 25,
+            "temperature_unit": "°C",
+            "description": "晴天",
+            "humidity": 60,
+            "wind_speed": 10,
+            "wind_unit": "m/s"
+        }
+    def _parse_weather_data(self, data):
+        """
+        解析天气数据为字典格式
+        :param data: API返回的原始数据
+        :return: 解析后的天气数据字典
+        """
+        weather_desc = data['weather'][0]['description'].title()
+        temp = data['main']['temp']
+        humidity = data['main']['humidity']
+        wind_speed = data['wind']['speed']
+        city = data['name']
+        
+        return {
+            "city": city,
+            "temperature": temp,
+            "temperature_unit": "°C" if self.unit == 'metric' else "°F",
+            "description": weather_desc,
+            "humidity": humidity,
+            "wind_speed": wind_speed,
+            "wind_unit": "m/s"
+        }
+    
+    def _format_weather_data(self, data):
+        """
+        格式化天气数据为字符串
+        :param data: API返回的原始数据
+        :return: 格式化后的天气信息字符串
+        """
+        weather_data = self._parse_weather_data(data)
+        
+        return (
+            f"🏙️ 城市: {weather_data['city']}\n"
+            f"🌡️ 温度: {weather_data['temperature']}{weather_data['temperature_unit']}\n"
+            f"📝 天气: {weather_data['description']}\n"
+            f"💧 湿度: {weather_data['humidity']}%\n"
+            f"🌬️ 风速: {weather_data['wind_speed']} {weather_data['wind_unit']}"
+        )
+    
+    def set_unit(self, unit):
+        """
+        设置温度单位
+        :param unit: 温度单位(metric=摄氏,imperial=华氏)
+        """
+        if unit not in ['metric', 'imperial']:
+            raise ValueError("单位必须是 'metric' 或 'imperial'")
+        self.unit = unit
+    
+    def set_api_key(self, api_key):
+        """
+        设置API密钥
+        :param api_key: 新的API密钥
+        """
+        self.api_key = api_key
+
+
+def get_weather(city_name, api_key=os.environ.get("OPENWEATHER_API_KEY"), unit='metric'):
+    """
+    向后兼容的函数,使用Weather类实现
+    :param city_name: 城市名称(英文)
+    :param api_key: 你的OpenWeatherMap API密钥
+    :param unit: 温度单位(metric=摄氏,imperial=华氏)
+    :return: 格式化后的天气信息
+    """
+    weather = Weather(api_key=api_key, unit=unit)
+    return weather.get_weather(city_name)
+
+
+# 使用示例
+if __name__ == "__main__":
+    weather = Weather()
+    weather_info = weather.get_weather("harbin")
+    print(weather_info)

+ 97 - 0
Co-creation-projects/allen2000-FashionDailyDress/weather_mcp.py

@@ -0,0 +1,97 @@
+"""
+自定义MCP服务器示例
+
+这是一个简单的MCP服务器,提供天气信息查询。
+用于演示如何创建自己的MCP服务器。
+
+运行方式:
+    python my_mcp_server.py
+
+或者作为MCP服务器被客户端调用:
+    MCPClient(["python", "weather_mcp.py"])
+"""
+from fastmcp import FastMCP
+from weather import Weather
+# 创建MCP服务器实例
+mcp = FastMCP("WeatherServer")
+
+
+# ==================== 数学工具 ====================
+
+@mcp.tool()
+def query_wearher(city_name: str):
+    """
+    查询天气
+
+    Args:
+        city_name: 城市名称
+
+    Returns:
+        天气信息
+    """
+    weather = Weather()
+    # 查询天气详细信息(字典格式)
+    weather_details = weather.get_weather_details(city_name)
+    
+    # 如果查询成功,返回详细信息
+    if "error" not in weather_details:
+        return weather_details
+    else:
+        # 如果查询失败,返回格式化字符串
+        return weather.get_weather(city_name)
+
+@mcp.tool()
+def get_weather_details(city_name: str):
+    """
+    获取详细的天气数据(结构化格式)
+
+    Args:
+        city_name: 城市名称
+
+    Returns:
+        包含详细天气数据的字典
+    """
+    weather = Weather()
+    return weather.get_weather_details(city_name)
+
+@mcp.resource("info://capabilities")
+def get_capabilities() -> str:
+    """
+    获取指定城市的天气信息
+
+    Returns:
+        能力列表的文本描述
+    """
+    capabilities = """
+服务器能力列表:
+
+天气查询能力:
+- query_weather: 获取指定城市的天气信息(结构化数据)
+- get_weather_details: 获取详细的天气数据(字典格式)
+"""
+    return capabilities.strip()
+
+
+# ==================== 提示词模板 ====================
+
+@mcp.prompt()
+def weather_helper() -> str:
+    """
+    天气信息查询提示词
+
+    Returns:
+        提示词模板
+    """
+    return """你是一个天气查询助手。你可以使用以下工具:
+- query_weather(city_name): 获取指定城市的天气信息
+
+请根据用户的问题选择合适的工具进行任务执行。"""
+
+
+
+# ==================== 主程序 ====================
+
+if __name__ == "__main__":
+    # 运行MCP服务器
+    # FastMCP会自动处理stdio传输
+    mcp.run()