feat: add comfort user

This commit is contained in:
熊潇 2025-06-30 01:59:26 +08:00
parent 42da851c37
commit 143cbc877c
8 changed files with 96 additions and 99 deletions

View File

@ -1,3 +1,4 @@
import { useContextKey } from '@kevisual/context';
import { BailianProvider } from '@kevisual/ai'; import { BailianProvider } from '@kevisual/ai';
import { config } from '../modules/config.ts'; import { config } from '../modules/config.ts';
@ -13,16 +14,23 @@ import { config } from '../modules/config.ts';
// .catch((res) => { // .catch((res) => {
// console.error('Error fetching AI usage info:', res.status); // console.error('Error fetching AI usage info:', res.status);
// }); // });
const createBaiLian = () => {
return new BailianProvider({
baseURL: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
model: 'qwen3-235b-a22b',
apiKey: config.BAILIAN_API_KEY,
});
};
// export const ai = await useContextKey('ai', createBaiLian());
export const ai = createBaiLian();
export const ai = new BailianProvider({
baseURL: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
model: 'qwen3-235b-a22b',
apiKey: config.BAILIAN_API_KEY,
});
console.log('Bailian AI initialized with model:', config.BAILIAN_API_KEY); console.log('Bailian AI initialized with model:', config.BAILIAN_API_KEY);
export const bailianModel = { export const bailianModel = useContextKey('bailianModel', () => {
turbo: 'qwen-turbo-2025-04-28', return {
plus: 'qwen-plus-2025-04-28', turbo: 'qwen-turbo-2025-04-28',
a22b235: 'qwen3-235b-a22b', plus: 'qwen-plus-2025-04-28',
}; a22b235: 'qwen3-235b-a22b',
};
});

View File

@ -1,6 +1,7 @@
import { agent } from '@/agent/agent.ts'; import { agent } from '@/agent/agent.ts';
import { ai } from '../ai.ts'; import { ai } from '../ai.ts';
import { getJsonFromString } from './content.ts'; import { getJsonFromString } from './content.ts';
// import { getJsonFromString } from '@kevisual/ai/src/utils/json.ts';
import { logger } from '../logger.ts'; import { logger } from '../logger.ts';
export const cmdList: { export const cmdList: {
@ -35,6 +36,14 @@ export const cmdList: {
key: 'summarize-note', key: 'summarize-note',
}, },
}, },
{
category: '指令安慰',
description: `安慰用户`,
action: {
path: 'tools',
key: 'comfort-user',
},
},
]; ];
agent agent
@ -69,6 +78,8 @@ ${cmdList.map((item) => `- ${item.category}: ${item.description}`).join('\n')}
${text} ${text}
</context> </context>
`; `;
logger.info('Command analysis prompt:', prompt);
const res = await ai const res = await ai
.chat( .chat(
[ [
@ -89,9 +100,7 @@ ${text}
}); });
const ans = res.choices[0]?.message?.content || ''; const ans = res.choices[0]?.message?.content || '';
if (!ans) { console.log('Command analysis response:', ans);
logger.error('Empty response from AI:', res);
}
const json = getJsonFromString(ans); const json = getJsonFromString(ans);
if (!json) { if (!json) {
logger.error('Invalid JSON format in response:', ans); logger.error('Invalid JSON format in response:', ans);
@ -101,6 +110,7 @@ ${text}
category: json.category || 'default', category: json.category || 'default',
}; };
const cmd = cmdList.find((item) => item.category === result.category); const cmd = cmdList.find((item) => item.category === result.category);
logger.info('Command analysis result:', cmd?.category, cmd?.action);
ctx.body = { cmd, text: text }; ctx.body = { cmd, text: text };
}) })
.addTo(agent); .addTo(agent);

View File

@ -9,5 +9,6 @@ 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'; import './tools/summarize-note.ts';
import './tools/comfort-user.ts';
export { agent }; export { agent };

View File

