From c3591394ca8c9dbef08f7643e529a22a37a26cb2 Mon Sep 17 00:00:00 2001 From: snowgitea Date: Wed, 1 Jul 2026 17:56:26 +0800 Subject: [PATCH] chore: src/modules/demo/controller/open/plugin.ts --- src/modules/demo/controller/open/plugin.ts | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/modules/demo/controller/open/plugin.ts diff --git a/src/modules/demo/controller/open/plugin.ts b/src/modules/demo/controller/open/plugin.ts new file mode 100644 index 0000000..c2d3310 --- /dev/null +++ b/src/modules/demo/controller/open/plugin.ts @@ -0,0 +1,29 @@ +import { CoolController, BaseController } from '@cool-midway/core'; +import { PluginService } from '../../../plugin/service/info'; +import { Get, Inject } from '@midwayjs/core'; + +/** + * 插件 + */ +@CoolController() +export class OpenDemoPluginController extends BaseController { + @Inject() + pluginService: PluginService; + + @Get('/invoke', { summary: '调用插件' }) + async invoke() { + // 获取插件实例 + const instance: any = await this.pluginService.getInstance('ollama'); + // 调用chat + const messages = [ + { role: 'system', content: '你叫小酷,是一个智能助理' }, + { role: 'user', content: '写一个1000字的关于春天的文章' }, + ]; + for (let i = 0; i < 3; i++) { + instance.chat(messages, { stream: true }, res => { + console.log(i, res.content); + }); + } + return this.ok(); + } +}