mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Added overridable instruct settings, removed macro override
This commit is contained in:
@@ -190,6 +190,7 @@ export class TextCompletionService {
|
|||||||
* @param {Object} options - Configuration options
|
* @param {Object} options - Configuration options
|
||||||
* @param {string?} [options.presetName] - Name of the preset to use for generation settings
|
* @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 {string?} [options.instructName] - Name of instruct preset for message formatting
|
||||||
|
* @param {Partial<InstructSettings>?} [options.instructSettings] - Override instruct settings
|
||||||
* @param {boolean} extractData - Whether to extract structured data from response
|
* @param {boolean} extractData - Whether to extract structured data from response
|
||||||
* @param {AbortSignal?} [signal]
|
* @param {AbortSignal?} [signal]
|
||||||
* @returns {Promise<ExtractedData | (() => AsyncGenerator<StreamResponse>)>} If not streaming, returns extracted data; if streaming, returns a function that creates an AsyncGenerator
|
* @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 {
|
|||||||
if (instructPreset) {
|
if (instructPreset) {
|
||||||
// Clone the preset to avoid modifying the original
|
// Clone the preset to avoid modifying the original
|
||||||
instructPreset = structuredClone(instructPreset);
|
instructPreset = structuredClone(instructPreset);
|
||||||
instructPreset.macro = false;
|
|
||||||
instructPreset.names_behavior = names_behavior_types.NONE;
|
instructPreset.names_behavior = names_behavior_types.NONE;
|
||||||
|
if (options.instructSettings) {
|
||||||
|
Object.assign(instructPreset, options.instructSettings);
|
||||||
|
}
|
||||||
|
|
||||||
// Format messages using instruct formatting
|
// Format messages using instruct formatting
|
||||||
const formattedMessages = [];
|
const formattedMessages = [];
|
||||||
@@ -270,7 +273,7 @@ export class TextCompletionService {
|
|||||||
}
|
}
|
||||||
requestData.prompt = formattedMessages.join('');
|
requestData.prompt = formattedMessages.join('');
|
||||||
const stoppingStrings = getInstructStoppingSequences({ customInstruct: instructPreset, useStopString: false });
|
const stoppingStrings = getInstructStoppingSequences({ customInstruct: instructPreset, useStopString: false });
|
||||||
requestData.stop = stoppingStrings
|
requestData.stop = stoppingStrings;
|
||||||
requestData.stopping_strings = stoppingStrings;
|
requestData.stopping_strings = stoppingStrings;
|
||||||
} else {
|
} else {
|
||||||
console.warn(`Instruct preset "${instructName}" not found, using basic formatting`);
|
console.warn(`Instruct preset "${instructName}" not found, using basic formatting`);
|
||||||
|
@@ -285,6 +285,7 @@ export class ConnectionManagerRequestService {
|
|||||||
extractData: true,
|
extractData: true,
|
||||||
includePreset: true,
|
includePreset: true,
|
||||||
includeInstruct: true,
|
includeInstruct: true,
|
||||||
|
instructSettings: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
static getAllowedTypes() {
|
static getAllowedTypes() {
|
||||||
@@ -298,11 +299,17 @@ export class ConnectionManagerRequestService {
|
|||||||
* @param {string} profileId
|
* @param {string} profileId
|
||||||
* @param {string | (import('../custom-request.js').ChatCompletionMessage & {ignoreInstruct?: boolean})[]} prompt
|
* @param {string | (import('../custom-request.js').ChatCompletionMessage & {ignoreInstruct?: boolean})[]} prompt
|
||||||
* @param {number} maxTokens
|
* @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<InstructSettings>?} [custom.instructSettings] Override instruct settings
|
||||||
* @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
|
* @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
|
||||||
*/
|
*/
|
||||||
static async sendRequest(profileId, prompt, maxTokens, custom = this.defaultSendRequestParams) {
|
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();
|
const context = SillyTavern.getContext();
|
||||||
if (context.extensionSettings.disabledExtensions.includes('connection-manager')) {
|
if (context.extensionSettings.disabledExtensions.includes('connection-manager')) {
|
||||||
@@ -346,6 +353,7 @@ export class ConnectionManagerRequestService {
|
|||||||
}, {
|
}, {
|
||||||
instructName: includeInstruct ? profile.instruct : undefined,
|
instructName: includeInstruct ? profile.instruct : undefined,
|
||||||
presetName: includePreset ? profile.preset : undefined,
|
presetName: includePreset ? profile.preset : undefined,
|
||||||
|
instructSettings: includeInstruct ? instructSettings : undefined,
|
||||||
}, extractData, signal);
|
}, extractData, signal);
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
Reference in New Issue
Block a user