@ -5,11 +5,12 @@ const main = async () => {
const text2 = '指令这个人很不错'; const text2 = '指令这个人很不错';
const text3 = '指令夸人, 这个人写代码写的非常好'; const text3 = '指令夸人, 这个人写代码写的非常好';
const text4 = '我想飞'; const text4 = '我想飞';
const text5 = '指令 笔记 安慰';
const res = await agent.call({ const res = await agent.call({
path: 'analyze', path: 'analyze',
key: 'cmd', key: 'cmd',
payload: { payload: {
text: text3 text: text5
}, },
}); });
console.log('analyze category res', res.code, 'content', res.body); console.log('analyze category res', res.code, 'content', res.body);

View File

@ -1,89 +1,7 @@
import { agent } from '../agent.ts'; import { agent } from '../agent.ts';
import { ai } from '../ai.ts'; import { ai } from '../ai.ts';
const kuarenPrompt = `### 浮夸夸人
****
vs
---
#### ** & **
1. **/**
- ****"你这张脸是上帝亲手雕的吧?下凡辛苦了!"
- ****
2. **/**
- ****"你这大脑是装了个量子计算机吗?!建议直接保送诺贝尔奖!"
- ****
3. **/**
- ****"你说话是撒了魔法金粉吗?听一句我灵魂都被净化了!"
- ****
4. **/**_重点_
- ****"你刚刚递咖啡的姿势,直接拍成广告能救活整个咖啡行业!"
- ****
---
#### ****
****
>
> 0.1
****
>
>
****
> XX XX
>
****_配合文字使用效果翻倍_
> .jpg 🍵
> .gif 🙇
---
#### ****
💥 ** 1**
> 线
💥 ** 2**
> 🌌
💥 ** 3**
> 🗿
####
`;
const pickGoodJobPrompt = `对提供的文字,提取单个的夸奖内容,并丰富为纯口语化模式,同时在括号中添加对应的姿态语言描述,同时添加了括号中的姿态语言描述,使其更具临场感和情感色彩。
1.
2.
3. 姿
4.
5.
6.
7.
const pickGoodJobPrompt = `
`; `;
agent agent

View File

@ -0,0 +1,53 @@
import { agent } from '../agent.ts';
import { ai } from '../ai.ts';
agent
.route({
path: 'tools',
key: 'comfort-user',
})
.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. 200
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,6 +1,7 @@
import { nanoid } from 'nanoid'; import { nanoid } from 'nanoid';
import { agent } from './agent.ts'; import { agent } from './agent.ts';
import { ai } from './ai.ts'; import { ai } from './ai.ts';
import { logger } from './logger.ts';
/** /**
* @信息 * @信息
* @param text * @param text
@ -64,6 +65,8 @@ agent
ctx.body = res.body || ''; ctx.body = res.body || '';
return; return;
} }
} else {
logger.error('指令分析错误:', analyzeRes.message);
} }
} }
const resFix = await agent.call({ const resFix = await agent.call({

View File

@ -6,6 +6,8 @@ import { queue, XHS_QUEUE_NAME, taskApp } from './index.ts';
import { addUnreadTask } from './task.ts'; import { addUnreadTask } from './task.ts';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { getTimeDuration } from './utils/time.ts'; import { getTimeDuration } from './utils/time.ts';
import { config, isDev } from '../modules/config.ts';
export const sleep = (ms: number) => { export const sleep = (ms: number) => {
return new Promise((resolve) => setTimeout(resolve, ms)); return new Promise((resolve) => setTimeout(resolve, ms));
}; };
@ -102,10 +104,11 @@ worker.on('completed', async (job) => {
// console.log('======has jobs, no need to add new job'); // console.log('======has jobs, no need to add new job');
} else { } else {
const up = timeRecorder.getClampDuration(true); const up = timeRecorder.getClampDuration(true);
const nextTime = up.nextTime + getTimeDuration(); const timeDuration = isDev ? 0 : getTimeDuration();
const nextTime = up.nextTime + timeDuration;
const unread = await queue.getJob('unread'); const unread = await queue.getJob('unread');
if (!unread) { if (!unread) {
console.log('====add unread next-time', nextTime, getTimeDuration()); console.log('====add unread next-time', nextTime, timeDuration);
addUnreadTask(nextTime); addUnreadTask(nextTime);
} }
} }