# qwen-agent-tutorial **Repository Path**: sherlock_king/qwen-agent-tutorial ## Basic Information - **Project Name**: qwen-agent-tutorial - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-03-06 - **Last Updated**: 2025-03-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # QwenAgent 项目 基于 Qwen Agent 框架的 Python AI 代理实现,具有多种 AI 功能,包括视觉故事创作、图像生成和天气查询。 ## 功能特性 ### 1. 视觉故事创作 通过双重 AI 代理将图像转换为创意叙事: - 由 Qwen-VL-Max 驱动的图像理解代理 - 生成 800 字叙事的创意写作代理 ### 2. 图像生成 AI 驱动的图像生成服务: - 接受文本描述作为输入 - 使用 Pollinations.ai API 生成相应图像 - 支持实时响应的流式输出 ### 3. 天气查询 集成高德地图天气 API,可以: - 提供实时天气信息 - 支持特定城市/区域查询 - 返回温度和天气状况 ## 环境配置 ### 前置要求 1. Python 环境 2. 以下 API 密钥: - Qwen API (Dashscope) - 高德地图天气 API ### 安装 ```bash pip install -r requirements.txt ``` ## 配置说明 1. 在相应文件中设置 API 密钥: - 天气服务:在环境变量或代码中设置 AMAP_TOKEN - Qwen 模型:在 LLM 配置中配置 api_key 2. LLM 配置示例: ```python llm_cfg = { 'model': 'qwen-max', 'model_server': 'dashscope', 'api_key': 'your-api-key' } ``` 或者设置环境变量DASHSCOPE_API_KEY ## 使用方法 ### 视觉故事创作 ```python from pic_2_doc import VisualStorytelling bot = VisualStorytelling(llm=llm_cfg) image = './resource/article.png' messages = [Message('user', [ContentItem(image=image)])] messages[-1]['content'].append(ContentItem(text='看图写作文')) for response in bot.run(messages): for msg in response: if msg.get('content'): print(msg['content']) ``` ### 图像生成 ```python from my_image_gen import MyImageGen # 创建实例并生成图像 tool = MyImageGen() result = tool.call('{"prompt": "你的图像描述"}') # 返回图像 URL ``` ### 天气查询 ```python from my_amap_weather import MyAmapWeather tool = MyAmapWeather() weather_info = tool.call(params={'location': '通州区'}) print(weather_info) ``` ## 项目结构 - `pic_2_doc.py`:视觉故事创作实现 - `my_image_gen.py`:图像生成服务 - `my_amap_weather.py`:天气查询服务 - `qwen_llm.py`:基础 LLM 配置和使用 - `resource/`:包含必要的资源和配置文件 ## 注意事项 确保安全处理 API 密钥,切勿将其提交到版本控制系统。在生产部署中使用环境变量或安全的配置管理方式。