Expose "Allow fallback providers" for OpenRouter

This commit is contained in:
Cohee 2024-07-19 23:34:16 +03:00
parent d8809238a7
commit 5f2a73ac9f
6 changed files with 33 additions and 16 deletions

View File

@ -2091,6 +2091,10 @@
<h4 data-i18n="Model Providers">Model Providers</h4>
<select id="openrouter_providers_text" class="openrouter_providers" multiple>
</select>
<label class="checkbox_label" for="openrouter_allow_fallbacks_textgenerationwebui" title="Automatically chooses an alternative provider if chosen providers can't serve your request.">
<input id="openrouter_allow_fallbacks_textgenerationwebui" type="checkbox" />
<span data-i18n="Allow fallback providers">Allow fallback providers</span>
</label>
</div>
</div>
<div data-tg-type="infermaticai" class="flex-container flexFlowColumn">
@ -2668,11 +2672,10 @@
<option data-i18n="-- Connect to the API --">-- Connect to the API --</option>
</select>
</div>
<div>
<h4 data-i18n="Model Providers">Model Providers</h4>
<select id="openrouter_providers_chat" class="openrouter_providers" multiple>
</select>
</div>
<label for="openrouter_use_fallback" class="checkbox_label marginTopBot5" data-i18n="[title]Allow fallback routes Description" title="Automatically chooses an alternative model if the chosen model can't serve your request.">
<input id="openrouter_use_fallback" type="checkbox" />
<span data-i18n="Allow fallback models">Allow fallback models</span>
</label>
<div class="marginTopBot5">
<div class="inline-drawer wide100p">
<div class="inline-drawer-toggle inline-drawer-header">
@ -2703,16 +2706,14 @@
</div>
</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>
<div>
<h4 data-i18n="Model Providers">Model Providers</h4>
<select id="openrouter_providers_chat" class="openrouter_providers" multiple>
</select>
<label class="checkbox_label marginTopBot5" for="openrouter_allow_fallbacks" title="Automatically chooses an alternative provider if chosen providers can't serve your request.">
<input id="openrouter_allow_fallbacks" type="checkbox" />
<span data-i18n="Allow fallback providers">Allow fallback providers</span>
</label>
<div class="toggle-description justifyLeft wide100p">
<span data-i18n="Allow fallback routes Description">
Automatically chooses an alternative model if the chosen model can't serve your request.
</span>
</div>
</div>
<div class="marginTopBot5">
<label for="openrouter_force_instruct" class="checkbox_label">

View File

