feat: 提示词管理
This commit is contained in:
parent
bf8c9e1e12
commit
aa6ab0d379
13
src/index.ts
13
src/index.ts
@ -1,16 +1,25 @@
|
|||||||
import { ContextManager } from './context.js';
|
import { ContextManager } from './context.js';
|
||||||
import { chat } from './llm.js';
|
import { chat } from './llm.js';
|
||||||
|
import { PROMPTS } from './prompts/system.js';
|
||||||
import * as readline from 'node:readline/promises';
|
import * as readline from 'node:readline/promises';
|
||||||
|
|
||||||
|
const promptName = process.argv[2] || 'default';
|
||||||
|
const systemPrompt = PROMPTS[promptName as keyof typeof PROMPTS];
|
||||||
|
|
||||||
|
if (!systemPrompt) {
|
||||||
|
console.error(`未知提示词: ${promptName},可选: ${Object.keys(PROMPTS).join(', ')}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
const context = new ContextManager();
|
const context = new ContextManager();
|
||||||
context.add({ role: 'system', content: '你是一个直爽的小助手,回答尽量简洁。' });
|
context.add({ role: 'system', content: systemPrompt });
|
||||||
|
|
||||||
const rl = readline.createInterface({
|
const rl = readline.createInterface({
|
||||||
input: process.stdin,
|
input: process.stdin,
|
||||||
output: process.stdout,
|
output: process.stdout,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Agent已启动,输入 "exit" 退出。\n');
|
console.log(`提示词模式: ${promptName},输入 "exit" 退出。\n`);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const userInput = await rl.question('我: ');
|
const userInput = await rl.question('我: ');
|
||||||
|
|||||||
9
src/prompts/system.ts
Normal file
9
src/prompts/system.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export const PROMPTS = {
|
||||||
|
default: '你是一个直爽的代码审查员,回答尽量简洁。',
|
||||||
|
toxic: '你是一个毒舌代码审查员,用讽刺的语气表达。',
|
||||||
|
json: `你是一个 API 格式化助手。你的回答必须是纯 JSON,不要加任何解释。
|
||||||
|
{
|
||||||
|
"answer": "你的回答",
|
||||||
|
"confidence": 0.0-1.0 之间的数字
|
||||||
|
}`,
|
||||||
|
} as const;
|
||||||
Loading…
x
Reference in New Issue
Block a user