feat: implement AI agent for flowme-life interactions
- Add agent-run module to handle AI interactions with tools and messages. - Create routes for proxying requests to OpenAI and Anthropic APIs. - Implement flowme-life chat route for user queries and task management. - Add services for retrieving and updating life records in the database. - Implement logic for fetching today's tasks and marking tasks as done with next execution time calculation. - Introduce tests for flowme-life functionalities.
This commit is contained in:
44
src/routes/flowme-life/chat.ts
Normal file
44
src/routes/flowme-life/chat.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
import { schema, app, cnb, models } from '@/app.ts'
|
||||
import z from 'zod';
|
||||
import { runAgent } from '@kevisual/ai/agent'
|
||||
|
||||
app.route({
|
||||
path: 'flowme-life',
|
||||
key: 'chat',
|
||||
description: `聊天接口, 对自己的数据进行操作,参数是 question或messages,question是用户的提问,messages是对话消息列表,优先级高于 question`,
|
||||
middleware: ['auth']
|
||||
, metadata: {
|
||||
args: {
|
||||
question: z.string().describe('用户的提问'),
|
||||
messages: z.any().optional().describe('对话消息列表,优先级高于 question'),
|
||||
}
|
||||
}
|
||||
}).define(async (ctx) => {
|
||||
const question = ctx.query.question || '';
|
||||
const _messages = ctx.query.messages;
|
||||
const token = ctx.query.token || '';
|
||||
if (!question && !_messages) {
|
||||
ctx.throw(400, '缺少参数 question 或 messages');
|
||||
}
|
||||
const routes = ctx.app.getList().filter(r => r.path.startsWith('flowme-life') && r.key !== 'chat');
|
||||
const messages = _messages || [
|
||||
{
|
||||
"role": "system" as const,
|
||||
"content": `你是我的智能助手,协助我操作我的数据, 请根据我的提问选择合适的接口进行调用。`
|
||||
},
|
||||
{
|
||||
"role": "user" as const,
|
||||
"content": question
|
||||
}
|
||||
]
|
||||
const res = await runAgent({
|
||||
app: app,
|
||||
messages: messages,
|
||||
languageModel: cnb(models['auto']),
|
||||
// query: 'WHERE path LIKE 'flowme-life%',
|
||||
routes,
|
||||
token,
|
||||
});
|
||||
ctx.body = res
|
||||
}).addTo(app);
|
||||
Reference in New Issue
Block a user