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);

View File

@@ -1,3 +1,5 @@
import { useConfig } from '@kevisual/use-config/env';
export const config = useConfig();
export const isDev = config.ENV === 'development';

View File

@@ -116,7 +116,9 @@ taskApp
// 检测是这个用户的username的笔记如果是的话需要有at的用户信息才继续。
const isOwner = xhsServices.isOwner({ username: note_username, userid: note_userid });
const isReplayAi = xhsServices.isReplayAi(data);
const xsec_token = data.xsec_token;
console.log(data);
const comment_id = data.comment.comment_id;
let content: string = data.comment?.content || 'test';
const postData = {
@@ -132,12 +134,29 @@ taskApp
return;
}
}
content = content.replace('@' + note_username, '');
content = content.replace('@' + note_username, '');
const sliceContentCmd = content.slice(0, 20);
let note = '';
let hasNote = false;
if (sliceContentCmd.includes('笔记') || sliceContentCmd.includes('总结')) {
const res = await xhsApp.call({ path: 'note', key: 'getNote', payload: { node_id: note_id, xsec_token } });
if (res.code === 200) {
note = res.body?.desc || '';
hasNote = note ? true : false;
}
}
if (isReplayAi) {
// 如果是对AI回复的评论则不需要再回复
console.log('不需要AI回复AI的评论', note_username, note_id, content);
return;
}
const resAgent = await agent.call({
path: 'xhs',
payload: {
text: content,
note,
hasNote,
},
});
let responseText = '';

View File

@@ -7,7 +7,7 @@ import { app as xhsApp, xhsServices as xhs, xhsRootClient, XhsServices } from '@
import { nanoid } from 'nanoid';
export const XHS_GET_UNREAD = 'unread_count';
export const XHS_QUEUE_NAME = 'XHS_QUEUE';
import { config } from '../modules/config.ts';
import { config, isDev } from '../modules/config.ts';
const server: XhsServices = xhs;
server.setCookie(config.XHS_ROOT_COOKIE || '');
@@ -15,7 +15,13 @@ server.setUserInfo({
userid: config.XHS_USER_ID || '',
username: config.XHS_USER_NAME || '',
});
if (isDev) {
server.setSignConfig({
signUrl: 'http://localhost:5006/sign',
});
}
console.log('XHS_USER_INFO', config.XHS_USER_ID, config.XHS_USER_NAME, 'XHS_ROOT_COOKIE', config.XHS_ROOT_COOKIE);
console.log('XHS_SIGN_URL', server.getSignConfig().signUrl);
export const taskApp = new QueryRouterServer();
export { xhsApp };
export const xhsServices = server;