Files
2026-08-21 11:06:49 +08:00

253 lines
6.7 KiB
Markdown
Executable File
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.
# 2026-04-02 - bbav20311 意图识别与RAG回复修复
## 项目信息
- **项目**: bbav20311
- **路径**: `/home/xia-lab/wutx/00test/bbav20311`
- **记录时间**: 2026-04-02
---
## 修复内容
### 1. 意图识别优化
**问题**: "帮我执行motif分析"被错误识别为基因家族鉴定
**修复文件**: `/gfa_core/mas/core/orchestrator.py`
**修改内容**:
- 在`_analysis_node`中添加LLM意图识别
- 支持识别以下分析类型:
- `identify`: 基因家族鉴定
- `phylogeny`: 进化树构建
- `motif`: Motif分析
- `domain`: 结构域分析
- `structure`: 基因结构分析
- `promoter`: 启动子分析
- `synteny`: 共线性分析
**代码片段**:
```python
# 使用LLM进行意图识别
intent_prompt = """你是一个基因家族分析系统的意图识别器...
分析类型(必须是以下之一):
- identify: 基因家族鉴定
- phylogeny: 进化树构建
- motif: Motif分析
...""")
```
---
### 2. RAG回复优化
**问题**: 回复泄露了CLI命令和系统内部信息
**修复文件**: `/gfa_core/mas/core/orchestrator.py`
**修改内容**:
- 修改knowledge节点的prompt
- 添加系统提示,禁止暴露内部信息
- 明确要求只回答用户问题本身
**修改前**:
```python
prompt = f"""基于以下参考资料回答问题...
参考资料: {context}
问题: {query}
请提供详细、准确的回答:"""
```
**修改后**:
```python
prompt = f"""你是一个基因家族分析专家...
参考资料: {context}
用户问题: {query}
请提供简洁、专业的回答。不要提及任何系统内部信息、代码、CLI命令或文件路径。"""
messages = [
LLMMessage(role="system", content="你是BotanicalBaseAgent基因家族分析系统的知识助手。只回答用户问题,不暴露任何系统内部信息。"),
LLMMessage(role="user", content=prompt)
]
```
---
## 验证结果(2026-04-02 10:00)
### 服务状态
| 组件 | 状态 |
|------|------|
| Redis | ✅ 运行中 (PID: 1460189) |
| Celery Worker | ✅ 运行中 (PID: 2216242) |
| FastAPI | ✅ 运行中 (前台模式稳定) |
### 意图识别验证 ✅
**测试用例**: "帮我执行motif分析"
**结果**:
```
[DEBUG] Intent analysis: type=motif, family=, species=
stage: motif ✅ 正确识别
agent: analysis ✅ 走到analysis节点
```
**修复内容**:
1. `_analysis_node` 中添加LLM意图识别
2. `_route_query` 添加motif/phylogeny/domain等关键词支持
3. 优先使用`_router_node`设置的mode进行路由
### RAG回复验证 ✅
**测试用例**: "什么是基因家族鉴定"
**结果**:
- 回复内容专业、面向用户
- `contains_cli: False` — 无CLI命令泄露
- 无文件路径、无代码、无系统内部信息
---
## 待办事项(全部完成 ✅)
1. ✅ 重新启动Celery Worker
2. ✅ 前端测试修复后的功能
3. ✅ 验证意图识别准确性
4. ✅ 验证RAG回复不再泄露系统信息
---
## 启动命令
```bash
# 启动Celery Worker
cd /home/xia-lab/wutx/00test/bbav20311
celery -A celery_app worker --loglevel=info --concurrency=1
# 启动FastAPI服务
cd /home/xia-lab/wutx/00test/bbav20311/apps/web/vue3
python3 main.py
```
---
## 关键修复代码
### 1. `_route_query` 路由优化
```python
def _route_query(self, state: GraphState) -> str:
query = state["query"].lower()
mode = state.get("mode", "faq")
# 优先使用router节点设置的mode
if mode == "analysis":
return "analysis"
if mode == "faq":
return "knowledge"
analysis_keywords = [
"鉴定", "分析", "帮我", "执行", "运行",
"identify", "analyze", "analysis", "run", "execute",
"motif", "phylogeny", "进化树", "结构域", "domain",
"启动子", "promoter", "共线性", "synteny",
]
for keyword in analysis_keywords:
if keyword in query:
return "analysis"
return "knowledge"
```
### 2. `_analysis_node` 意图识别
```python
# 使用LLM进行意图识别
intent_prompt = """分析用户的请求,提取以下信息:
1. 分析类型(identify/phylogeny/motif/domain/structure/promoter/synteny)
2. 基因家族名称
3. 物种
请以JSON格式回复..."""
```
---
## 3. 意图识别扩展(2026-04-02 17:00)
**问题**: RNA-Seq子阶段、Combo、PEP等分析无法识别
**修复文件**: `/gfa_core/mas/core/orchestrator.py`
**修改内容**:
- 扩展分析类型到19种:identify, phylogeny, motif, domain, structure, promoter, synteny, interspecies_synteny, karyotype, ppi, kaks, expression, enrichment, pep, combo, rna_seq_qc, rna_seq_mapping, rna_seq_quantification, trend, wgcna
- 添加50+生物信息学常用术语关键词
- 完善意图识别prompt,覆盖所有分析类型别名
---
## 4. PPI分析修复(2026-04-02 21:00 - 23:00)
**问题**: PPI分析失败,缺少ortholog_pairs.txt映射文件
**修复文件**:
- `/apps/web/pipeline_backend.py`
- `/apps/cli/run_ortholog.py`(新增)
**修改内容**:
1. **自动查找种间共线性结果**: 优先使用`interspecies_synteny/analysis/Ft.Ath.anchors`
2. **自动格式转换**: 将anchors格式转换为ortholog_pairs格式
3. **精准筛选**: 只筛选当前基因家族成员的映射关系
4. **格式修正**: 修正输出格式为`苦荞ID 拟南芥ID`(符合PPI脚本期望)
**关键代码**:
```python
# 从种间共线性结果中筛选当前基因家族的映射
if mapping_file and mapping_file.name.endswith(".anchors"):
gene_id_file = final_dir / f"{prefix}.final_members.id"
gene_family_ids = set()
# 读取基因家族成员...
# 只保留当前基因家族成员的映射
if ft_gene in gene_family_ids:
f_out.write(f"{ft_gene}\t{ath_gene}\n") # 苦荞ID 拟南芥ID
```
---
## 5. 种间共线性分析修复(2026-04-02 21:00)
**问题**: 种间共线性分析被错误识别为种内共线性
**修复文件**: `/gfa_core/mas/core/orchestrator.py`
**修改内容**:
- 将`interspecies`改为`interspecies_synteny`以匹配pipeline stage名称
- 添加stage名称映射:`interspecies` -> `interspecies_synteny`
---
## 6. 语法错误修复(2026-04-02 21:12)
**问题**: IndentationError: unexpected indent
**修复文件**: `/gfa_core/mas/core/orchestrator.py`
**修改内容**:
- 删除重复的guidance_map定义
- 修复缩进错误
---
## 修复文件清单
| 文件路径 | 修改类型 | 说明 |
|---------|---------|------|
| `/gfa_core/mas/core/orchestrator.py` | 修改 | 意图识别、路由、RAG回复优化 |
| `/apps/web/pipeline_backend.py` | 修改 | PPI分析自动查找/生成ortholog映射 |
| `/apps/cli/run_ortholog.py` | 新增 | 同源基因识别脚本(BLASTP) |
---
*记录时间: 2026-04-02 01:08*
*更新时间: 2026-04-03 01:03*