Files
erp-ass/backend/app/core/prompts.py
dazhuang acd73431ae feat: implement ERP AI Assistant Phase 1
Backend (FastAPI + SQLAlchemy + Claude API + RAG):
- Config management with Pydantic v2
- Database engine with connection pooling and SQL injection prevention
- AI engine with Claude API integration (support custom base URL)
- RAG engine with ChromaDB and sentence-transformers
- Requirement analysis service
- Config generation service
- Executor engine with SQL validation
- REST API endpoints: /analyze, /generate, /execute

Frontend (Vue 3 + Element Plus + Pinia):
- Complete 3-step workflow: analyze → generate → execute
- Step indicator with progress visualization
- Analysis result display with field table
- SQL preview with monospace font
- Execute confirmation dialog with safety warning
- Execution result display
- State management with Pinia
- API service integration

Security:
- SQL injection prevention with parameterized queries
- Dangerous SQL operation blocking
- Database password URL encoding
- Transaction auto-rollback
- Pydantic config validation

Features:
- Natural language requirement analysis
- Automated SQL configuration generation
- Safe execution with human review
- LAN access support
- Custom Claude API endpoint support

Documentation:
- README with quick start guide
- Quick start guide
- LAN access configuration
- Dependency fixes guide
- Claude API configuration
- Git operation guide
- Implementation report

Dependencies fixed:
- numpy<2.0.0 for chromadb compatibility
- sentence-transformers==2.7.0 for huggingface_hub compatibility

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 14:23:20 +00:00

145 lines
4.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
Prompt 模板定义
模板说明:
- SYSTEM_PROMPT: 系统提示词,定义 Claude 的角色和专业领域
- ANALYZE_PROMPT_TEMPLATE: 需求解析模板占位符user_input, knowledge_context, existing_tables
- GENERATE_PROMPT_TEMPLATE: 配置生成模板占位符requirements, platform_rules, similar_cases
"""
SYSTEM_PROMPT = """你是一个 ERP 平台配置专家助手,专门帮助开发人员配置一零软件结构化开发平台。
## 你的职责
你是 ERP 系统配置和开发的专业顾问,负责:
1. 分析用户需求,理解业务场景
2. 设计合理的数据库表结构
3. 生成符合平台规范的配置方案
4. 提供完整的 SQL 脚本和配置说明
## 平台知识
你熟悉以下平台概念:
- 窗体类型:基础资料、单据、报表、系统设置等
- 标准字段命名规范F 开头的主键、FPrefix 前缀的自定义字段
- 配置流程:需求分析 → 表结构设计 → 功能配置 → 页面配置 → 菜单配置
- 命名约定:表名以 T_开头功能号以功能类别前缀开头
## 输出要求
1. 提供完整的 SQL 脚本,包括建表语句、函数配置、页面配置等
2. 确保配置符合平台规范和最佳实践
3. 进行风险评估,提示潜在问题
4. 使用 JSON 格式输出结构化结果
5. 所有字段和表名使用英文,注释使用中文
请始终保持专业、严谨的工作态度,确保输出的配置方案可落地执行。"""
ANALYZE_PROMPT_TEMPLATE = """请分析以下用户需求,生成结构化的需求分析文档。
## 用户输入
{user_input}
## 相关知识上下文
{knowledge_context}
## 现有表结构
{existing_tables}
## 分析要求
请输出结构化的需求分析文档,使用 JSON 格式,包含以下字段:
# Note: Use {{ and }} to escape braces for .format() - rendered as literal { and }
```json
{{
"功能名称": "功能的中文名称",
"功能号建议": "建议的功能编号,如 SAL001",
"窗体类型": "基础资料/单据/报表/系统设置",
"主表名建议": "建议的主表名,如 T_SAL_Order",
"从表名建议": "建议的从表名,如 T_SAL_OrderEntry",
"主表字段": [
{{"字段名": "FOrderId", "字段类型": "varchar(50)", "中文名称": "订单编号", "必填": true}},
...
],
"从表字段": [
{{"字段名": "FEntryId", "字段类型": "int", "中文名称": "分录 ID", "必填": true}},
...
],
"业务需求": "详细的业务需求描述",
"关联表": ["相关表 1", "相关表 2"],
"风险提示": ["潜在风险 1", "潜在风险 2"]
}}
```
## 注意事项
1. 字段命名遵循平台规范:主键以 F 开头,使用 PascalCase
2. 表名以 T_开头使用模块前缀
3. 考虑必填字段、默认值、数据长度等约束
4. 识别必要的业务关联关系
5. 评估潜在的数据一致性和性能风险"""
GENERATE_PROMPT_TEMPLATE = """请根据需求分析结果,生成完整的平台配置方案。
## 需求分析结果
{requirements}
## 平台规则
{platform_rules}
## 类似案例参考
{similar_cases}
## 生成要求
请生成完整的配置方案,使用 JSON 格式,包含以下内容:
# Note: Use {{ and }} to escape braces for .format() - rendered as literal { and }
```json
{{
"table_sql": "建表 SQL 语句,包括主表和从表",
"function_config_sql": "功能配置 SQL 语句",
"page_config_sql": "页面配置 SQL 语句",
"menu_config_sql": "菜单配置 SQL 语句",
"ikey_config_sql": "IKEY 配置 SQL 语句",
"config_summary": {{
"created_tables": ["表 1", "表 2"],
"main_entities": ["主要实体 1", "主要实体 2"],
"relationships": "表间关系说明"
}},
"implementation_notes": "实施注意事项",
"validation_rules": ["验证规则 1", "验证规则 2"]
}}
```
## 配置规范
1. **建表 SQL**:
- 主键使用 FId 或 F+ 表名缩写 + Id
- 包含创建时间、创建人、更新时间、更新人等审计字段
- 使用合适的索引提高查询性能
2. **功能配置**:
- 定义功能号、功能名称、功能类型
- 配置数据权限和操作权限
3. **页面配置**:
- 配置表单布局、字段顺序
- 设置字段属性(必填、只读、可见性)
4. **菜单配置**:
- 配置菜单层级、图标、排序
5. **IKEY 配置**:
- 配置编码规则、生成策略
## 注意事项
- 所有 SQL 语句需要语法正确、可直接执行
- 配置需要符合平台规范
- 考虑扩展性和维护性
- 提供必要的注释说明"""