Merge branch 'SillyTavern:staging' into staging

This commit is contained in:
Tony Ribeiro 2023-08-24 15:18:02 +02:00 committed by GitHub
commit 43e70c9df1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 118 additions and 15 deletions

View File

@ -129,6 +129,7 @@
"prefer_character_prompt": true, "prefer_character_prompt": true,
"prefer_character_jailbreak": true, "prefer_character_jailbreak": true,
"quick_continue": false, "quick_continue": false,
"continue_on_send": false,
"trim_spaces": true, "trim_spaces": true,
"relaxed_api_urls": false, "relaxed_api_urls": false,
"default_instruct": "", "default_instruct": "",

View File

@ -0,0 +1,6 @@
{
"name": "NovelAI",
"story_string": "{{#if system}}{{system}}{{/if}}\n{{#if wiBefore}}{{wiBefore}}{{/if}}\n{{#if persona}}{{persona}}{{/if}}\n{{#if description}}{{description}}{{/if}}\n{{#if personality}}Personality: {{personality}}{{/if}}\n{{#if scenario}}Scenario: {{scenario}}{{/if}}\n{{#if wiAfter}}{{wiAfter}}{{/if}}",
"chat_start": "***",
"example_separator": "***"
}

View File

@ -1972,6 +1972,17 @@
<option data-i18n="Connect to the API">-- Connect to the API --</option> <option data-i18n="Connect to the API">-- Connect to the API --</option>
</select> </select>
</div> </div>
<div class="marginTopBot5">
<label for="openrouter_use_fallback" class="checkbox_label">
<input id="openrouter_use_fallback" type="checkbox" />
<span data-i18n="Allow fallback routes">Allow fallback routes</span>
</label>
<div class="toggle-description justifyLeft">
<span data-i18n="Allow fallback routes Description">
Automatically chooses an alternative model if the chosen model can't serve your request.
</span>
</div>
</div>
<h4 data-i18n="OpenRouter API Key">OpenRouter API Key</h4> <h4 data-i18n="OpenRouter API Key">OpenRouter API Key</h4>
<div> <div>
<small> <small>
@ -2816,6 +2827,12 @@
<input id="prefer_character_jailbreak" type="checkbox" /> <input id="prefer_character_jailbreak" type="checkbox" />
<span data-i18n="Prefer Character Card Jailbreak">Prefer Char. JB</span> <span data-i18n="Prefer Character Card Jailbreak">Prefer Char. JB</span>
</label> </label>
<label class="checkbox_label" for="continue_on_send">
<input id="continue_on_send" type="checkbox" />
<span data-i18n="Press Send to continue">
Press "Send" to continue
</span>
</label>
<label class="checkbox_label" for="quick_continue"> <label class="checkbox_label" for="quick_continue">
<input id="quick_continue" type="checkbox" /> <input id="quick_continue" type="checkbox" />
<span data-i18n="Press Send to continue"> <span data-i18n="Press Send to continue">

View File

