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_jailbreak": true,
"quick_continue": false,
"continue_on_send": false,
"trim_spaces": true,
"relaxed_api_urls": false,
"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>
</select>
</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>
<div>
<small>
@ -2816,6 +2827,12 @@
<input id="prefer_character_jailbreak" type="checkbox" />
<span data-i18n="Prefer Character Card Jailbreak">Prefer Char. JB</span>
</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">
<input id="quick_continue" type="checkbox" />
<span data-i18n="Press Send to continue">

View File

@ -1,8 +1,8 @@
{
"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",
"input_sequence": "USER: ",
"output_sequence": "ASSISTANT: ",
"input_sequence": "\nUSER: ",
"output_sequence": "\nASSISTANT: ",
"last_output_sequence": "",
"system_sequence": "BEGINNING OF CONVERSATION:",
"stop_sequence": "",

View File

@ -2,7 +2,7 @@
"compilerOptions": {
"checkJs": true,
"target": "ESNext",
"module": "commonjs",
"module": "ESNext",
"allowUmdGlobalAccess": 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';
if (!dryRun) {
@ -2641,7 +2645,10 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
console.debug('--setting Prompt string');
mesExmString = pinExmString ?? mesExamplesArray.slice(0, count_exm_add).join('');
mesSend[mesSend.length - 1] = modifyLastPromptLine(mesSend[mesSend.length - 1]);
if (mesSend.length) {
mesSend[mesSend.length - 1] = modifyLastPromptLine(mesSend[mesSend.length - 1]);
}
}
function modifyLastPromptLine(lastMesString) {
@ -3332,11 +3339,7 @@ function addChatsPreamble(mesSendString) {
}
function addChatsSeparator(mesSendString) {
if (main_api === 'novel') {
return '***\n' + mesSendString;
}
else if (power_user.context.chat_start) {
if (power_user.context.chat_start) {
return power_user.context.chat_start + '\n' + mesSendString;
}
@ -3803,6 +3806,10 @@ async function saveReply(type, getMessage, this_mes_is_name, title) {
type = 'normal';
}
if (chat.length && typeof chat[chat.length - 1]['extra'] !== 'object') {
chat[chat.length - 1]['extra'] = {};
}
let oldMessage = ''
const generationFinished = new Date();
const img = extractImageFromMessage(getMessage);
@ -4360,18 +4367,17 @@ function getFirstMessage() {
const message = {
name: name2,
is_user: false,
is_system: false,
is_name: true,
send_date: getMessageTimeStamp(),
mes: getRegexedString(firstMes, regex_placement.AI_OUTPUT),
extra: {},
};
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['swipes'] = message['mes'].concat(
alternateGreetings.map(
(greeting) => substituteParams(getRegexedString(greeting, regex_placement.AI_OUTPUT))
)
);
message['swipes'] = swipes;
message['swipe_info'] = [];
}
return message;

View File

@ -3,6 +3,55 @@ import { waitUntilCondition } from "./utils.js";
const storageKey = "language";
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) {
const overrideLanguage = localStorage.getItem("language");
var language = overrideLanguage || navigator.language || navigator.userLanguage;

View File

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

View File

@ -152,6 +152,7 @@ let power_user = {
prefer_character_prompt: true,
prefer_character_jailbreak: true,
quick_continue: false,
continue_on_send: false,
trim_spaces: true,
relaxed_api_urls: false,
@ -708,6 +709,7 @@ function loadPowerUserSettings(settings, data) {
$('#relaxed_api_urls').prop("checked", power_user.relaxed_api_urls);
$('#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);
$('#mes_continue').css('display', power_user.quick_continue ? '' : 'none');
$('#auto_swipe').prop("checked", power_user.auto_swipe);
@ -1968,6 +1970,12 @@ $(document).ready(() => {
saveSettingsDebounced();
});
$("#continue_on_send").on("input", function () {
const value = !!$(this).prop('checked');
power_user.continue_on_send = value;
saveSettingsDebounced();
});
$("#quick_continue").on("input", function () {
const value = !!$(this).prop('checked');
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,
"bad_words_ids": badWordsList,
"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_string": true,
"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
headers = { 'HTTP-Referer': request.headers.referer };
bodyParams = { 'transforms': ["middle-out"] };
if (request.body.use_fallback) {
bodyParams['route'] = 'fallback';
}
}
if (!api_key_openai && !request.body.reverse_proxy) {