init
This commit is contained in:
33
test/common.ts
Normal file
33
test/common.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { App } from '../src/app.ts';
|
||||
import { useConfig } from '@kevisual/use-config';
|
||||
|
||||
export const config = useConfig();
|
||||
export const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
||||
const time = Date.now();
|
||||
const app = new App({ token: config.KEVISUAL_TOKEN || '' });
|
||||
|
||||
|
||||
console.log('time to init app', Date.now() - time);
|
||||
|
||||
await app.loadAI();
|
||||
console.log('app ai inited', Date.now() - time);
|
||||
const router = app.router;
|
||||
router.route({
|
||||
description: '获取天气,返回天气情况',
|
||||
}).define(async ctx => {
|
||||
ctx.body = '今天天气晴朗,气温25度,适合出行。';
|
||||
}).addTo(router)
|
||||
|
||||
router.route({
|
||||
description: '获取新闻,返回最新新闻',
|
||||
}).define(async (ctx) => {
|
||||
ctx.body = '今天的头条新闻是:科技公司发布了最新的智能手机。';
|
||||
}).addTo(router)
|
||||
|
||||
// await sleep(1000);
|
||||
|
||||
const run = await app.chat('今天的新闻');
|
||||
console.log('run', run);
|
||||
|
||||
console.log('all done', Date.now() - time);
|
||||
Reference in New Issue
Block a user