@ -1,8 +1,8 @@
{ {
"name": "Vicuna 1.1", "name": "Vicuna 1.1",
"system_prompt": "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.\n\nWrite {{char}}'s next reply in a fictional roleplay chat between {{user}} and {{char}}.\n", "system_prompt": "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.\n\nWrite {{char}}'s next reply in a fictional roleplay chat between {{user}} and {{char}}.\n",
"input_sequence": "USER: ", "input_sequence": "\nUSER: ",
"output_sequence": "ASSISTANT: ", "output_sequence": "\nASSISTANT: ",
"last_output_sequence": "", "last_output_sequence": "",
"system_sequence": "BEGINNING OF CONVERSATION:", "system_sequence": "BEGINNING OF CONVERSATION:",
"stop_sequence": "", "stop_sequence": "",

View File

@ -2,7 +2,7 @@
"compilerOptions": { "compilerOptions": {
"checkJs": true, "checkJs": true,
"target": "ESNext", "target": "ESNext",
"module": "commonjs", "module": "ESNext",
"allowUmdGlobalAccess": true, "allowUmdGlobalAccess": true,
"allowSyntheticDefaultImports": true "allowSyntheticDefaultImports": true
}, },

View File

@ -2320,6 +2320,10 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
} }
} }
if (!type && !textareaText && power_user.continue_on_send && !selected_group && chat.length && !chat[chat.length - 1]['is_user'] && !chat[chat.length - 1]['is_system']) {
type = 'continue';
}
const isContinue = type == 'continue'; const isContinue = type == 'continue';
if (!dryRun) { if (!dryRun) {
@ -2641,8 +2645,11 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
console.debug('--setting Prompt string'); console.debug('--setting Prompt string');
mesExmString = pinExmString ?? mesExamplesArray.slice(0, count_exm_add).join(''); mesExmString = pinExmString ?? mesExamplesArray.slice(0, count_exm_add).join('');
if (mesSend.length) {
mesSend[mesSend.length - 1] = modifyLastPromptLine(mesSend[mesSend.length - 1]); mesSend[mesSend.length - 1] = modifyLastPromptLine(mesSend[mesSend.length - 1]);
} }
}
function modifyLastPromptLine(lastMesString) { function modifyLastPromptLine(lastMesString) {
// Add quiet generation prompt at depth 0 // Add quiet generation prompt at depth 0
@ -3332,11 +3339,7 @@ function addChatsPreamble(mesSendString) {
} }
function addChatsSeparator(mesSendString) { function addChatsSeparator(mesSendString) {
if (main_api === 'novel') { if (power_user.context.chat_start) {
return '***\n' + mesSendString;
}
else if (power_user.context.chat_start) {
return power_user.context.chat_start + '\n' + mesSendString; return power_user.context.chat_start + '\n' + mesSendString;
} }
@ -3803,6 +3806,10 @@ async function saveReply(type, getMessage, this_mes_is_name, title) {
type = 'normal'; type = 'normal';
} }
if (chat.length && typeof chat[chat.length - 1]['extra'] !== 'object') {
chat[chat.length - 1]['extra'] = {};
}
let oldMessage = '' let oldMessage = ''
const generationFinished = new Date(); const generationFinished = new Date();
const img = extractImageFromMessage(getMessage); const img = extractImageFromMessage(getMessage);
@ -4360,18 +4367,17 @@ function getFirstMessage() {
const message = { const message = {
name: name2, name: name2,
is_user: false, is_user: false,
is_system: false,
is_name: true, is_name: true,
send_date: getMessageTimeStamp(), send_date: getMessageTimeStamp(),
mes: getRegexedString(firstMes, regex_placement.AI_OUTPUT), mes: getRegexedString(firstMes, regex_placement.AI_OUTPUT),
extra: {},
}; };
if (Array.isArray(alternateGreetings) && alternateGreetings.length > 0) { if (Array.isArray(alternateGreetings) && alternateGreetings.length > 0) {
const swipes = [message.mes, ...(alternateGreetings.map(greeting => substituteParams(getRegexedString(greeting, regex_placement.AI_OUTPUT))))];
message['swipe_id'] = 0; message['swipe_id'] = 0;
message['swipes'] = message['mes'].concat( message['swipes'] = swipes;
alternateGreetings.map(
(greeting) => substituteParams(getRegexedString(greeting, regex_placement.AI_OUTPUT))
)
);
message['swipe_info'] = []; message['swipe_info'] = [];
} }
return message; return message;

View File

@ -3,6 +3,55 @@ import { waitUntilCondition } from "./utils.js";
const storageKey = "language"; const storageKey = "language";
export const localeData = await fetch("i18n.json").then(response => response.json()); export const localeData = await fetch("i18n.json").then(response => response.json());
function getMissingTranslations() {
const missingData = [];
for (const language of localeData.lang) {
$(document).find("[data-i18n]").each(function () {
const keys = $(this).data("i18n").split(';'); // Multi-key entries are ; delimited
for (const key of keys) {
const attributeMatch = key.match(/\[(\S+)\](.+)/); // [attribute]key
if (attributeMatch) { // attribute-tagged key
const localizedValue = localeData?.[language]?.[attributeMatch[2]];
if (!localizedValue) {
missingData.push({ key, language, value: $(this).attr(attributeMatch[1]) });
}
} else { // No attribute tag, treat as 'text'
const localizedValue = localeData?.[language]?.[key];
if (!localizedValue) {
missingData.push({ key, language, value: $(this).text().trim() });
}
}
}
});
}
// Remove duplicates
const uniqueMissingData = [];
for (const { key, language, value } of missingData) {
if (!uniqueMissingData.some(x => x.key === key && x.language === language && x.value === value)) {
uniqueMissingData.push({ key, language, value });
}
}
// Sort by language, then key
uniqueMissingData.sort((a, b) => a.language.localeCompare(b.language) || a.key.localeCompare(b.key));
// Map to { language: { key: value } }
const missingDataMap = {};
for (const { key, language, value } of uniqueMissingData) {
if (!missingDataMap[language]) {
missingDataMap[language] = {};
}
missingDataMap[language][key] = value;
}
console.table(uniqueMissingData);
console.log(missingDataMap);
}
window["getMissingTranslations"] = getMissingTranslations;
export function applyLocale(root = document) { export function applyLocale(root = document) {
const overrideLanguage = localStorage.getItem("language"); const overrideLanguage = localStorage.getItem("language");
var language = overrideLanguage || navigator.language || navigator.userLanguage; var language = overrideLanguage || navigator.language || navigator.userLanguage;

View File

@ -174,6 +174,7 @@ const default_settings = {
ai21_model: 'j2-ultra', ai21_model: 'j2-ultra',
windowai_model: '', windowai_model: '',
openrouter_model: openrouter_website_model, openrouter_model: openrouter_website_model,
openrouter_use_fallback: true,
jailbreak_system: false, jailbreak_system: false,
reverse_proxy: '', reverse_proxy: '',
legacy_streaming: false, legacy_streaming: false,
@ -217,6 +218,7 @@ const oai_settings = {
ai21_model: 'j2-ultra', ai21_model: 'j2-ultra',
windowai_model: '', windowai_model: '',
openrouter_model: openrouter_website_model, openrouter_model: openrouter_website_model,
openrouter_use_fallback: true,
jailbreak_system: false, jailbreak_system: false,
reverse_proxy: '', reverse_proxy: '',
legacy_streaming: false, legacy_streaming: false,
@ -1158,6 +1160,7 @@ async function sendOpenAIRequest(type, openai_msgs_tosend, signal) {
if (isOpenRouter) { if (isOpenRouter) {
generate_data['use_openrouter'] = true; generate_data['use_openrouter'] = true;
generate_data['top_k'] = Number(oai_settings.top_k_openai); generate_data['top_k'] = Number(oai_settings.top_k_openai);
generate_data['use_fallback'] = oai_settings.openrouter_use_fallback;
} }
if (isScale) { if (isScale) {
@ -1842,6 +1845,7 @@ function loadOpenAISettings(data, settings) {
oai_settings.claude_model = settings.claude_model ?? default_settings.claude_model; oai_settings.claude_model = settings.claude_model ?? default_settings.claude_model;
oai_settings.windowai_model = settings.windowai_model ?? default_settings.windowai_model; oai_settings.windowai_model = settings.windowai_model ?? default_settings.windowai_model;
oai_settings.openrouter_model = settings.openrouter_model ?? default_settings.openrouter_model; oai_settings.openrouter_model = settings.openrouter_model ?? default_settings.openrouter_model;
oai_settings.openrouter_use_fallback = settings.openrouter_use_fallback ?? default_settings.openrouter_use_fallback;
oai_settings.ai21_model = settings.ai21_model ?? default_settings.ai21_model; oai_settings.ai21_model = settings.ai21_model ?? default_settings.ai21_model;
oai_settings.chat_completion_source = settings.chat_completion_source ?? default_settings.chat_completion_source; oai_settings.chat_completion_source = settings.chat_completion_source ?? default_settings.chat_completion_source;
oai_settings.api_url_scale = settings.api_url_scale ?? default_settings.api_url_scale; oai_settings.api_url_scale = settings.api_url_scale ?? default_settings.api_url_scale;
@ -1891,6 +1895,7 @@ function loadOpenAISettings(data, settings) {
$('#use_ai21_tokenizer').prop('checked', oai_settings.use_ai21_tokenizer); $('#use_ai21_tokenizer').prop('checked', oai_settings.use_ai21_tokenizer);
$('#exclude_assistant').prop('checked', oai_settings.exclude_assistant); $('#exclude_assistant').prop('checked', oai_settings.exclude_assistant);
$('#scale-alt').prop('checked', oai_settings.use_alt_scale); $('#scale-alt').prop('checked', oai_settings.use_alt_scale);
$('#openrouter_use_fallback').prop('checked', oai_settings.openrouter_use_fallback);
if (settings.impersonation_prompt !== undefined) oai_settings.impersonation_prompt = settings.impersonation_prompt; if (settings.impersonation_prompt !== undefined) oai_settings.impersonation_prompt = settings.impersonation_prompt;
$('#impersonation_prompt_textarea').val(oai_settings.impersonation_prompt); $('#impersonation_prompt_textarea').val(oai_settings.impersonation_prompt);
@ -2055,6 +2060,7 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) {
claude_model: settings.claude_model, claude_model: settings.claude_model,
windowai_model: settings.windowai_model, windowai_model: settings.windowai_model,
openrouter_model: settings.openrouter_model, openrouter_model: settings.openrouter_model,
openrouter_use_fallback: settings.openrouter_use_fallback,
ai21_model: settings.ai21_model, ai21_model: settings.ai21_model,
temperature: settings.temp_openai, temperature: settings.temp_openai,
frequency_penalty: settings.freq_pen_openai, frequency_penalty: settings.freq_pen_openai,
@ -2413,6 +2419,7 @@ function onSettingsPresetChange() {
claude_model: ['#model_claude_select', 'claude_model', false], claude_model: ['#model_claude_select', 'claude_model', false],
windowai_model: ['#model_windowai_select', 'windowai_model', false], windowai_model: ['#model_windowai_select', 'windowai_model', false],
openrouter_model: ['#model_openrouter_select', 'openrouter_model', false], openrouter_model: ['#model_openrouter_select', 'openrouter_model', false],
openrouter_use_fallback: ['#openrouter_use_fallback', 'openrouter_use_fallback', true],
ai21_model: ['#model_ai21_select', 'ai21_model', false], ai21_model: ['#model_ai21_select', 'ai21_model', false],
openai_max_context: ['#openai_max_context', 'openai_max_context', false], openai_max_context: ['#openai_max_context', 'openai_max_context', false],
openai_max_tokens: ['#openai_max_tokens', 'openai_max_tokens', false], openai_max_tokens: ['#openai_max_tokens', 'openai_max_tokens', false],
@ -3125,6 +3132,11 @@ $(document).ready(async function () {
saveSettingsDebounced(); saveSettingsDebounced();
}); });
$('#openrouter_use_fallback').on('input', function () {
oai_settings.openrouter_use_fallback = !!$(this).prop('checked');
saveSettingsDebounced();
});
$("#api_button_openai").on("click", onConnectButtonClick); $("#api_button_openai").on("click", onConnectButtonClick);
$("#openai_reverse_proxy").on("input", onReverseProxyInput); $("#openai_reverse_proxy").on("input", onReverseProxyInput);
$("#model_openai_select").on("change", onModelChange); $("#model_openai_select").on("change", onModelChange);

View File

@ -152,6 +152,7 @@ let power_user = {
prefer_character_prompt: true, prefer_character_prompt: true,
prefer_character_jailbreak: true, prefer_character_jailbreak: true,
quick_continue: false, quick_continue: false,
continue_on_send: false,
trim_spaces: true, trim_spaces: true,
relaxed_api_urls: false, relaxed_api_urls: false,
@ -708,6 +709,7 @@ function loadPowerUserSettings(settings, data) {
$('#relaxed_api_urls').prop("checked", power_user.relaxed_api_urls); $('#relaxed_api_urls').prop("checked", power_user.relaxed_api_urls);
$('#trim_spaces').prop("checked", power_user.trim_spaces); $('#trim_spaces').prop("checked", power_user.trim_spaces);
$('#continue_on_send').prop("checked", power_user.continue_on_send);
$('#quick_continue').prop("checked", power_user.quick_continue); $('#quick_continue').prop("checked", power_user.quick_continue);
$('#mes_continue').css('display', power_user.quick_continue ? '' : 'none'); $('#mes_continue').css('display', power_user.quick_continue ? '' : 'none');
$('#auto_swipe').prop("checked", power_user.auto_swipe); $('#auto_swipe').prop("checked", power_user.auto_swipe);
@ -1968,6 +1970,12 @@ $(document).ready(() => {
saveSettingsDebounced(); saveSettingsDebounced();
}); });
$("#continue_on_send").on("input", function () {
const value = !!$(this).prop('checked');
power_user.continue_on_send = value;
saveSettingsDebounced();
});
$("#quick_continue").on("input", function () { $("#quick_continue").on("input", function () {
const value = !!$(this).prop('checked'); const value = !!$(this).prop('checked');
power_user.quick_continue = value; power_user.quick_continue = value;

View File

@ -1921,7 +1921,7 @@ app.post("/generate_novelai", jsonParser, async function (request, response_gene
"stop_sequences": request.body.stop_sequences, "stop_sequences": request.body.stop_sequences,
"bad_words_ids": badWordsList, "bad_words_ids": badWordsList,
"logit_bias_exp": logit_bias_exp, "logit_bias_exp": logit_bias_exp,
//generate_until_sentence = true; "generate_until_sentence": request.body.generate_until_sentence,
"use_cache": request.body.use_cache, "use_cache": request.body.use_cache,
"use_string": true, "use_string": true,
"return_full_text": request.body.return_full_text, "return_full_text": request.body.return_full_text,
@ -3479,6 +3479,10 @@ app.post("/generate_openai", jsonParser, function (request, response_generate_op
// OpenRouter needs to pass the referer: https://openrouter.ai/docs // OpenRouter needs to pass the referer: https://openrouter.ai/docs
headers = { 'HTTP-Referer': request.headers.referer }; headers = { 'HTTP-Referer': request.headers.referer };
bodyParams = { 'transforms': ["middle-out"] }; bodyParams = { 'transforms': ["middle-out"] };
if (request.body.use_fallback) {
bodyParams['route'] = 'fallback';
}
} }
if (!api_key_openai && !request.body.reverse_proxy) { if (!api_key_openai && !request.body.reverse_proxy) {