Added overridable instruct settings, removed macro override
| @@ -190,6 +190,7 @@ export class TextCompletionService { | ||
| 190 | 190 | * @param {Object} options - Configuration options |
| 191 | 191 | * @param {string?} [options.presetName] - Name of the preset to use for generation settings |
| 192 | 192 | * @param {string?} [options.instructName] - Name of instruct preset for message formatting |
| 193 | + * @param {Partial<InstructSettings>?} [options.instructSettings] - Override instruct settings | |
| 193 | 194 | * @param {boolean} extractData - Whether to extract structured data from response |
| 194 | 195 | * @param {AbortSignal?} [signal] |
| 195 | 196 | * @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 | 233 | if (instructPreset) { |
| 233 | 234 | // Clone the preset to avoid modifying the original |
| 234 | 235 | instructPreset = structuredClone(instructPreset); |
| 235 | - instructPreset.macro = false; | |
| 236 | 236 | instructPreset.names_behavior = names_behavior_types.NONE; |
| 237 | + if (options.instructSettings) { | |
| 238 | + Object.assign(instructPreset, options.instructSettings); | |
| 239 | + } | |
| 237 | 240 | |
| 238 | 241 | // Format messages using instruct formatting |
| 239 | 242 | const formattedMessages = []; |
| @@ -270,7 +273,7 @@ export class TextCompletionService { | ||
| 270 | 273 | } |
| 271 | 274 | requestData.prompt = formattedMessages.join(''); |
| 272 | 275 | const stoppingStrings = getInstructStoppingSequences({ customInstruct: instructPreset, useStopString: false }); |
| 273 | 276 | requestData.stop = stoppingStrings; |
| 274 | 277 | requestData.stopping_strings = stoppingStrings; |
| 275 | 278 | } else { |
| 276 | 279 | console.warn(`Instruct preset "${instructName}" not found, using basic formatting`); |
| @@ -285,6 +285,7 @@ export class ConnectionManagerRequestService { | ||
| 285 | 285 | extractData: true, |
| 286 | 286 | includePreset: true, |
| 287 | 287 | includeInstruct: true, |
| 288 | + instructSettings: {}, | |
| 288 | 289 | }; |
| 289 | 290 | |
| 290 | 291 | static getAllowedTypes() { |
| @@ -298,11 +299,17 @@ export class ConnectionManagerRequestService { | ||
| 298 | 299 | * @param {string} profileId |
| 299 | 300 | * @param {string | (import('../custom-request.js').ChatCompletionMessage & {ignoreInstruct?: boolean})[]} prompt |
| 300 | 301 | * @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 | |
| 302 | 309 | * @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 | 311 | static async sendRequest(profileId, prompt, maxTokens, custom = this.defaultSendRequestParams) { |
| 305 | 312 | const { stream, signal, extractData, includePreset, includeInstruct, instructSettings } = { ...this.defaultSendRequestParams, ...custom }; |
| 306 | 313 | |
| 307 | 314 | const context = SillyTavern.getContext(); |
| 308 | 315 | if (context.extensionSettings.disabledExtensions.includes('connection-manager')) { |
| @@ -346,6 +353,7 @@ export class ConnectionManagerRequestService { | ||
| 346 | 353 | }, { |
| 347 | 354 | instructName: includeInstruct ? profile.instruct : undefined, |
| 348 | 355 | presetName: includePreset ? profile.preset : undefined, |
| 356 | + instructSettings: includeInstruct ? instructSettings : undefined, | |
| 349 | 357 | }, extractData, signal); |
| 350 | 358 | } |
| 351 | 359 | default: { |