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);