feat: 添加夸一下的内容

This commit is contained in:
熊潇 2025-06-25 11:35:16 +08:00
parent b807cc9f38
commit bce94f52a0
8 changed files with 124 additions and 53 deletions

View File

@ -6,7 +6,7 @@ import { logger } from '../logger.ts';
export const cmdList: {
category: string;
description?: string;
callPath?: {
action?: {
path?: string;
key?: string;
};
@ -14,7 +14,7 @@ export const cmdList: {
{
category: '指令夸人',
description: `进行夸奖`,
callPath: {
action: {
path: 'tools',
key: 'good-job',
},
@ -28,8 +28,10 @@ agent
description: '分析文本内容,意图分析,判断对应的指令内容',
})
.define(async (ctx) => {
const text = ctx.query?.text || '';
let text = ctx.query?.text || '';
if (text.length > 40) {
text = text.slice(0, 40).trim();
}
let result = {
category: 'default',
};
@ -51,8 +53,6 @@ ${cmdList.map((item) => `- ${item.category}: ${item.description}`).join('\n')}
${text}
</context>
`;
const now = Date.now();
console.log('start');
const res = await ai
.chat(
[
@ -72,7 +72,6 @@ ${text}
return err;
});
console.log('end', Date.now() - now, 'ms');
const ans = res.choices[0]?.message?.content || '';
if (!ans) {
logger.error('Empty response from AI:', res);

View File

@ -22,7 +22,7 @@ agent
{
role: 'user',
content: `
500markdown模式HTML标签或其他格式化内容
500500markdown模式HTML标签或其他格式化内容
@ -34,6 +34,10 @@ agent
<content></content>
<content>500</content>
3.
<content>300</content>
<content>300</content>

View File

@ -9,7 +9,7 @@ const main = async () => {
path: 'analyze',
key: 'cmd',
payload: {
text: text4
text: text3
},
});
console.log('analyze category res', res.code, 'content', res.body);

View File

@ -6,11 +6,12 @@ const main = async () => {
const text2 = '告诉我1+1的值';
const text3 = 'html和css的大纲是什么';
const text4 = '1+1=';
const text5 = '请分析一下这个图片300字内';
const res = await agent.call({
path: 'fix',
key: 'xhs',
payload: {
text: text,
text: text5,
},
});
console.log('fix xhs res', res.code, 'content', res.body);

View File

@ -0,0 +1,16 @@
import { agent } from '../../index.ts';
const main = async () => {
const text1 = '你长得真好看啊';
const text2 = '你说话是撒了魔法金粉吗?听一句我灵魂都被净化了!';
const res = await agent.call({
path: 'tools',
key: 'good-job',
payload: {
text: text2,
},
});
console.log('good job res', res.code, 'content', res.body);
};
main();

View File

@ -71,6 +71,58 @@ const kuarenPrompt = `### 浮夸夸人
####
`;
const pickGoodJobPrompt = `对提供的文字,提取单个的夸奖内容,并丰富为纯口语化模式,同时在括号中添加对应的姿态语言描述,同时添加了括号中的姿态语言描述,使其更具临场感和情感色彩。
1.
2.
3. 姿
4.
5.
6.
7.
`;
agent
.route({
path: 'tools',
key: 'pick-good-job',
description: '对用户的内容进行夸奖后,提取出夸奖的内容',
})
.define(async (ctx) => {
let { text } = ctx.query;
if (!text) {
text = '真厉害啊';
}
const prompt = `${pickGoodJobPrompt} ${text}`;
const res = await ai
.chat(
[
{
role: 'user',
content: prompt,
},
],
{
enable_thinking: false,
},
)
.catch((err) => {
console.error('AI service error:', err.status);
ctx.throw(500, 'AI service error: ' + err.status);
return err;
});
const ans = res.choices[0]?.message?.content || '';
if (!ans) {
ctx.throw(500, 'AI response is empty');
}
ctx.body = ans;
})
.addTo(agent);
agent
.route({
path: 'tools',
@ -103,7 +155,23 @@ agent
if (!ans) {
ctx.throw(500, 'AI response is empty');
}
ctx.body = ans;
console.log('AI response:', ans);
// ctx.body = ans;
// console.log('AI response:', ans);
const resPick = await agent.call({
path: 'tools',
key: 'pick-good-job',
payload: {
text: ans,
},
});
if (resPick.code !== 200) {
ctx.throw(500, 'AI pick good job error: ' + resPick.message);
return;
}
const pickAns = resPick.body || '';
if (!pickAns) {
ctx.throw(500, 'AI pick good job response is empty');
}
ctx.body = pickAns;
})
.addTo(agent);

View File

@ -1,6 +1,7 @@
import { nanoid } from 'nanoid';
import { agent } from './agent.ts';
import { ai } from './ai.ts';
import { cmdList } from './analyze/cmd.ts';
/**
* @信息
* @param text
@ -10,33 +11,6 @@ const clearAtInfo = (text: string = '') => {
return newText.trim();
};
const cmdList: {
cmd: string;
description?: string;
callPath?: {
path?: string;
key?: string;
};
}[] = [
{
cmd: '指令夸人',
description: `进行夸奖`,
callPath: {
path: 'tools',
key: 'good-job',
},
},
];
const getTextCmd = (text: string, cmdList = []) => {
const text20 = text.length > 20 ? text.slice(0, 20) : text;
const cmd = cmdList.find((item) => text20.includes(item.cmd));
if (cmd) {
return cmd;
}
return {
cmd: undefined,
};
};
agent
.route({
path: 'xhs',
@ -45,20 +19,29 @@ agent
const { text = '' } = ctx.query || {};
const id = nanoid();
const no_at_text = clearAtInfo(text);
const cmd = getTextCmd(no_at_text, cmdList);
if (cmd.cmd) {
const newText = no_at_text.replace(cmd.cmd, '').trim();
if (cmd.callPath) {
const res = await agent.call({
path: cmd.callPath.path,
key: cmd.callPath.key,
payload: {
text: newText,
},
});
ctx.body = res.body || '';
const some_text = no_at_text.length > 20 ? no_at_text.slice(0, 20) : no_at_text;
const hasCmd = some_text.includes('指令');
if (hasCmd) {
const analyzeRes = await agent.call({
path: 'analyze',
key: 'cmd',
payload: {
text: no_at_text,
},
});
if (analyzeRes.code === 200) {
const cmd = analyzeRes.body?.cmd;
if (cmd) {
const res = await agent.call({
...cmd.action,
payload: {
text: no_at_text,
},
});
ctx.body = res.body || '';
return;
}
}
return;
}
const resFix = await agent.call({
path: 'fix',

View File

@ -96,7 +96,7 @@ export const worker = new Worker(
worker.on('completed', async (job) => {
const jobCounts = await queue.getJobCounts('waiting', 'wait', 'delayed');
if (job.name !== 'unread') {
console.log('job completed', job.name, job.id, job.returnvalue, jobCounts.delayed, jobCounts.wait);
console.log('job completed', job.name, 'run id', job.id, job.returnvalue, jobCounts.delayed, jobCounts.wait);
}
if (jobCounts.delayed + jobCounts.wait > 0) {
// console.log('======has jobs, no need to add new job');