feat: add summary

This commit is contained in:
2025-06-28 02:46:50 +08:00
parent 204165bf73
commit e2d0720698
14 changed files with 158 additions and 15 deletions

View File

@@ -27,6 +27,14 @@ export const cmdList: {
key: 'call-xiaoxiao',
},
},
{
category: '指令总结',
description: `总结当前的笔记,缩写当前笔记的内容`,
action: {
path: 'tools',
key: 'summarize-note',
},
},
];
agent
@@ -96,4 +104,3 @@ ${text}
ctx.body = { cmd, text: text };
})
.addTo(agent);

View File

@@ -22,7 +22,7 @@ agent
{
role: 'user',
content: `
你是一个提示词优化的专家,请根据用户提供的提示词进行修正和优化,其中用户的提示词返回的要求如果没有或者不明确,请你修正为要求返回的文本在500字以内如果有则要求在500字内。同时要求内容是纯文本格式不能是markdown模式也不包含任何HTML标签或其他格式化内容。
你是一个提示词优化的专家请根据用户提供的提示词进行修正和优化其中用户的提示词返回的要求如果没有或者不明确请你修正为要求返回的文本在500字以内如果有保持原本的要求数字的文本。与此同时要求内容是纯文本格式不能是markdown模式也不包含任何HTML标签或其他格式化内容。
只对提示词进行优化,并且不需要对内容进行分析或总结。并返回修改后的总的提示词内容。
@@ -64,6 +64,6 @@ ${text}
if (!ans) {
logger.error('Empty response from AI:', res);
}
ctx.body = getTagContent(ans)
ctx.body = getTagContent(ans);
})
.addTo(agent);

View File

@@ -8,5 +8,6 @@ import './fix/prompt.ts';
import './xhs.ts';
import './tools/kuaren.ts';
import './tools/call-xiaoxiao.ts';
import './tools/summarize-note.ts';
export { agent };

View File

@@ -0,0 +1,53 @@
import { agent } from '../agent.ts';
import { ai } from '../ai.ts';
agent
.route({
path: 'tools',
key: 'summarize-note',
})
.define(async (ctx: any) => {
const text = ctx?.query?.text || '';
const note = ctx?.query?.note || '';
if (!text) {
ctx.throw('请提供要总结的笔记内容');
}
const prompt = `
请根据以下内容生成一段总结:
要求
0. 如果没有必要总结,直接返回 "当前内容不需要总结"。
1. 总结内容要简洁明了,突出重点。
2. 使用口语化的表达方式,易于理解。
3. 总结内容要有逻辑性,能够清晰地传达信息。
4. 如果有必要,可以使用一些比喻或形象的表达方式来增强总结的效果。
5. 总结内容要与原文内容相关,不能脱离主题。
6. 250字以内。
7. 不要包含除开总结内容以外的其他内容。
8. 其他要求:
${text ? text : '无'}
当前的笔记内容是:
${note}
`;
const res = await ai.chat(
[
{
role: 'user',
content: prompt,
},
],
{
// @ts-ignore
enable_thinking: false,
},
);
const pickRes = res.choices[0]?.message?.content || '';
if (!pickRes) {
ctx.throw('AI 没有返回任何内容,请稍后再试');
}
// 返回总结内容
ctx.body = pickRes.trim();
})
.addTo(agent);