feat(ssa): Complete Phase I-IV intelligent dialogue and tool system development
Phase I - Session Blackboard + READ Layer: - SessionBlackboardService with Postgres-Only cache - DataProfileService for data overview generation - PicoInferenceService for LLM-driven PICO extraction - Frontend DataContextCard and VariableDictionaryPanel - E2E tests: 31/31 passed Phase II - Conversation Layer LLM + Intent Router: - ConversationService with SSE streaming - IntentRouterService (rule-first + LLM fallback, 6 intents) - SystemPromptService with 6-segment dynamic assembly - TokenTruncationService for context management - ChatHandlerService as unified chat entry - Frontend SSAChatPane and useSSAChat hook - E2E tests: 38/38 passed Phase III - Method Consultation + AskUser Standardization: - ToolRegistryService with Repository Pattern - MethodConsultService with DecisionTable + LLM enhancement - AskUserService with global interrupt handling - Frontend AskUserCard component - E2E tests: 13/13 passed Phase IV - Dialogue-Driven Analysis + QPER Integration: - ToolOrchestratorService (plan/execute/report) - analysis_plan SSE event for WorkflowPlan transmission - Dual-channel confirmation (ask_user card + workspace button) - PICO as optional hint for LLM parsing - E2E tests: 25/25 passed R Statistics Service: - 5 new R tools: anova_one, baseline_table, fisher, linear_reg, wilcoxon - Enhanced guardrails and block helpers - Comprehensive test suite (run_all_tools_test.js) Documentation: - Updated system status document (v5.9) - Updated SSA module status and development plan (v1.8) Total E2E: 107/107 passed (Phase I: 31, Phase II: 38, Phase III: 13, Phase IV: 25) Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
135
backend/scripts/seed-ssa-phase4-prompts.ts
Normal file
135
backend/scripts/seed-ssa-phase4-prompts.ts
Normal file
@@ -0,0 +1,135 @@
|
||||
/**
|
||||
* Phase IV — analyze 意图 Prompt 种子脚本
|
||||
*
|
||||
* 写入 Prompt 模板:
|
||||
* 1. SSA_ANALYZE_PLAN — 指导 LLM 用自然语言解释分析方案
|
||||
*
|
||||
* 运行方式: npx tsx scripts/seed-ssa-phase4-prompts.ts
|
||||
* 前置: 数据库已启动
|
||||
*/
|
||||
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
interface PromptDef {
|
||||
code: string;
|
||||
name: string;
|
||||
description: string;
|
||||
variables: string[];
|
||||
content: string;
|
||||
modelConfig: Record<string, any>;
|
||||
}
|
||||
|
||||
const PROMPTS: PromptDef[] = [
|
||||
{
|
||||
code: 'SSA_ANALYZE_PLAN',
|
||||
name: 'SSA 分析方案说明指令',
|
||||
description: 'Phase IV — analyze 意图,指导 LLM 向用户解释生成的分析方案',
|
||||
variables: [],
|
||||
content: `## 当前任务:解释分析方案
|
||||
|
||||
系统已根据用户的分析需求和数据特征,通过决策引擎生成了一份统计分析方案。方案详情在"工具执行结果"中给出。
|
||||
|
||||
### 输出要求(严格遵守)
|
||||
|
||||
1. **首先用一句话总结推荐方案**(如:"建议对BMI和血压做Pearson相关分析,并配合散点图展示")
|
||||
2. 然后简要说明:
|
||||
- **为什么选择这些方法** — 结合数据特征和研究目的解释
|
||||
- **分析步骤的逻辑** — 用非技术语言说明各步骤的作用和顺序
|
||||
- **需要注意的事项** — 如前提条件检验、可能的降级方案
|
||||
3. 最后提示用户确认方案
|
||||
|
||||
### 禁止事项
|
||||
- 严禁重复列出步骤编号和工具代码(用户已在右侧面板看到)
|
||||
- 严禁使用过多统计术语,要用用户能理解的语言
|
||||
- 严禁编造数据特征或假设用户未提供的信息
|
||||
- 严禁直接执行分析,只解释方案`,
|
||||
modelConfig: { model: 'deepseek-v3', temperature: 0.5, maxTokens: 1200 },
|
||||
},
|
||||
];
|
||||
|
||||
async function upsertPrompt(def: PromptDef): Promise<void> {
|
||||
const existing = await prisma.prompt_templates.findUnique({
|
||||
where: { code: def.code },
|
||||
});
|
||||
|
||||
if (existing) {
|
||||
const latestVersion = await prisma.prompt_versions.findFirst({
|
||||
where: { template_id: existing.id },
|
||||
orderBy: { version: 'desc' },
|
||||
});
|
||||
|
||||
const activeVersion = await prisma.prompt_versions.findFirst({
|
||||
where: { template_id: existing.id, status: 'ACTIVE' },
|
||||
});
|
||||
|
||||
if (activeVersion && activeVersion.content === def.content) {
|
||||
console.log(` ⏭️ ${def.code} 内容未变化,跳过`);
|
||||
return;
|
||||
}
|
||||
|
||||
const newVersion = (latestVersion?.version ?? 0) + 1;
|
||||
|
||||
await prisma.prompt_versions.updateMany({
|
||||
where: { template_id: existing.id, status: 'ACTIVE' },
|
||||
data: { status: 'ARCHIVED' },
|
||||
});
|
||||
|
||||
await prisma.prompt_versions.create({
|
||||
data: {
|
||||
template_id: existing.id,
|
||||
version: newVersion,
|
||||
content: def.content,
|
||||
model_config: def.modelConfig,
|
||||
status: 'ACTIVE',
|
||||
changelog: `Phase IV v${newVersion}: ${def.description}`,
|
||||
created_by: 'system-seed',
|
||||
},
|
||||
});
|
||||
|
||||
console.log(` ✅ ${def.code} 更新到 v${newVersion}`);
|
||||
} else {
|
||||
const template = await prisma.prompt_templates.create({
|
||||
data: {
|
||||
code: def.code,
|
||||
name: def.name,
|
||||
module: 'SSA',
|
||||
description: def.description,
|
||||
variables: def.variables,
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.prompt_versions.create({
|
||||
data: {
|
||||
template_id: template.id,
|
||||
version: 1,
|
||||
content: def.content,
|
||||
model_config: def.modelConfig,
|
||||
status: 'ACTIVE',
|
||||
changelog: `Phase IV v1.0: ${def.description}`,
|
||||
created_by: 'system-seed',
|
||||
},
|
||||
});
|
||||
|
||||
console.log(` ✅ ${def.code} 创建成功 (id=${template.id})`);
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('🚀 开始写入 SSA Phase IV Prompt 模板...\n');
|
||||
|
||||
for (const def of PROMPTS) {
|
||||
console.log(`📝 处理 ${def.code} (${def.name})...`);
|
||||
await upsertPrompt(def);
|
||||
}
|
||||
|
||||
console.log(`\n✅ 全部 ${PROMPTS.length} 个 Prompt 模板写入完成!`);
|
||||
}
|
||||
|
||||
main()
|
||||
.catch(e => {
|
||||
console.error('❌ Seed 失败:', e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(() => prisma.$disconnect());
|
||||
Reference in New Issue
Block a user