generated from tailored/router-template
temp
This commit is contained in:
parent
a25f7c7eb4
commit
b807cc9f38
91
src/agent/analyze/cmd.ts
Normal file
91
src/agent/analyze/cmd.ts
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
import { agent } from '@/agent/agent.ts';
|
||||||
|
import { ai } from '../ai.ts';
|
||||||
|
import { getJsonFromString } from './content.ts';
|
||||||
|
import { logger } from '../logger.ts';
|
||||||
|
|
||||||
|
export const cmdList: {
|
||||||
|
category: string;
|
||||||
|
description?: string;
|
||||||
|
callPath?: {
|
||||||
|
path?: string;
|
||||||
|
key?: string;
|
||||||
|
};
|
||||||
|
}[] = [
|
||||||
|
{
|
||||||
|
category: '指令夸人',
|
||||||
|
description: `进行夸奖`,
|
||||||
|
callPath: {
|
||||||
|
path: 'tools',
|
||||||
|
key: 'good-job',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
agent
|
||||||
|
.route({
|
||||||
|
path: 'analyze',
|
||||||
|
key: 'cmd',
|
||||||
|
description: '分析文本内容,意图分析,判断对应的指令内容',
|
||||||
|
})
|
||||||
|
.define(async (ctx) => {
|
||||||
|
const text = ctx.query?.text || '';
|
||||||
|
|
||||||
|
let result = {
|
||||||
|
category: 'default',
|
||||||
|
};
|
||||||
|
|
||||||
|
const prompt = `
|
||||||
|
请分析<context>包函的内容,判断是否程序运行指令,返回一个JSON对象。
|
||||||
|
识别的分类包括:
|
||||||
|
${cmdList.map((item) => `- ${item.category}: ${item.description}`).join('\n')}
|
||||||
|
|
||||||
|
返回内容示例:
|
||||||
|
\`\`\`json
|
||||||
|
{
|
||||||
|
"category": "daily_poetry"
|
||||||
|
}
|
||||||
|
\`\`\`
|
||||||
|
|
||||||
|
分析的内容是
|
||||||
|
<context>
|
||||||
|
${text}
|
||||||
|
</context>
|
||||||
|
`;
|
||||||
|
const now = Date.now();
|
||||||
|
console.log('start');
|
||||||
|
const res = await ai
|
||||||
|
.chat(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
role: 'user',
|
||||||
|
content: prompt,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
{
|
||||||
|
// @ts-ignore
|
||||||
|
enable_thinking: false,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.catch((err) => {
|
||||||
|
console.log('AI service error:', err.status);
|
||||||
|
ctx.throw(500, 'AI service error: ' + err.status);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
const json = getJsonFromString(ans);
|
||||||
|
if (!json) {
|
||||||
|
logger.error('Invalid JSON format in response:', ans);
|
||||||
|
ctx.throw(400, 'Invalid JSON format in response');
|
||||||
|
}
|
||||||
|
result = {
|
||||||
|
category: json.category || 'default',
|
||||||
|
};
|
||||||
|
const cmd = cmdList.find((item) => item.category === result.category);
|
||||||
|
ctx.body = { cmd, text: text };
|
||||||
|
})
|
||||||
|
.addTo(agent);
|
@ -49,7 +49,7 @@ agent
|
|||||||
}
|
}
|
||||||
\`\`\`
|
\`\`\`
|
||||||
分析的文本的内容是:
|
分析的文本的内容是:
|
||||||
<context>
|
<context>
|
||||||
${text}
|
${text}
|
||||||
</context>
|
</context>
|
||||||
`;
|
`;
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
import { agent } from './agent.ts';
|
import { agent } from './agent.ts';
|
||||||
import './analyze/content.ts';
|
import './analyze/content.ts';
|
||||||
import './analyze/category.ts';
|
import './analyze/category.ts';
|
||||||
|
import './analyze/cmd.ts';
|
||||||
|
|
||||||
import './fix/prompt.ts';
|
import './fix/prompt.ts';
|
||||||
|
|
||||||
import './xhs.ts';
|
import './xhs.ts';
|
||||||
|
import './tools/kuaren.ts';
|
||||||
|
|
||||||
export { agent };
|
export { agent };
|
||||||
|
17
src/agent/test/cmd.ts
Normal file
17
src/agent/test/cmd.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { agent } from '../index.ts';
|
||||||
|
|
||||||
|
const main = async () => {
|
||||||
|
const text1 = '夸一下这个人。';
|
||||||
|
const text2 = '指令这个人很不错';
|
||||||
|
const text3 = '指令夸人, 这个人写代码写的非常好';
|
||||||
|
const text4 = '我想飞';
|
||||||
|
const res = await agent.call({
|
||||||
|
path: 'analyze',
|
||||||
|
key: 'cmd',
|
||||||
|
payload: {
|
||||||
|
text: text4
|
||||||
|
},
|
||||||
|
});
|
||||||
|
console.log('analyze category res', res.code, 'content', res.body);
|
||||||
|
};
|
||||||
|
main();
|
109
src/agent/tools/kuaren.ts
Normal file
109
src/agent/tools/kuaren.ts
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
import { agent } from '../agent.ts';
|
||||||
|
import { ai } from '../ai.ts';
|
||||||
|
const kuarenPrompt = `### 浮夸夸人
|
||||||
|
|
||||||
|
**核心要求**:
|
||||||
|
⚠️ 用词极致夸张| ⚠️ 比喻突破天际| ⚠️ 语气充满崇拜| ⚠️ 营造“凡人 vs 神仙”对比感
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### **夸人维度 & 浮夸话术示例**
|
||||||
|
|
||||||
|
1. **颜值/气质类**
|
||||||
|
|
||||||
|
- ✨ **例句**:"你这张脸是上帝亲手雕的吧?下凡辛苦了!"
|
||||||
|
- ✨ **关键词**:女娲毕设、建模脸、自带滤镜、呼吸都带仙气
|
||||||
|
|
||||||
|
2. **才华/能力类**
|
||||||
|
|
||||||
|
- ✨ **例句**:"你这大脑是装了个量子计算机吗?!建议直接保送诺贝尔奖!"
|
||||||
|
- ✨ **关键词**:人类天花板、降维打击、天才操作、教科书成精
|
||||||
|
|
||||||
|
3. **性格/情商类**
|
||||||
|
|
||||||
|
- ✨ **例句**:"你说话是撒了魔法金粉吗?听一句我灵魂都被净化了!"
|
||||||
|
- ✨ **关键词**:人间充电宝、社交天花板、灵魂按摩师、情商天花板
|
||||||
|
|
||||||
|
4. **细节/小事类**(_重点:把小事吹成神迹_)
|
||||||
|
- ✨ **例句**:"你刚刚递咖啡的姿势,直接拍成广告能救活整个咖啡行业!"
|
||||||
|
- ✨ **关键词**:随手拯救世界、文艺复兴级操作、人类文明之光
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### **浮夸技巧工具箱**
|
||||||
|
|
||||||
|
✅ **宇宙级比喻**:
|
||||||
|
|
||||||
|
> “你这创意是偷了宙斯的闪电吧?!”
|
||||||
|
> “你的存在让地球自转加速了 0.1 秒!”
|
||||||
|
|
||||||
|
✅ **玄幻修辞法**:
|
||||||
|
|
||||||
|
> “建议科学家把你列入未解之谜!”
|
||||||
|
> “你一笑,北极极光都暗淡了!”
|
||||||
|
|
||||||
|
✅ **凡尔赛对比**:
|
||||||
|
|
||||||
|
> “别人 XX 叫努力,你 XX 叫刷新人类极限!”
|
||||||
|
> “你这水平还谦虚?让普通人怎么活啊?!”
|
||||||
|
|
||||||
|
✅ **动作加持**(_配合文字使用效果翻倍_):
|
||||||
|
|
||||||
|
> “给大佬递茶.jpg 🍵”
|
||||||
|
> “跪着听讲.gif 🙇♂️”
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### **示例输出**
|
||||||
|
|
||||||
|
💥 **场景 1**(对方随手画了张小涂鸦)
|
||||||
|
|
||||||
|
> “这线条!这配色!达芬奇转世没你画得灵!!建议卢浮宫连夜来收购!!”
|
||||||
|
|
||||||
|
💥 **场景 2**(对方讲了个冷笑话)
|
||||||
|
|
||||||
|
> “你这幽默感是黑洞做的吗?!我笑到平行宇宙都裂开了!!🌌”
|
||||||
|
|
||||||
|
💥 **场景 3**(对方帮忙解决了小问题)
|
||||||
|
|
||||||
|
> “你是雅典娜派来的救世主吧?!这波操作够我刻成碑传家!!🗿”
|
||||||
|
|
||||||
|
#### 当前的场景是
|
||||||
|
`;
|
||||||
|
|
||||||
|
agent
|
||||||
|
.route({
|
||||||
|
path: 'tools',
|
||||||
|
key: 'good-job',
|
||||||
|
})
|
||||||
|
.define(async (ctx) => {
|
||||||
|
let { text } = ctx.query;
|
||||||
|
if (!text) {
|
||||||
|
text = '作者发了一篇好的文章';
|
||||||
|
}
|
||||||
|
const prompt = `${kuarenPrompt} ${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;
|
||||||
|
console.log('AI response:', ans);
|
||||||
|
})
|
||||||
|
.addTo(agent);
|
@ -9,6 +9,34 @@ const clearAtInfo = (text: string = '') => {
|
|||||||
const newText = text.replace(/@[\u4e00-\u9fa5\w]+/g, '').replace(/#.*?#/g, '');
|
const newText = text.replace(/@[\u4e00-\u9fa5\w]+/g, '').replace(/#.*?#/g, '');
|
||||||
return newText.trim();
|
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
|
agent
|
||||||
.route({
|
.route({
|
||||||
path: 'xhs',
|
path: 'xhs',
|
||||||
@ -17,6 +45,21 @@ agent
|
|||||||
const { text = '' } = ctx.query || {};
|
const { text = '' } = ctx.query || {};
|
||||||
const id = nanoid();
|
const id = nanoid();
|
||||||
const no_at_text = clearAtInfo(text);
|
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 || '';
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
const resFix = await agent.call({
|
const resFix = await agent.call({
|
||||||
path: 'fix',
|
path: 'fix',
|
||||||
key: 'xhs',
|
key: 'xhs',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user