技术拆解-浸入式学语言助手

技术方案

提取网页内容

亮点设计

Service化编程

将内容抽象分类为不同的Service,比如:

  • background
  • content
  • Prompt

提示词的规范

结构化组装提示词,这样从程序上就约束了提示词的规范:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**
* 生成统一提示词 - 精简版
*/
public getUnifiedPrompt(config: PromptConfig): string {
const { targetLanguage, userLevel, replacementRate } = config;

const components = [
this.generateBaseInstruction(), // 保持,但稍精简
this.generateTaskAndRules(targetLanguage), // 新合并:任务+规则
this.generateUserConfig(userLevel, replacementRate), // 新合并:水平+比例
this.generateFormatRequirements(), // 强化强调
this.generateExamples(targetLanguage), // 增加示例
].filter((component) => component.trim() !== '');

return components.join('\n\n');
}