Added overridable instruct settings, removed macro override

a7d48b1aed317625bb5eab5aac8baa471883b374

bmen25124 <bmen25124@gmail.com>

2 files changed, +15 -4Showing whitespace changes
public/scripts/custom-request.js+5 -2
@@ -190,6 +190,7 @@ export class TextCompletionService {
190 * @param {Object} options - Configuration options190 * @param {Object} options - Configuration options
191 * @param {string?} [options.presetName] - Name of the preset to use for generation settings191 * @param {string?} [options.presetName] - Name of the preset to use for generation settings
192 * @param {string?} [options.instructName] - Name of instruct preset for message formatting192 * @param {string?} [options.instructName] - Name of instruct preset for message formatting
193 * @param {Partial<InstructSettings>?} [options.instructSettings] - Override instruct settings
193 * @param {boolean} extractData - Whether to extract structured data from response194 * @param {boolean} extractData - Whether to extract structured data from response
194 * @param {AbortSignal?} [signal]195 * @param {AbortSignal?} [signal]
195 * @returns {Promise<ExtractedData | (() => AsyncGenerator<StreamResponse>)>} If not streaming, returns extracted data; if streaming, returns a function that creates an AsyncGenerator196 * @returns {Promise<ExtractedData | (() => AsyncGenerator<StreamResponse>)>} If not streaming, returns extracted data; if streaming, returns a function that creates an AsyncGenerator
@@ -232,8 +233,10 @@ export class TextCompletionService {
232 if (instructPreset) {233 if (instructPreset) {
233 // Clone the preset to avoid modifying the original234 // Clone the preset to avoid modifying the original
234 instructPreset = structuredClone(instructPreset);235 instructPreset = structuredClone(instructPreset);
235 instructPreset.macro = false;
236 instructPreset.names_behavior = names_behavior_types.NONE;236 instructPreset.names_behavior = names_behavior_types.NONE;
237 if (options.instructSettings) {
238 Object.assign(instructPreset, options.instructSettings);
239 }
237240
238 // Format messages using instruct formatting241 // Format messages using instruct formatting
239 const formattedMessages = [];242 const formattedMessages = [];
@@ -270,7 +273,7 @@ export class TextCompletionService {
270 }273 }
271 requestData.prompt = formattedMessages.join('');274 requestData.prompt = formattedMessages.join('');
272 const stoppingStrings = getInstructStoppingSequences({ customInstruct: instructPreset, useStopString: false });275 const stoppingStrings = getInstructStoppingSequences({ customInstruct: instructPreset, useStopString: false });
273 requestData.stop = stoppingStrings276 requestData.stop = stoppingStrings;
274 requestData.stopping_strings = stoppingStrings;277 requestData.stopping_strings = stoppingStrings;
275 } else {278 } else {
276 console.warn(`Instruct preset "${instructName}" not found, using basic formatting`);279 console.warn(`Instruct preset "${instructName}" not found, using basic formatting`);
public/scripts/extensions/shared.js+10 -2
@@ -285,6 +285,7 @@ export class ConnectionManagerRequestService {
285 extractData: true,285 extractData: true,
286 includePreset: true,286 includePreset: true,
287 includeInstruct: true,287 includeInstruct: true,
288 instructSettings: {},
288 };289 };
289290
290 static getAllowedTypes() {291 static getAllowedTypes() {
@@ -298,11 +299,17 @@ export class ConnectionManagerRequestService {
298 * @param {string} profileId299 * @param {string} profileId
299 * @param {string | (import('../custom-request.js').ChatCompletionMessage & {ignoreInstruct?: boolean})[]} prompt300 * @param {string | (import('../custom-request.js').ChatCompletionMessage & {ignoreInstruct?: boolean})[]} prompt
300 * @param {number} maxTokens301 * @param {number} maxTokens
301 * @param {{stream?: boolean, signal?: AbortSignal, extractData?: boolean, includePreset?: boolean, includeInstruct?: boolean}} custom - default values are true302 * @param {object} custom
303 * @param {boolean?} [custom.stream=false]
304 * @param {AbortSignal?} [custom.signal]
305 * @param {boolean?} [custom.extractData=true]
306 * @param {boolean?} [custom.includePreset=true]
307 * @param {boolean?} [custom.includeInstruct=true]
308 * @param {Partial<InstructSettings>?} [custom.instructSettings] Override instruct settings
302 * @returns {Promise<import('../custom-request.js').ExtractedData | (() => AsyncGenerator<import('../custom-request.js').StreamResponse>)>} If not streaming, returns extracted data; if streaming, returns a function that creates an AsyncGenerator309 * @returns {Promise<import('../custom-request.js').ExtractedData | (() => AsyncGenerator<import('../custom-request.js').StreamResponse>)>} If not streaming, returns extracted data; if streaming, returns a function that creates an AsyncGenerator
303 */310 */
304 static async sendRequest(profileId, prompt, maxTokens, custom = this.defaultSendRequestParams) {311 static async sendRequest(profileId, prompt, maxTokens, custom = this.defaultSendRequestParams) {
305 const { stream, signal, extractData, includePreset, includeInstruct } = { ...this.defaultSendRequestParams, ...custom };312 const { stream, signal, extractData, includePreset, includeInstruct, instructSettings } = { ...this.defaultSendRequestParams, ...custom };
306313
307 const context = SillyTavern.getContext();314 const context = SillyTavern.getContext();
308 if (context.extensionSettings.disabledExtensions.includes('connection-manager')) {315 if (context.extensionSettings.disabledExtensions.includes('connection-manager')) {
@@ -346,6 +353,7 @@ export class ConnectionManagerRequestService {
346 }, {353 }, {
347 instructName: includeInstruct ? profile.instruct : undefined,354 instructName: includeInstruct ? profile.instruct : undefined,
348 presetName: includePreset ? profile.preset : undefined,355 presetName: includePreset ? profile.preset : undefined,
356 instructSettings: includeInstruct ? instructSettings : undefined,
349 }, extractData, signal);357 }, extractData, signal);
350 }358 }
351 default: {359 default: {