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