@ -278,6 +278,7 @@ const default_settings = {
openrouter_group_models: false,
openrouter_sort_models: 'alphabetically',
openrouter_providers: [],
openrouter_allow_fallbacks: true,
jailbreak_system: false,
reverse_proxy: '',
chat_completion_source: chat_completion_sources.OPENAI,
@ -357,6 +358,7 @@ const oai_settings = {
openrouter_group_models: false,
openrouter_sort_models: 'alphabetically',
openrouter_providers: [],
openrouter_allow_fallbacks: true,
jailbreak_system: false,
reverse_proxy: '',
chat_completion_source: chat_completion_sources.OPENAI,
@ -1881,6 +1883,7 @@ async function sendOpenAIRequest(type, messages, signal) {
generate_data['top_a'] = Number(oai_settings.top_a_openai);
generate_data['use_fallback'] = oai_settings.openrouter_use_fallback;
generate_data['provider'] = oai_settings.openrouter_providers;
generate_data['allow_fallbacks'] = oai_settings.openrouter_allow_fallbacks;
if (isTextCompletion) {
generate_data['stop'] = getStoppingStrings(isImpersonate, isContinue);
@ -3001,6 +3004,7 @@ function loadOpenAISettings(data, settings) {
oai_settings.openrouter_sort_models = settings.openrouter_sort_models ?? default_settings.openrouter_sort_models;
oai_settings.openrouter_use_fallback = settings.openrouter_use_fallback ?? default_settings.openrouter_use_fallback;
oai_settings.openrouter_force_instruct = settings.openrouter_force_instruct ?? default_settings.openrouter_force_instruct;
oai_settings.openrouter_allow_fallbacks = settings.openrouter_allow_fallbacks ?? default_settings.openrouter_allow_fallbacks;
oai_settings.ai21_model = settings.ai21_model ?? default_settings.ai21_model;
oai_settings.mistralai_model = settings.mistralai_model ?? default_settings.mistralai_model;
oai_settings.cohere_model = settings.cohere_model ?? default_settings.cohere_model;
@ -3105,6 +3109,7 @@ function loadOpenAISettings(data, settings) {
$('#openrouter_use_fallback').prop('checked', oai_settings.openrouter_use_fallback);
$('#openrouter_force_instruct').prop('checked', oai_settings.openrouter_force_instruct);
$('#openrouter_group_models').prop('checked', oai_settings.openrouter_group_models);
$('#openrouter_allow_fallbacks').prop('checked', oai_settings.openrouter_allow_fallbacks);
$('#openrouter_providers_chat').val(oai_settings.openrouter_providers).trigger('change');
$('#squash_system_messages').prop('checked', oai_settings.squash_system_messages);
$('#continue_prefill').prop('checked', oai_settings.continue_prefill);
@ -3334,6 +3339,7 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) {
openrouter_group_models: settings.openrouter_group_models,
openrouter_sort_models: settings.openrouter_sort_models,
openrouter_providers: settings.openrouter_providers,
openrouter_allow_fallbacks: settings.openrouter_allow_fallbacks,
ai21_model: settings.ai21_model,
mistralai_model: settings.mistralai_model,
cohere_model: settings.cohere_model,
@ -3770,6 +3776,7 @@ function onSettingsPresetChange() {
openrouter_group_models: ['#openrouter_group_models', 'openrouter_group_models', false],
openrouter_sort_models: ['#openrouter_sort_models', 'openrouter_sort_models', false],
openrouter_providers: ['#openrouter_providers_chat', 'openrouter_providers', false],
openrouter_allow_fallbacks: ['#openrouter_allow_fallbacks', 'openrouter_allow_fallbacks', true],
ai21_model: ['#model_ai21_select', 'ai21_model', false],
mistralai_model: ['#model_mistralai_select', 'mistralai_model', false],
cohere_model: ['#model_cohere_select', 'cohere_model', false],
@ -5102,6 +5109,11 @@ $(document).ready(async function () {
saveSettingsDebounced();
});
$('#openrouter_allow_fallbacks').on('input', function () {
oai_settings.openrouter_allow_fallbacks = !!$(this).prop('checked');
saveSettingsDebounced();
});
$('#squash_system_messages').on('input', function () {
oai_settings.squash_system_messages = !!$(this).prop('checked');
saveSettingsDebounced();

View File

@ -332,6 +332,7 @@ class PresetManager {
'featherless_model',
'max_tokens_second',
'openrouter_providers',
'openrouter_allow_fallbacks',
];
const settings = Object.assign({}, getSettingsByApiId(this.apiId));

View File

@ -187,6 +187,7 @@ const settings = {
server_urls: {},
custom_model: '',
bypass_status_check: false,
openrouter_allow_fallbacks: true,
};
export let textgenerationwebui_banned_in_macros = [];
@ -261,6 +262,7 @@ export const setting_names = [
'logit_bias',
'custom_model',
'bypass_status_check',
'openrouter_allow_fallbacks',
];
const DYNATEMP_BLOCK = document.getElementById('dynatemp_block_ooba');
@ -1172,6 +1174,7 @@ export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate,
if (settings.type === OPENROUTER) {
params.provider = settings.openrouter_providers;
params.allow_fallbacks = settings.openrouter_allow_fallbacks;
}
if (settings.type === KOBOLDCPP) {

View File

@ -879,7 +879,7 @@ router.post('/generate', jsonParser, function (request, response) {
if (Array.isArray(request.body.provider) && request.body.provider.length > 0) {
bodyParams['provider'] = {
allow_fallbacks: true,
allow_fallbacks: request.body.allow_fallbacks ?? true,
order: request.body.provider ?? [],
};
}

View File

@ -309,7 +309,7 @@ router.post('/generate', jsonParser, async function (request, response) {
if (request.body.api_type === TEXTGEN_TYPES.OPENROUTER) {
if (Array.isArray(request.body.provider) && request.body.provider.length > 0) {
request.body.provider = {
allow_fallbacks: true,
allow_fallbacks: request.body.allow_fallbacks ?? true,
order: request.body.provider,
};
} else {