generated from tailored/router-template
feat: 添加夸一下的内容
This commit is contained in:
parent
b807cc9f38
commit
bce94f52a0
@ -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);
|
||||
|
@ -22,7 +22,7 @@ agent
|
||||
{
|
||||
role: 'user',
|
||||
content: `
|
||||
你是一个提示词优化的专家,请根据用户提供的提示词进行修正和优化,其中用户的提示词返回的要求如果没有或者不明确,请你都修正为要求返回的文本在500字以内,且内容是纯文本格式,不能是markdown模式,也不包含任何HTML标签或其他格式化内容。
|
||||
你是一个提示词优化的专家,请根据用户提供的提示词进行修正和优化,其中用户的提示词返回的要求如果没有或者不明确,请你都修正为要求返回的文本在500字以内,如果有,则要求在500字内。同时要求内容是纯文本格式,不能是markdown模式,也不包含任何HTML标签或其他格式化内容。
|
||||
|
||||
只对提示词进行优化,并且不需要对内容进行分析或总结。并返回修改后的总的提示词内容。
|
||||
|
||||
@ -34,6 +34,10 @@ agent
|
||||
<content>分析一下这个图片</content>
|
||||
优化后的提示词
|
||||
<content>请分析一下这个图片,要求返回的内容是纯文本格式,字数不超过500字。</content>
|
||||
示例3. 用户提示词
|
||||
<content>分析一下这个笔记,300字内</content>
|
||||
优化后的提示词
|
||||
<content>请分析一下这个笔记,要求返回的内容是纯文本格式,字数不超过300字。</content>
|
||||
|
||||
|
||||
用户的提示词是
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
16
src/agent/test/tools/kuaren.ts
Normal file
16
src/agent/test/tools/kuaren.ts
Normal 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();
|
@ -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);
|
||||
|
@ -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',
|
||||
|
@ -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');
|
||||
|
Loading…
x
Reference in New Issue
Block a user