Summary: - Implement Prompt management infrastructure and core services - Build admin portal frontend with light theme - Integrate CodeMirror 6 editor for non-technical users Phase 3.5.1: Infrastructure Setup - Create capability_schema for Prompt storage - Add prompt_templates and prompt_versions tables - Add prompt:view/edit/debug/publish permissions - Migrate RVW prompts to database (RVW_EDITORIAL, RVW_METHODOLOGY) Phase 3.5.2: PromptService Core - Implement gray preview logic (DRAFT for debuggers, ACTIVE for users) - Module-level debug control (setDebugMode) - Handlebars template rendering - Variable extraction and validation (extractVariables, validateVariables) - Three-level disaster recovery (database -> cache -> hardcoded fallback) Phase 3.5.3: Management API - 8 RESTful endpoints (/api/admin/prompts/*) - Permission control (PROMPT_ENGINEER can edit, SUPER_ADMIN can publish) Phase 3.5.4: Frontend Management UI - Build admin portal architecture (AdminLayout, OrgLayout) - Add route system (/admin/*, /org/*) - Implement PromptListPage (filter, search, debug switch) - Implement PromptEditor (CodeMirror 6 simplified for clinical users) - Implement PromptEditorPage (edit, save, publish, test, version history) Technical Details: - Backend: 6 files, ~2044 lines (prompt.service.ts 596 lines) - Frontend: 9 files, ~1735 lines (PromptEditorPage.tsx 399 lines) - CodeMirror 6: Line numbers, auto-wrap, variable highlight, search, undo/redo - Chinese-friendly: 15px font, 1.8 line-height, system fonts Next Step: Phase 3.5.5 - Integrate RVW module with PromptService Tested: Backend API tests passed (8/8), Frontend pending user testing Status: Ready for Phase 3.5.5 RVW integration
101 lines
2.7 KiB
TypeScript
101 lines
2.7 KiB
TypeScript
/**
|
||
* 兜底 Prompt(Hardcoded Fallbacks)
|
||
*
|
||
* 三级容灾机制的最后一道防线:
|
||
* 1. 正常:从数据库获取 ACTIVE 版本
|
||
* 2. 缓存:数据库不可用时使用缓存
|
||
* 3. 兜底:缓存也失效时使用这里的 hardcoded 版本
|
||
*
|
||
* ⚠️ 注意:这里的 Prompt 是最基础版本,仅保证系统不崩溃
|
||
* 实际生产环境应该始终使用数据库中的版本
|
||
*/
|
||
|
||
import type { ModelConfig } from './prompt.types.js';
|
||
|
||
interface FallbackPrompt {
|
||
content: string;
|
||
modelConfig: ModelConfig;
|
||
}
|
||
|
||
/**
|
||
* RVW 模块兜底 Prompt
|
||
*/
|
||
const RVW_FALLBACKS: Record<string, FallbackPrompt> = {
|
||
RVW_EDITORIAL: {
|
||
content: `你是一位专业的医学期刊编辑,负责评估稿件的规范性。
|
||
|
||
【评估标准】
|
||
1. 文稿科学性与实用性
|
||
2. 文题(中文不超过20字,英文不超过10实词)
|
||
3. 作者格式
|
||
4. 摘要(300-500字,含目的、方法、结果、结论)
|
||
5. 关键词(2-5个)
|
||
6. 医学名词和药物名称
|
||
7. 缩略语
|
||
8. 计量单位
|
||
9. 图片格式
|
||
10. 动态图像
|
||
11. 参考文献
|
||
|
||
请输出JSON格式的评估结果,包含overall_score和items数组。`,
|
||
modelConfig: { model: 'deepseek-v3', temperature: 0.3 },
|
||
},
|
||
|
||
RVW_METHODOLOGY: {
|
||
content: `你是一位资深的医学统计学专家,负责评估稿件的方法学质量。
|
||
|
||
【评估框架】
|
||
第一部分:科研设计评估(研究类型、对象、对照、质控)
|
||
第二部分:统计学方法描述(软件、方法、混杂因素)
|
||
第三部分:统计分析评估(方法正确性、结果描述)
|
||
|
||
请输出JSON格式的评估结果,包含overall_score和parts数组。`,
|
||
modelConfig: { model: 'deepseek-v3', temperature: 0.3 },
|
||
},
|
||
};
|
||
|
||
/**
|
||
* ASL 模块兜底 Prompt(预留)
|
||
*/
|
||
const ASL_FALLBACKS: Record<string, FallbackPrompt> = {
|
||
ASL_SCREENING: {
|
||
content: `你是一位文献筛选专家,负责根据纳入排除标准筛选文献。
|
||
|
||
请根据提供的标准对文献进行筛选,输出JSON格式的结果。`,
|
||
modelConfig: { model: 'deepseek-v3', temperature: 0.2 },
|
||
},
|
||
};
|
||
|
||
/**
|
||
* 所有模块的兜底 Prompt 汇总
|
||
*/
|
||
export const FALLBACK_PROMPTS: Record<string, FallbackPrompt> = {
|
||
...RVW_FALLBACKS,
|
||
...ASL_FALLBACKS,
|
||
};
|
||
|
||
/**
|
||
* 获取兜底 Prompt
|
||
*
|
||
* @param code Prompt 代码
|
||
* @returns 兜底 Prompt 或 undefined
|
||
*/
|
||
export function getFallbackPrompt(code: string): FallbackPrompt | undefined {
|
||
return FALLBACK_PROMPTS[code];
|
||
}
|
||
|
||
/**
|
||
* 检查是否有兜底 Prompt
|
||
*/
|
||
export function hasFallbackPrompt(code: string): boolean {
|
||
return code in FALLBACK_PROMPTS;
|
||
}
|
||
|
||
/**
|
||
* 获取所有兜底 Prompt 的代码列表
|
||
*/
|
||
export function getAllFallbackCodes(): string[] {
|
||
return Object.keys(FALLBACK_PROMPTS);
|
||
}
|
||
|