Added overridable instruct settings, removed macro override
| @@ -190,6 +190,7 @@ export class TextCompletionService { | |||
| 190 | * @param {Object} options - Configuration options | 190 | * @param {Object} options - Configuration options |
| 191 | * @param {string?} [options.presetName] - Name of the preset to use for generation settings | 191 | * @param {string?} [options.presetName] - Name of the preset to use for generation settings |
| 192 | * @param {string?} [options.instructName] - Name of instruct preset for message formatting | 192 | * @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 response | 194 | * @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 AsyncGenerator | 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 | if (instructPreset) { | 233 | if (instructPreset) { |
| 233 | // Clone the preset to avoid modifying the original | 234 | // 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 | } | ||
| 237 | 240 | ||
| 238 | // Format messages using instruct formatting | 241 | // 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 = stoppingStrings | 276 | 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`); |
| @@ -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 | }; |
| 289 | 290 | ||
| 290 | static getAllowedTypes() { | 291 | static getAllowedTypes() { |
| @@ -298,11 +299,17 @@ export class ConnectionManagerRequestService { | |||
| 298 | * @param {string} profileId | 299 | * @param {string} profileId |
| 299 | * @param {string | (import('../custom-request.js').ChatCompletionMessage & {ignoreInstruct?: boolean})[]} prompt | 300 | * @param {string | (import('../custom-request.js').ChatCompletionMessage & {ignoreInstruct?: boolean})[]} prompt |
| 300 | * @param {number} maxTokens | 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 | * @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 | 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 | 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 }; |
| 306 | 313 | ||
| 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: { |