generated from tailored/router-template
feat: add summary
This commit is contained in:
parent
204165bf73
commit
e2d0720698
@ -38,6 +38,7 @@ export const getSign = async (signInfo: SignInfo, options?: SignOptions): Promis
|
|||||||
// signUrl = 'http://localhost:5005/sign';
|
// signUrl = 'http://localhost:5005/sign';
|
||||||
// const urlA1 = ''http://light.xiongxiao.me:5006/a1';
|
// const urlA1 = ''http://light.xiongxiao.me:5006/a1';
|
||||||
// const urlA1 = 'http://localhost:5005/a1';
|
// const urlA1 = 'http://localhost:5005/a1';
|
||||||
|
// console.log('sign', signUrl);
|
||||||
const signs = await fetch(signUrl, {
|
const signs = await fetch(signUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@ -215,6 +216,7 @@ export class XhsClient extends XhsClientBase {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await this.post(uri, data, { sign: this.sign.bind(this) });
|
const response = await this.post(uri, data, { sign: this.sign.bind(this) });
|
||||||
|
console.log('getNoteById response', response, typeof response);
|
||||||
// return response['items'][0]['node_card'];
|
// return response['items'][0]['node_card'];
|
||||||
return response;
|
return response;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -1 +1,2 @@
|
|||||||
import './mentions/index.ts'
|
import './mentions/index.ts'
|
||||||
|
import './notes/index.ts'
|
@ -7,8 +7,8 @@ app
|
|||||||
})
|
})
|
||||||
.define(async (ctx) => {
|
.define(async (ctx) => {
|
||||||
const client = xhsServices.getClient();
|
const client = xhsServices.getClient();
|
||||||
const res = await client.c
|
// const res = await client.getNote({});
|
||||||
if (res.code === 0) {
|
// if (res.code === 0) {
|
||||||
}
|
// }
|
||||||
})
|
})
|
||||||
.addTo(app);
|
.addTo(app);
|
||||||
|
18
packages/xhs/src/routes/notes/get-note.ts
Normal file
18
packages/xhs/src/routes/notes/get-note.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { app, xhsServices } from '@kevisual/xhs/app.ts';
|
||||||
|
app
|
||||||
|
.route({
|
||||||
|
path: 'note',
|
||||||
|
key: 'getNote',
|
||||||
|
description: '获取笔记详情',
|
||||||
|
})
|
||||||
|
.define(async (ctx) => {
|
||||||
|
const { node_id, xsec_token } = ctx.query;
|
||||||
|
const client = xhsServices.getClient();
|
||||||
|
const res = await client.getNote(node_id, xsec_token);
|
||||||
|
if (res.code === 200) {
|
||||||
|
ctx.body = res.data || {};
|
||||||
|
} else {
|
||||||
|
ctx.throw(`获取笔记失败: ${node_id}`);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.addTo(app);
|
@ -1 +1,2 @@
|
|||||||
import './create-note.ts'
|
import './create-note.ts'
|
||||||
|
import './get-note.ts'
|
@ -104,6 +104,16 @@ export class XhsServices {
|
|||||||
}
|
}
|
||||||
return user.userid === xhsUserInfo.userid;
|
return user.userid === xhsUserInfo.userid;
|
||||||
}
|
}
|
||||||
|
isReplayAi(data: any, key?: string) {
|
||||||
|
const mention = data?.mention || {};
|
||||||
|
const user_info = mention?.comment_info?.target_comment?.user_info || {};
|
||||||
|
if (user_info?.userid) {
|
||||||
|
const xhsUserInfo = this.getXhsUserInfo(key);
|
||||||
|
// 处理用户信息
|
||||||
|
return user_info.userid === xhsUserInfo.userid;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
setCookie(cookie: string, key?: string) {
|
setCookie(cookie: string, key?: string) {
|
||||||
const xhsClient = this.map.get(this.getKey(key));
|
const xhsClient = this.map.get(this.getKey(key));
|
||||||
if (xhsClient) {
|
if (xhsClient) {
|
||||||
@ -123,4 +133,17 @@ export class XhsServices {
|
|||||||
xhsClient.options.username = user.username;
|
xhsClient.options.username = user.username;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setSignConfig(signConfig: { signUrl: string }, key?: string) {
|
||||||
|
const xhsClient = this.map.get(this.getKey(key));
|
||||||
|
if (xhsClient) {
|
||||||
|
xhsClient.options.signConfig = signConfig;
|
||||||
|
xhsClient.client.signConfig = signConfig;
|
||||||
|
}
|
||||||
|
console.log('setSignConfig', xhsClient?.options?.signConfig);
|
||||||
|
}
|
||||||
|
getSignConfig(key?: string) {
|
||||||
|
const xhsClient = this.map.get(this.getKey(key));
|
||||||
|
return xhsClient?.options?.signConfig || {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,17 +8,27 @@ import util from 'node:util';
|
|||||||
// });
|
// });
|
||||||
const getNoteById = async () => {
|
const getNoteById = async () => {
|
||||||
const client = xhsServices.getClient();
|
const client = xhsServices.getClient();
|
||||||
client.getNoteById('68136dab0000000007034c46', 'LByEmonX8WfJ9ebpAowVbOZX9Xh8T0Qkjil5KRFqDD6LM').then((res) => {
|
// client.getNoteById('68136dab0000000007034c46', 'LByEmonX8WfJ9ebpAowVbOZX9Xh8T0Qkjil5KRFqDD6LM').then((res) => {
|
||||||
console.log(res);
|
// console.log(res);
|
||||||
});
|
// });
|
||||||
|
|
||||||
|
const res = await client.getNoteById('68136dab0000000007034c46', 'LB6fmNfsd0keAQNjh3zOejDC2TVQLGY3zlTZjeRazBZdI=');
|
||||||
|
// console.log(res);
|
||||||
};
|
};
|
||||||
const getNote = async () => {
|
const getNote = async () => {
|
||||||
|
// const id = '68136dab0000000007034c46';
|
||||||
|
// const x = 'LByEmonX8WfJ9ebpAowVbOZX9Xh8T0Qkjil5KRFqDD6LM=';
|
||||||
const id = '68136dab0000000007034c46';
|
const id = '68136dab0000000007034c46';
|
||||||
const x = 'LByEmonX8WfJ9ebpAowVbOZX9Xh8T0Qkjil5KRFqDD6LM=';
|
const x = 'LB6fmNfsd0keAQNjh3zOejDC2TVQLGY3zlTZjeRazBZdI=';
|
||||||
const client = xhsServices.getClient();
|
const client = xhsServices.getClient();
|
||||||
client.getNote(id, x).then((res) => {
|
const res = await client.getNote(id, x).then((res) => {
|
||||||
console.log(util.inspect(res, { depth: null }));
|
console.log(util.inspect(res, { depth: null }));
|
||||||
|
return res;
|
||||||
});
|
});
|
||||||
|
console.log('type res', typeof res);
|
||||||
|
if (res.code === 0) {
|
||||||
|
console.log('desc', res.data.desc);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
program
|
program
|
||||||
.command('get-note')
|
.command('get-note')
|
||||||
|
@ -27,6 +27,14 @@ export const cmdList: {
|
|||||||
key: 'call-xiaoxiao',
|
key: 'call-xiaoxiao',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
category: '指令总结',
|
||||||
|
description: `总结当前的笔记,缩写当前笔记的内容`,
|
||||||
|
action: {
|
||||||
|
path: 'tools',
|
||||||
|
key: 'summarize-note',
|
||||||
|
},
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
agent
|
agent
|
||||||
@ -96,4 +104,3 @@ ${text}
|
|||||||
ctx.body = { cmd, text: text };
|
ctx.body = { cmd, text: text };
|
||||||
})
|
})
|
||||||
.addTo(agent);
|
.addTo(agent);
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ agent
|
|||||||
{
|
{
|
||||||
role: 'user',
|
role: 'user',
|
||||||
content: `
|
content: `
|
||||||
你是一个提示词优化的专家,请根据用户提供的提示词进行修正和优化,其中用户的提示词返回的要求如果没有或者不明确,请你都修正为要求返回的文本在500字以内,如果有,则要求在500字内。同时要求内容是纯文本格式,不能是markdown模式,也不包含任何HTML标签或其他格式化内容。
|
你是一个提示词优化的专家,请根据用户提供的提示词进行修正和优化,其中用户的提示词返回的要求如果没有或者不明确,请你修正为要求返回的文本在500字以内,如果有,保持原本的要求数字的文本。与此同时,要求内容是纯文本格式,不能是markdown模式,也不包含任何HTML标签或其他格式化内容。
|
||||||
|
|
||||||
只对提示词进行优化,并且不需要对内容进行分析或总结。并返回修改后的总的提示词内容。
|
只对提示词进行优化,并且不需要对内容进行分析或总结。并返回修改后的总的提示词内容。
|
||||||
|
|
||||||
@ -64,6 +64,6 @@ ${text}
|
|||||||
if (!ans) {
|
if (!ans) {
|
||||||
logger.error('Empty response from AI:', res);
|
logger.error('Empty response from AI:', res);
|
||||||
}
|
}
|
||||||
ctx.body = getTagContent(ans)
|
ctx.body = getTagContent(ans);
|
||||||
})
|
})
|
||||||
.addTo(agent);
|
.addTo(agent);
|
||||||
|
@ -8,5 +8,6 @@ import './fix/prompt.ts';
|
|||||||
import './xhs.ts';
|
import './xhs.ts';
|
||||||
import './tools/kuaren.ts';
|
import './tools/kuaren.ts';
|
||||||
import './tools/call-xiaoxiao.ts';
|
import './tools/call-xiaoxiao.ts';
|
||||||
|
import './tools/summarize-note.ts';
|
||||||
|
|
||||||
export { agent };
|
export { agent };
|
||||||
|
53
src/agent/tools/summarize-note.ts
Normal file
53
src/agent/tools/summarize-note.ts
Normal 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);
|
@ -1,3 +1,5 @@
|
|||||||
import { useConfig } from '@kevisual/use-config/env';
|
import { useConfig } from '@kevisual/use-config/env';
|
||||||
|
|
||||||
export const config = useConfig();
|
export const config = useConfig();
|
||||||
|
|
||||||
|
export const isDev = config.ENV === 'development';
|
||||||
|
@ -116,7 +116,9 @@ taskApp
|
|||||||
|
|
||||||
// 检测是这个用户的username的笔记,如果是的话,需要有at的用户信息才继续。
|
// 检测是这个用户的username的笔记,如果是的话,需要有at的用户信息才继续。
|
||||||
const isOwner = xhsServices.isOwner({ username: note_username, userid: note_userid });
|
const isOwner = xhsServices.isOwner({ username: note_username, userid: note_userid });
|
||||||
|
const isReplayAi = xhsServices.isReplayAi(data);
|
||||||
const xsec_token = data.xsec_token;
|
const xsec_token = data.xsec_token;
|
||||||
|
console.log(data);
|
||||||
const comment_id = data.comment.comment_id;
|
const comment_id = data.comment.comment_id;
|
||||||
let content: string = data.comment?.content || 'test';
|
let content: string = data.comment?.content || 'test';
|
||||||
const postData = {
|
const postData = {
|
||||||
@ -132,12 +134,29 @@ taskApp
|
|||||||
return;
|
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({
|
const resAgent = await agent.call({
|
||||||
path: 'xhs',
|
path: 'xhs',
|
||||||
payload: {
|
payload: {
|
||||||
text: content,
|
text: content,
|
||||||
|
note,
|
||||||
|
hasNote,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
let responseText = '';
|
let responseText = '';
|
||||||
|
@ -7,7 +7,7 @@ import { app as xhsApp, xhsServices as xhs, xhsRootClient, XhsServices } from '@
|
|||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
export const XHS_GET_UNREAD = 'unread_count';
|
export const XHS_GET_UNREAD = 'unread_count';
|
||||||
export const XHS_QUEUE_NAME = 'XHS_QUEUE';
|
export const XHS_QUEUE_NAME = 'XHS_QUEUE';
|
||||||
import { config } from '../modules/config.ts';
|
import { config, isDev } from '../modules/config.ts';
|
||||||
|
|
||||||
const server: XhsServices = xhs;
|
const server: XhsServices = xhs;
|
||||||
server.setCookie(config.XHS_ROOT_COOKIE || '');
|
server.setCookie(config.XHS_ROOT_COOKIE || '');
|
||||||
@ -15,7 +15,13 @@ server.setUserInfo({
|
|||||||
userid: config.XHS_USER_ID || '',
|
userid: config.XHS_USER_ID || '',
|
||||||
username: config.XHS_USER_NAME || '',
|
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_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 const taskApp = new QueryRouterServer();
|
||||||
export { xhsApp };
|
export { xhsApp };
|
||||||
export const xhsServices = server;
|
export const xhsServices = server;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user