From a35f8a31a07a848ce655ebb3cd343343f764cc82 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Sun, 25 Jun 2023 18:07:23 +0800 Subject: [PATCH] feat: try to support ap-plugin --- apps/chat.js | 13 ++++++++----- utils/tools/APTool.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 utils/tools/APTool.js diff --git a/apps/chat.js b/apps/chat.js index 85f02fc..c8b3752 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -1,6 +1,6 @@ import plugin from '../../../lib/plugins/plugin.js' import _ from 'lodash' -import { Config, defaultOpenAIAPI, pureSydneyInstruction } from '../utils/config.js' +import { Config, defaultOpenAIAPI } from '../utils/config.js' import { v4 as uuid } from 'uuid' import delay from 'delay' import { ChatGPTAPI } from '../utils/openai/chatgpt-api.js' @@ -61,8 +61,9 @@ import { SerpIkechan8370Tool } from '../utils/tools/SerpIkechan8370Tool.js' import { SendPictureTool } from '../utils/tools/SendPictureTool.js' import { SerpImageTool } from '../utils/tools/SearchImageTool.js' import { ImageCaptionTool } from '../utils/tools/ImageCaptionTool.js' -import {TTSTool} from "../utils/tools/TTSTool.js"; -import {ProcessPictureTool} from "../utils/tools/ProcessPictureTool.js"; +import { TTSTool } from '../utils/tools/TTSTool.js' +import { ProcessPictureTool } from '../utils/tools/ProcessPictureTool.js' +import { APTool } from '../utils/tools/APTool.js' try { await import('emoji-strip') } catch (err) { @@ -1975,7 +1976,8 @@ export class chatgpt extends plugin { new SerpIkechan8370Tool(), new SerpTool(), new TTSTool(), - new ProcessPictureTool() + new ProcessPictureTool(), + new APTool() ] // todo 3.0再重构tool的插拔和管理 let tools = [ @@ -1989,6 +1991,7 @@ export class chatgpt extends plugin { new WeatherTool(), new SendPictureTool(), new TTSTool(), + new APTool(), serpTool ] let img = [] @@ -2059,7 +2062,7 @@ export class chatgpt extends plugin { } catch (err) { args.groupId = e.group_id + '' || e.sender.user_id + '' } - let functionResult = await fullFuncMap[name].exec(Object.assign({ isAdmin, sender }, args)) + let functionResult = await fullFuncMap[name].exec(Object.assign({ isAdmin, sender }, args), e) logger.mark(`function ${name} execution result: ${functionResult}`) option.parentMessageId = msg.id option.name = name diff --git a/utils/tools/APTool.js b/utils/tools/APTool.js new file mode 100644 index 0000000..d7eecaa --- /dev/null +++ b/utils/tools/APTool.js @@ -0,0 +1,36 @@ +import { AbstractTool } from './AbstractTool.js' + +export class APTool extends AbstractTool { + name = 'draw' + + parameters = { + properties: { + prompt: { + type: 'string', + description: 'draw prompt of StableDiffusion, must be in English' + } + }, + required: ['prompt'] + } + + description = 'Useful when you want to draw' + + func = async function (opts, e) { + let { prompt } = opts + let ap + try { + // eslint-disable-next-line camelcase + let { Ai_Painting } = await import('../../../ap-plugin/apps/aiPainting.js') + ap = new Ai_Painting(e) + } catch (err) { + return 'the user didn\'t install ap-plugin' + } + try { + e.msg = '#绘图' + prompt + await ap.aiPainting(e) + return 'draw success!' + } catch (err) { + return 'draw failed due to unknown error' + } + } +}