init
This commit is contained in:
@@ -9,30 +9,51 @@
|
||||
- 💬 **多轮对话**: 内置对话状态管理和上下文维护
|
||||
- 📊 **工作流管理**: 多种工作流类型,支持会话和工具使用
|
||||
- ⚙️ **配置管理**: 统一的环境变量和配置管理
|
||||
- 🧩 **FastAPI 接入**: 提供 HTTP 接口对外服务
|
||||
- 🧭 **Nacos 注册**: 支持服务注册与心跳
|
||||
- 🧪 **测试支持**: 包含基础测试和示例代码
|
||||
|
||||
## 项目结构
|
||||
|
||||
```
|
||||
more_dots/
|
||||
├── agents/ # 代理模块
|
||||
│ ├── base_agent.py # 基础代理类
|
||||
│ ├── conversation_agent.py # 对话代理
|
||||
│ └── tool_agent.py # 工具使用代理
|
||||
├── tools/ # 工具模块
|
||||
│ ├── calculator.py # 计算器工具
|
||||
│ └── web_search.py # 网络搜索工具(占位符)
|
||||
├── workflows/ # 工作流管理
|
||||
│ └── workflow_manager.py # 工作流管理器
|
||||
├── examples/ # 使用示例
|
||||
│ └── basic_usage.py # 基础用法示例
|
||||
├── tests/ # 测试文件
|
||||
│ └── test_basic.py # 基础测试
|
||||
├── config.py # 配置文件
|
||||
├── agent/ # Agent 核心逻辑层
|
||||
│ ├── graph.py # LangGraph 图结构定义
|
||||
│ ├── nodes.py # 节点执行逻辑
|
||||
│ ├── state.py # Agent 状态定义
|
||||
│ ├── conversation.py # 对话代理
|
||||
│ └── tool.py # 工具代理
|
||||
├── api/ # API 接口层
|
||||
│ ├── endpoints.py # FastAPI 路由定义
|
||||
│ └── dependencies.py # API 依赖注入
|
||||
├── services/ # 服务层
|
||||
│ ├── llm_factory.py # LLM 实例工厂
|
||||
│ └── nacos_service.py # Nacos 集成
|
||||
├── schemas/ # 数据模型层
|
||||
│ ├── agent_input.py # 输入模型
|
||||
│ └── agent_output.py # 输出模型
|
||||
├── config/ # 配置层
|
||||
│ └── settings.py # 配置读取
|
||||
│ └── prompts.yaml # 提示词配置
|
||||
│ └── ragflow_templates/ # RAGFlow 模板(表名 -> 模板列表)
|
||||
│ └── table_metadata_prompts/ # 表模型元数据提示词
|
||||
├── tools/ # 工具模块
|
||||
│ ├── calculator.py # 计算器工具
|
||||
│ └── web_search.py # 网络搜索工具(占位符)
|
||||
├── workflows/ # 工作流管理
|
||||
│ └── workflow_manager.py
|
||||
├── examples/ # 使用示例
|
||||
│ └── basic_usage.py
|
||||
├── tests/ # 测试文件
|
||||
│ └── test_basic.py
|
||||
├── requirements.txt # 依赖包列表
|
||||
├── .env.example # 环境变量示例
|
||||
├── main.py # 主程序入口
|
||||
└── README.md # 项目说明
|
||||
├── config/
|
||||
│ ├── config.ini.example # 配置文件示例
|
||||
│ ├── config.ini # 本地配置(需自行创建)
|
||||
│ └── prompts.yaml # 提示词配置
|
||||
├── server.py # FastAPI 服务入口
|
||||
├── main.py # CLI 入口
|
||||
└── README.md # 项目说明
|
||||
```
|
||||
|
||||
## 快速开始
|
||||
@@ -43,14 +64,25 @@ more_dots/
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### 2. 配置环境变量
|
||||
### 2. 配置 config.ini
|
||||
|
||||
```bash
|
||||
# 复制环境变量文件
|
||||
cp .env.example .env
|
||||
# 复制配置文件
|
||||
cp config/config.ini.example config/config.ini
|
||||
|
||||
# 编辑 .env 文件,设置你的 OpenAI API 密钥
|
||||
OPENAI_API_KEY=your_openai_api_key_here
|
||||
# 编辑 config/config.ini,设置你的 API Key,并可添加多个模型配置
|
||||
[General]
|
||||
DEFAULT_MODEL_SECTION = gpt-4o
|
||||
MAX_RETRIES = 3
|
||||
TIMEOUT = 30
|
||||
|
||||
[gpt-4o]
|
||||
MODEL_NAME = gpt-4o
|
||||
OPENAI_API_KEY = your_openai_api_key_here
|
||||
|
||||
[gpt-3.5-turbo]
|
||||
MODEL_NAME = gpt-3.5-turbo
|
||||
OPENAI_API_KEY = your_openai_api_key_here
|
||||
```
|
||||
|
||||
### 3. 运行示例
|
||||
@@ -59,8 +91,14 @@ OPENAI_API_KEY=your_openai_api_key_here
|
||||
# 运行基础示例
|
||||
python examples/basic_usage.py
|
||||
|
||||
# 运行交互式 CLI
|
||||
# 运行交互式 CLI(默认模型)
|
||||
python main.py
|
||||
|
||||
# 运行交互式 CLI(指定模型配置段)
|
||||
python main.py gpt-3.5-turbo
|
||||
|
||||
# 运行 FastAPI 服务
|
||||
python server.py
|
||||
```
|
||||
|
||||
## 使用指南
|
||||
@@ -70,9 +108,55 @@ python main.py
|
||||
```python
|
||||
from workflows.workflow_manager import WorkflowManager, WorkflowType
|
||||
|
||||
# 创建工作流管理器
|
||||
# 创建工作流管理器(默认模型)
|
||||
manager = WorkflowManager()
|
||||
|
||||
# 创建工作流管理器(指定模型配置段)
|
||||
manager_alt = WorkflowManager(default_model_section="gpt-3.5-turbo")
|
||||
|
||||
### FastAPI 接口
|
||||
|
||||
启动服务后,可使用以下接口:
|
||||
|
||||
- `GET /health`:健康检查
|
||||
- `GET /nacos/status`:查看 Nacos 注册状态
|
||||
- `POST /api/workflows`:执行工作流
|
||||
|
||||
示例请求体:
|
||||
|
||||
```json
|
||||
{
|
||||
"input": "你好,帮我算 1 + 2",
|
||||
"session_id": null,
|
||||
"workflow_type": "conversation"
|
||||
}
|
||||
```
|
||||
|
||||
### Nacos 配置
|
||||
|
||||
在 `config/config.ini` 中开启 Nacos:
|
||||
|
||||
```ini
|
||||
[nacos]
|
||||
enabled = true
|
||||
server = localhost:8848
|
||||
namespace = public
|
||||
group_name = DEFAULT_GROUP
|
||||
cluster_name = DEFAULT
|
||||
heartbeat_interval = 5
|
||||
```
|
||||
|
||||
### RAGFlow 模板同步
|
||||
|
||||
模板文件位于 `config/ragflow_templates`,每个 JSON 对应一个表名与模板列表。
|
||||
同步脚本:
|
||||
|
||||
```bash
|
||||
python scripts/sync_ragflow_templates.py
|
||||
```
|
||||
|
||||
请在 `config/config.ini` 中配置 `ragflow.upload` 上传接口。
|
||||
|
||||
# 使用对话工作流
|
||||
result = manager.execute_workflow(
|
||||
WorkflowType.CONVERSATION,
|
||||
@@ -161,7 +245,6 @@ logging.basicConfig(level=logging.DEBUG)
|
||||
- `langchain`: LangChain 主包
|
||||
- `langgraph`: LangGraph 图工作流
|
||||
- `langchain-openai`: OpenAI 集成
|
||||
- `python-dotenv`: 环境变量管理
|
||||
- `pydantic`: 数据验证
|
||||
|
||||
## 许可证
|
||||
|
||||
Reference in New Issue
Block a user