diff --git a/public/scripts/custom-request.js b/public/scripts/custom-request.js index d6281a57a..353e6cec0 100644 --- a/public/scripts/custom-request.js +++ b/public/scripts/custom-request.js @@ -190,6 +190,7 @@ export class TextCompletionService { * @param {Object} options - Configuration options * @param {string?} [options.presetName] - Name of the preset to use for generation settings * @param {string?} [options.instructName] - Name of instruct preset for message formatting + * @param {Partial?} [options.instructSettings] - Override instruct settings * @param {boolean} extractData - Whether to extract structured data from response * @param {AbortSignal?} [signal] * @returns {Promise AsyncGenerator)>} If not streaming, returns extracted data; if streaming, returns a function that creates an AsyncGenerator @@ -232,8 +233,10 @@ export class TextCompletionService { if (instructPreset) { // Clone the preset to avoid modifying the original instructPreset = structuredClone(instructPreset); - instructPreset.macro = false; instructPreset.names_behavior = names_behavior_types.NONE; + if (options.instructSettings) { + Object.assign(instructPreset, options.instructSettings); + } // Format messages using instruct formatting const formattedMessages = []; @@ -270,7 +273,7 @@ export class TextCompletionService { } requestData.prompt = formattedMessages.join(''); const stoppingStrings = getInstructStoppingSequences({ customInstruct: instructPreset, useStopString: false }); - requestData.stop = stoppingStrings + requestData.stop = stoppingStrings; requestData.stopping_strings = stoppingStrings; } else { console.warn(`Instruct preset "${instructName}" not found, using basic formatting`); diff --git a/public/scripts/extensions/shared.js b/public/scripts/extensions/shared.js index 144ac3d6b..9ca630fa9 100644 --- a/public/scripts/extensions/shared.js +++ b/public/scripts/extensions/shared.js @@ -285,6 +285,7 @@ export class ConnectionManagerRequestService { extractData: true, includePreset: true, includeInstruct: true, + instructSettings: {}, }; static getAllowedTypes() { @@ -298,11 +299,17 @@ export class ConnectionManagerRequestService { * @param {string} profileId * @param {string | (import('../custom-request.js').ChatCompletionMessage & {ignoreInstruct?: boolean})[]} prompt * @param {number} maxTokens - * @param {{stream?: boolean, signal?: AbortSignal, extractData?: boolean, includePreset?: boolean, includeInstruct?: boolean}} custom - default values are true + * @param {object} custom + * @param {boolean?} [custom.stream=false] + * @param {AbortSignal?} [custom.signal] + * @param {boolean?} [custom.extractData=true] + * @param {boolean?} [custom.includePreset=true] + * @param {boolean?} [custom.includeInstruct=true] + * @param {Partial?} [custom.instructSettings] Override instruct settings * @returns {Promise AsyncGenerator)>} If not streaming, returns extracted data; if streaming, returns a function that creates an AsyncGenerator */ static async sendRequest(profileId, prompt, maxTokens, custom = this.defaultSendRequestParams) { - const { stream, signal, extractData, includePreset, includeInstruct } = { ...this.defaultSendRequestParams, ...custom }; + const { stream, signal, extractData, includePreset, includeInstruct, instructSettings } = { ...this.defaultSendRequestParams, ...custom }; const context = SillyTavern.getContext(); if (context.extensionSettings.disabledExtensions.includes('connection-manager')) { @@ -346,6 +353,7 @@ export class ConnectionManagerRequestService { }, { instructName: includeInstruct ? profile.instruct : undefined, presetName: includePreset ? profile.preset : undefined, + instructSettings: includeInstruct ? instructSettings : undefined, }, extractData, signal); } default: {