From cacad3600eb1740779bc4d8fcf7f5467fb4330c1 Mon Sep 17 00:00:00 2001 From: Bo26fhmC5M <88071760+Bo26fhmC5M@users.noreply.github.com> Date: Sat, 15 Mar 2025 01:13:30 +0900 Subject: [PATCH] fix: update plugin docs with abortSignal support - Add setArg function to plugin docs - Add abortSignal parameter to addProvider function --- plugins.md | 14 ++++++++++++-- src/ts/plugins/plugins.ts | 7 ++++--- src/ts/process/request.ts | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/plugins.md b/plugins.md index 92832dab..a11ff891 100644 --- a/plugins.md +++ b/plugins.md @@ -75,6 +75,15 @@ Gets the argument value by name. - `string|number` - The argument value. +### `setArg(name: string, value: string|number): void` + +Sets the argument value by name. + +#### Arguments + +- `name: string` - The argument name. must be format of `::` like `exampleplugin::arg1`. +- `value: string|number` - The argument value. + ### `getChar(): character` Gets the current character. @@ -83,14 +92,14 @@ Gets the current character. Sets the current character. -### `addProvider(type: string, func: (arg:PluginV2ProviderArgument, options?:PluginV2ProviderOptions) => Promise<{success:boolean,content:string}>): void` +### `addProvider(type: string, func: (arg:PluginV2ProviderArgument, abortSignal?: AbortSignal) => Promise<{success:boolean,content:string|ReadableStream}>, options?:PluginV2ProviderOptions): void` Adds a provider to the plugin. #### Arguments - `type: string` - The provider name. -- `func: (arg:PluginV2ProviderArgument) => Promise<{success:boolean,content:string}>` - The provider function. +- `func: (arg:PluginV2ProviderArgument, abortSignal?: AbortSignal) => Promise<{success:boolean,content:string}>` - The provider function. - `arg: PluginV2ProviderArgument` - The provider argument. - `prompt_chat: Chat[]` - The chat prompt. - `frequency_penalty?: number` - The frequency penalty. @@ -102,6 +111,7 @@ Adds a provider to the plugin. - `temperature?: number` - The temperature value. - `max_tokens?: number` - The max tokens value. - `mode: string` - The mode. one of `model`, `submodel`, `memory`, `emotion`, `otherAx`, `translate` + - `abortSignal?: AbortSignal` - The signal to use for aborting the request. - `Promise<{success:boolean,content:string|ReadableStream}>` - The provider result. - `success: boolean` - If the provider was successful. - `content: string|ReadableStream` - The provider content. if it's a ReadableStream, it will be streamed to the chat. diff --git a/src/ts/plugins/plugins.ts b/src/ts/plugins/plugins.ts index df59fed7..2a757db8 100644 --- a/src/ts/plugins/plugins.ts +++ b/src/ts/plugins/plugins.ts @@ -120,7 +120,7 @@ export async function loadPlugins() { } type PluginV2ProviderArgument = { - prompt_chat: OpenAIChat[], + prompt_chat: OpenAIChat[] frequency_penalty: number min_p: number presence_penalty: number @@ -129,6 +129,7 @@ type PluginV2ProviderArgument = { top_p: number temperature: number mode: string + max_tokens: number } type PluginV2ProviderOptions = { @@ -140,7 +141,7 @@ type EditFunction = (content:string) => string|null|undefined|Promise OpenAIChat[]|Promise export const pluginV2 = { - providers: new Map Promise<{success:boolean,content:string|ReadableStream}> >(), + providers: new Map Promise<{success:boolean,content:string|ReadableStream}> >(), providerOptions: new Map(), editdisplay: new Set(), editoutput: new Set(), @@ -189,7 +190,7 @@ export async function loadV2Plugin(plugins:RisuPlugin[]){ db.characters[charid] = char setDatabaseLite(db) }, - addProvider: (name:string, func:(arg:PluginV2ProviderArgument) => Promise<{success:boolean,content:string}>, options?:PluginV2ProviderOptions) => { + addProvider: (name:string, func:(arg:PluginV2ProviderArgument, abortSignal?:AbortSignal) => Promise<{success:boolean,content:string}>, options?:PluginV2ProviderOptions) => { let provs = get(customProviderStore) provs.push(name) pluginV2.providers.set(name, func) diff --git a/src/ts/process/request.ts b/src/ts/process/request.ts index d2e76f71..d07b5014 100644 --- a/src/ts/process/request.ts +++ b/src/ts/process/request.ts @@ -1606,7 +1606,7 @@ async function requestPlugin(arg:RequestDataArgumentExtended):Promise