mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge pull request #3721 from SillyTavern/or-prompt-post-processing
OpenRouter: Allow applying prompt post-processing
This commit is contained in:
@@ -3415,13 +3415,6 @@
|
|||||||
<div class="flex-container">
|
<div class="flex-container">
|
||||||
<select id="model_custom_select" class="text_pole model_custom_select"></select>
|
<select id="model_custom_select" class="text_pole model_custom_select"></select>
|
||||||
</div>
|
</div>
|
||||||
<h4 data-i18n="Prompt Post-Processing">Prompt Post-Processing</h4>
|
|
||||||
<select id="custom_prompt_post_processing" class="text_pole" title="Applies additional processing to the prompt before sending it to the API." data-i18n="[title]Applies additional processing to the prompt before sending it to the API.">
|
|
||||||
<option data-i18n="prompt_post_processing_none" value="">None</option>
|
|
||||||
<option data-i18n="prompt_post_processing_merge" value="merge">Merge consecutive roles</option>
|
|
||||||
<option data-i18n="prompt_post_processing_semi" value="semi">Semi-strict (alternating roles)</option>
|
|
||||||
<option data-i18n="prompt_post_processing_strict" value="strict">Strict (user first, alternating roles)</option>
|
|
||||||
</select>
|
|
||||||
</form>
|
</form>
|
||||||
<div id="01ai_form" data-source="01ai">
|
<div id="01ai_form" data-source="01ai">
|
||||||
<h4>
|
<h4>
|
||||||
@@ -3440,6 +3433,15 @@
|
|||||||
<select id="model_01ai_select">
|
<select id="model_01ai_select">
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="prompt_post_porcessing_form" data-source="custom,openrouter">
|
||||||
|
<h4 data-i18n="Prompt Post-Processing">Prompt Post-Processing</h4>
|
||||||
|
<select id="custom_prompt_post_processing" class="text_pole" title="Applies additional processing to the prompt before sending it to the API." data-i18n="[title]Applies additional processing to the prompt before sending it to the API.">
|
||||||
|
<option data-i18n="prompt_post_processing_none" value="">None</option>
|
||||||
|
<option data-i18n="prompt_post_processing_merge" value="merge">Merge consecutive roles</option>
|
||||||
|
<option data-i18n="prompt_post_processing_semi" value="semi">Semi-strict (alternating roles)</option>
|
||||||
|
<option data-i18n="prompt_post_processing_strict" value="strict">Strict (user first, alternating roles)</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div class="flex-container flex">
|
<div class="flex-container flex">
|
||||||
<div id="api_button_openai" class="api_button menu_button menu_button_icon" type="submit" data-i18n="Connect">Connect</div>
|
<div id="api_button_openai" class="api_button menu_button menu_button_icon" type="submit" data-i18n="Connect">Connect</div>
|
||||||
<div class="api_loading menu_button menu_button_icon" data-i18n="Cancel">Cancel</div>
|
<div class="api_loading menu_button menu_button_icon" data-i18n="Cancel">Cancel</div>
|
||||||
|
@@ -2020,6 +2020,7 @@ async function sendOpenAIRequest(type, messages, signal) {
|
|||||||
'reasoning_effort': String(oai_settings.reasoning_effort),
|
'reasoning_effort': String(oai_settings.reasoning_effort),
|
||||||
'enable_web_search': Boolean(oai_settings.enable_web_search),
|
'enable_web_search': Boolean(oai_settings.enable_web_search),
|
||||||
'request_images': Boolean(oai_settings.request_images),
|
'request_images': Boolean(oai_settings.request_images),
|
||||||
|
'custom_prompt_post_processing': oai_settings.custom_prompt_post_processing,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!canMultiSwipe && ToolManager.canPerformToolCalls(type)) {
|
if (!canMultiSwipe && ToolManager.canPerformToolCalls(type)) {
|
||||||
@@ -2100,7 +2101,6 @@ async function sendOpenAIRequest(type, messages, signal) {
|
|||||||
generate_data['custom_include_body'] = oai_settings.custom_include_body;
|
generate_data['custom_include_body'] = oai_settings.custom_include_body;
|
||||||
generate_data['custom_exclude_body'] = oai_settings.custom_exclude_body;
|
generate_data['custom_exclude_body'] = oai_settings.custom_exclude_body;
|
||||||
generate_data['custom_include_headers'] = oai_settings.custom_include_headers;
|
generate_data['custom_include_headers'] = oai_settings.custom_include_headers;
|
||||||
generate_data['custom_prompt_post_processing'] = oai_settings.custom_prompt_post_processing;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCohere) {
|
if (isCohere) {
|
||||||
|
@@ -1048,6 +1048,15 @@ router.post('/generate', function (request, response) {
|
|||||||
let bodyParams;
|
let bodyParams;
|
||||||
const isTextCompletion = Boolean(request.body.model && TEXT_COMPLETION_MODELS.includes(request.body.model)) || typeof request.body.messages === 'string';
|
const isTextCompletion = Boolean(request.body.model && TEXT_COMPLETION_MODELS.includes(request.body.model)) || typeof request.body.messages === 'string';
|
||||||
|
|
||||||
|
const postProcessTypes = [CHAT_COMPLETION_SOURCES.CUSTOM, CHAT_COMPLETION_SOURCES.OPENROUTER];
|
||||||
|
if (Array.isArray(request.body.messages) && postProcessTypes.includes(request.body.chat_completion_source) && request.body.custom_prompt_post_processing) {
|
||||||
|
console.info('Applying custom prompt post-processing of type', request.body.custom_prompt_post_processing);
|
||||||
|
request.body.messages = postProcessPrompt(
|
||||||
|
request.body.messages,
|
||||||
|
request.body.custom_prompt_post_processing,
|
||||||
|
getPromptNames(request));
|
||||||
|
}
|
||||||
|
|
||||||
if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.OPENAI) {
|
if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.OPENAI) {
|
||||||
apiUrl = new URL(request.body.reverse_proxy || API_OPENAI).toString();
|
apiUrl = new URL(request.body.reverse_proxy || API_OPENAI).toString();
|
||||||
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.OPENAI);
|
apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.OPENAI);
|
||||||
@@ -1121,14 +1130,6 @@ router.post('/generate', function (request, response) {
|
|||||||
|
|
||||||
mergeObjectWithYaml(bodyParams, request.body.custom_include_body);
|
mergeObjectWithYaml(bodyParams, request.body.custom_include_body);
|
||||||
mergeObjectWithYaml(headers, request.body.custom_include_headers);
|
mergeObjectWithYaml(headers, request.body.custom_include_headers);
|
||||||
|
|
||||||
if (request.body.custom_prompt_post_processing) {
|
|
||||||
console.info('Applying custom prompt post-processing of type', request.body.custom_prompt_post_processing);
|
|
||||||
request.body.messages = postProcessPrompt(
|
|
||||||
request.body.messages,
|
|
||||||
request.body.custom_prompt_post_processing,
|
|
||||||
getPromptNames(request));
|
|
||||||
}
|
|
||||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.PERPLEXITY) {
|
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.PERPLEXITY) {
|
||||||
apiUrl = API_PERPLEXITY;
|
apiUrl = API_PERPLEXITY;
|
||||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.PERPLEXITY);
|
apiKey = readSecret(request.user.directories, SECRET_KEYS.PERPLEXITY);
|
||||||
|
Reference in New Issue
Block a user