# AIGC Space - AI模型广场 一个集成多种AI功能的综合平台,支持文本对话、图像生成、音频合成、视频生成等多种AI服务。 ## 🌟 核心功能 ### 💬 智能对话 - 支持多种大语言模型(Qwen、DeepSeek、Kimi等) - **🔍 联网搜索功能** - 实时信息检索,获取最新数据 - 多轮对话记录和管理 - 流式输出支持 ### 🎨 图像生成 - 多种AI绘画模型支持 - 自定义参数调节 - 批量生成和管理 ### 🎵 音频合成 - 文本转语音(TTS) - 语音克隆 - 多种音色选择 ### 🎬 视频生成 - AI视频合成 - 多种视频模型支持 ## 🔍 联网搜索功能亮点 ### 实时信息检索 - 获取最新的网络信息,解决训练数据时效性限制 - 支持天气、股票、汇率等垂直领域的精准查询 - 多种搜索策略:turbo(快速)、max(详尽)、agent(智能) ### 高级功能 - **引用和溯源**: 提供搜索来源URL和引用标注 - **流式搜索**: 完全兼容流式对话模式 - **自然语言搜索控制**: 精确控制搜索范围和方向 - **优雅降级**: 搜索失败时自动降级到普通对话模式 ### 支持的垂直领域 - 🌤️ 天气预报 - 📈 股票行情 - 💱 汇率查询 - ⛽ 油价信息 - 📅 万年历 - 🥇 金价银价 - 🎲 彩票开奖 - 🎬 影视资讯 - 🚗 车牌限行 - ⚽ 足球赛事 ## 🚀 快速开始 ### 环境要求 - Python 3.11+ - Node.js 16+ - PostgreSQL 13+ ### 后端启动 ```bash cd backend # 安装依赖 pip install -r requirements.txt # 配置环境变量 cp .env.example .env # 编辑 .env 文件,配置数据库和API密钥 # 配置搜索功能(可选) export DASHSCOPE_API_KEY="your_dashscope_api_key" export LLM_SEARCH_ENABLED=true # 数据库迁移 python scripts/apply_search_migrations.py # 启动服务 uvicorn main:app --host 0.0.0.0 --port 8000 --reload ``` ### 前端启动 ```bash cd frontend # 安装依赖 npm install # 启动开发服务器 npm run dev ``` ### 搜索功能配置检查 ```bash cd backend python scripts/check_search_config.py ``` ## 📖 文档 ### 搜索功能文档 - **[快速开始指南](./backend/docs/llm_web_search_quick_start.md)** - 5分钟快速上手搜索功能 - **[完整功能指南](./backend/docs/llm_web_search_complete_guide.md)** - 全面的搜索功能介绍 - **[API使用指南](./backend/docs/api_search_usage.md)** - 详细的API接口文档 - **[配置指南](./backend/docs/llm_web_search_configuration.md)** - 搜索功能配置说明 - **[故障排除指南](./backend/docs/llm_web_search_troubleshooting.md)** - 常见问题解决 ### 其他文档 - [数据库架构](./docs/database_schema.md) - [API文档](./backend/docs/) ## 🔧 技术栈 ### 后端 - **FastAPI** - 现代化的Python Web框架 - **SQLAlchemy** - ORM数据库操作 - **PostgreSQL** - 主数据库 - **阿里云百炼** - LLM服务和联网搜索 - **Hypothesis** - 属性测试框架 ### 前端 - **React** - 用户界面框架 - **TypeScript** - 类型安全的JavaScript - **Vite** - 现代化构建工具 - **Tailwind CSS** - 实用优先的CSS框架 ## 🧪 测试 ### 运行后端测试 ```bash cd backend # 运行所有测试 python -m pytest # 运行搜索功能测试 python -m pytest tests/test_*search*.py -v # 运行属性测试 python -m pytest tests/test_property_*.py -v ``` ### 运行前端测试 ```bash cd frontend npm test ``` ## 📊 API示例 ### 基础对话 ```bash curl -X POST "http://localhost:8000/api/llm/chat" \ -H "Content-Type: application/json" \ -d '{ "model": "qwen-plus", "messages": [{"role": "user", "content": "你好"}] }' ``` ### 联网搜索对话 ```bash curl -X POST "http://localhost:8000/api/llm/chat" \ -H "Content-Type: application/json" \ -d '{ "model": "qwen-plus", "messages": [{"role": "user", "content": "今天北京天气怎么样?"}], "search_options": { "enable_search": true, "enable_search_extension": true, "enable_source": true } }' ``` ### 垂直领域搜索 ```bash curl -X POST "http://localhost:8000/api/llm/chat" \ -H "Content-Type: application/json" \ -d '{ "model": "qwen-plus", "messages": [{"role": "user", "content": "美元兑人民币汇率"}], "search_options": { "enable_search": true, "enable_search_extension": true, "search_strategy": "turbo" } }' ``` ## 🔍 搜索功能使用示例 ### Python代码示例 ```python from app.schemas.llm_schema import SearchOptions, EnhancedChatRequest, ChatMessage # 创建搜索增强的对话请求 request = EnhancedChatRequest( model="qwen-plus", messages=[ChatMessage(role="user", content="最新AI技术发展")], search_options=SearchOptions( enable_search=True, search_strategy="turbo", freshness=7, # 搜索最近7天的内容 enable_source=True, # 返回搜索来源 enable_citation=True, # 启用引用标注 intention_options={ "prompt_intervene": "重点搜索AI技术突破和大语言模型发展" } ) ) ``` ### JavaScript前端示例 ```javascript const response = await fetch('/api/llm/chat', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ model: 'qwen-plus', messages: [{ role: 'user', content: '2024年人工智能有哪些突破?' }], search_options: { enable_search: true, search_strategy: 'max', enable_source: true, enable_citation: true, citation_format: '[ref_]' } }) }); const result = await response.json(); console.log('AI回复:', result.data.content); console.log('搜索来源:', result.data.search_results); ``` ## 🛠️ 开发 ### 项目结构 ``` ├── backend/ # 后端服务 │ ├── app/ # 应用代码 │ │ ├── models/ # 数据模型 │ │ ├── routers/ # API路由 │ │ ├── services/ # 业务逻辑 │ │ └── schemas/ # 数据模式 │ ├── docs/ # 后端文档 │ ├── examples/ # 代码示例 │ ├── tests/ # 测试代码 │ └── migrations/ # 数据库迁移 ├── frontend/ # 前端应用 │ ├── components/ # React组件 │ ├── pages/ # 页面组件 │ ├── services/ # API服务 │ └── types/ # TypeScript类型 └── docs/ # 项目文档 ``` ### 搜索功能架构 ``` ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ Frontend │ │ LLM Service │ │ DashScope API │ │ │ │ │ │ │ │ Search Options │───▶│ Search Options │───▶│ Web Search │ │ UI Components │ │ Validator │ │ Vertical Domain │ │ │ │ │ │ │ └─────────────────┘ └─────────────────┘ └─────────────────┘ │ ▼ ┌─────────────────┐ │ Citation │ │ Formatter │ └─────────────────┘ ``` ## 🤝 贡献 欢迎贡献代码!请遵循以下步骤: 1. Fork 项目 2. 创建功能分支 (`git checkout -b feature/AmazingFeature`) 3. 提交更改 (`git commit -m 'Add some AmazingFeature'`) 4. 推送到分支 (`git push origin feature/AmazingFeature`) 5. 开启 Pull Request ### 开发规范 - 后端代码遵循 PEP 8 规范 - 前端代码使用 ESLint 和 Prettier - 提交信息使用约定式提交格式 - 新功能需要包含测试用例 - 重要功能需要更新文档 ## 📄 许可证 本项目采用 MIT 许可证 - 查看 [LICENSE](LICENSE) 文件了解详情。 ## 🙏 致谢 - [阿里云百炼](https://dashscope.aliyuncs.com/) - 提供LLM服务和联网搜索API - [FastAPI](https://fastapi.tiangolo.com/) - 现代化的Python Web框架 - [React](https://reactjs.org/) - 用户界面构建库 - [Hypothesis](https://hypothesis.readthedocs.io/) - 属性测试框架 ## 📞 联系我们 - 项目主页: [GitHub Repository](https://github.com/your-org/aigc-space) - 问题反馈: [GitHub Issues](https://github.com/your-org/aigc-space/issues) - 技术支持: support@example.com --- **开始使用搜索功能**: 查看 [搜索功能快速开始指南](./backend/docs/llm_web_search_quick_start.md) 快速上手!