feat(web3): AI 生成正则 + Python re 测试 + 规则弹窗保存按钮
LLM 接入(P9 plan 阶段)
- 后端:
- backend/core/llm.py 从 web/core/llm.py 拷贝,default_config_path() 改读 web3/backend/configs/llm.yaml
- backend/core/ai_regex.py:强制走 LLM(删规则库),LLM 返回用 re.compile 校验,编译失败回弹修复,最多 5 次重试
- backend/routers/ai.py:注册 POST /api/ai/regex
- backend/configs/llm.example.yaml:多 provider 示例模板(真实 llm.yaml 已 gitignore)
- backend/app.py:注册 ai_router
- backend/requirements.txt:+anthropic +openai +pyyaml
- 前端:
- src/api/ai.js:genRegex(desc)
- src/components/RuleModal.vue:删前端 mock 改调后端
测试改走 Python re(避免 JS RegExp 方言差异)
- backend/core/ai_regex.py:+test_regex(regex, value) → {ok, match, error, groups}
- backend/routers/ai.py:+POST /api/regex/test
- src/api/ai.js:+testRegex(regex, value)
- src/components/RuleModal.vue:testRegex() 改调后端,捕获组带回前端展示
规则弹窗保存按钮
- src/components/RuleModal.vue:emit 'save' + 取消/保存两按钮 + onSave() + hasValidRules
(必须 ≥1 条规则 + desc/regex 都非空才允许保存)
- watch 监听 [open, field.key],每次打开从父组件重新同步
- src/components/TaskModal.vue:onRuleSave 回写 field.rules(徽章数字刷新)
- TaskModal onSave() payload 加 fields: [{key, en, cn, rules, show_default}](P4 落库用)
端到端验证
- 身份证/URL/UUID/产品型号 多 desc 都通过 LLM 生成 + Python re 校验
- 7 例 /api/regex/test 覆盖:真身份证、短串、捕获组日期、分隔符错、空 value、语法错、空 regex
踩坑
- 规则库'数字'关键词过宽易误命中,按用户意见删整段强制走 LLM
- curl 中文 JSON body 在 Git Bash 转义破坏,用 --data @file 或 printf
- python web3/backend/start.py 报 ModuleNotFoundError,要 python -m web3.backend.start
- Vue3 const 不 hoist,hasValidRules 必须放在 ruleList 声明之后
Showing
web3/backend/core/llm.py
0 → 100644
This diff is collapsed.
web3/backend/routers/ai.py
0 → 100644
web3/src/api/ai.js
0 → 100644
Please register or sign in to comment