ai-rule-engine/README.md
2026-05-19 03:51:25 +08:00

46 lines
1.1 KiB
Markdown
Raw Permalink 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.

# AI Rule Engine
将自然语言规则描述通过 AI 转换为可执行 Python 函数的规则引擎。
## 核心功能
- **自然语言 → 代码**:使用 LLM 将规则描述转换为 Python 函数
- **安全执行**RestrictedPython 沙箱隔离
- **快速校验**:规则编译后存储,后续判断无需 LLM 调用
- **冲突检测**:自动检测矛盾规则
- **LLM 兜底**:无匹配时自动调用 LLM 补充规则
## 技术栈
- Python 3.10+
- SQLite规则存储
- LLM APIOpenAI GPT-4o / Anthropic Claude
## 项目结构
```
src/rule_engine/
├── api.py # REST API
├── compiler.py # 规则编译
├── conflict.py # 冲突检测
├── executor.py # 规则执行
├── matcher.py # 规则匹配
├── store.py # SQLite 存储
├── web.py # HTTP 服务器
└── models.py # 数据模型
tests/
```
## 快速开始
```python
from rule_engine import RuleEngine
engine = RuleEngine()
engine.create_rule("规则名称", "当 x > 10 时返回 true")
result = engine.evaluate("x=15")
```
## License
MIT