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 {
190190 * @param {Object} options - Configuration options
191191 * @param {string?} [options.presetName] - Name of the preset to use for generation settings
192192 * @param {string?} [options.instructName] - Name of instruct preset for message formatting
193+ * @param {Partial<InstructSettings>?} [options.instructSettings] - Override instruct settings
193194 * @param {boolean} extractData - Whether to extract structured data from response
194195 * @param {AbortSignal?} [signal]
195196 * @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 {
232233 if (instructPreset) {
233234 // Clone the preset to avoid modifying the original
234235 instructPreset = structuredClone(instructPreset);
235- instructPreset.macro = false;
236236 instructPreset.names_behavior = names_behavior_types.NONE;
237+ if (options.instructSettings) {
238+ Object.assign(instructPreset, options.instructSettings);
239+ }
237240
238241 // Format messages using instruct formatting
239242 const formattedMessages = [];
@@ -270,7 +273,7 @@ export class TextCompletionService {
270273 }
271274 requestData.prompt = formattedMessages.join('');
272275 const stoppingStrings = getInstructStoppingSequences({ customInstruct: instructPreset, useStopString: false });
273276 requestData.stop = stoppingStrings;
274277 requestData.stopping_strings = stoppingStrings;
275278 } else {
276279 console.warn(`Instruct preset "${instructName}" not found, using basic formatting`);
public/scripts/extensions/shared.js+10 -2
@@ -285,6 +285,7 @@ export class ConnectionManagerRequestService {
285285 extractData: true,
286286 includePreset: true,
287287 includeInstruct: true,
288+ instructSettings: {},
288289 };
289290
290291 static getAllowedTypes() {
@@ -298,11 +299,17 @@ export class ConnectionManagerRequestService {
298299 * @param {string} profileId
299300 * @param {string | (import('../custom-request.js').ChatCompletionMessage & {ignoreInstruct?: boolean})[]} prompt
300301 * @param {number} maxTokens
301- * @param {{stream?: boolean, signal?: AbortSignal, extractData?: boolean, includePreset?: boolean, includeInstruct?: boolean}} custom - default values are true
302+ * @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
302309 * @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
303310 */
304311 static async sendRequest(profileId, prompt, maxTokens, custom = this.defaultSendRequestParams) {
305312 const { stream, signal, extractData, includePreset, includeInstruct, instructSettings } = { ...this.defaultSendRequestParams, ...custom };
306313
307314 const context = SillyTavern.getContext();
308315 if (context.extensionSettings.disabledExtensions.includes('connection-manager')) {
@@ -346,6 +353,7 @@ export class ConnectionManagerRequestService {
346353 }, {
347354 instructName: includeInstruct ? profile.instruct : undefined,
348355 presetName: includePreset ? profile.preset : undefined,
356+ instructSettings: includeInstruct ? instructSettings : undefined,
349357 }, extractData, signal);
350358 }
351359 default: {