Add fallback option for OpenRouter
This commit is contained in:
parent
b8531ee75c
commit
3b7ca5e379
|
@ -1779,6 +1779,17 @@
|
||||||
Max prompt cost: <span id="openrouter_max_prompt_cost">Unknown</span> <span id="openrouter_max_prompt_cost_currency">USD</span>
|
Max prompt cost: <span id="openrouter_max_prompt_cost">Unknown</span> <span id="openrouter_max_prompt_cost_currency">USD</span>
|
||||||
</small>
|
</small>
|
||||||
</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>
|
||||||
|
|
|
@ -135,6 +135,7 @@ const default_settings = {
|
||||||
claude_model: 'claude-instant-v1',
|
claude_model: 'claude-instant-v1',
|
||||||
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,
|
||||||
|
@ -173,6 +174,7 @@ const oai_settings = {
|
||||||
claude_model: 'claude-instant-v1',
|
claude_model: 'claude-instant-v1',
|
||||||
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,
|
||||||
|
@ -804,7 +806,8 @@ 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'] = parseFloat(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) {
|
||||||
|
@ -1130,6 +1133,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.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;
|
||||||
oai_settings.show_external_models = settings.show_external_models ?? default_settings.show_external_models;
|
oai_settings.show_external_models = settings.show_external_models ?? default_settings.show_external_models;
|
||||||
|
@ -1170,6 +1174,7 @@ function loadOpenAISettings(data, settings) {
|
||||||
$('#legacy_streaming').prop('checked', oai_settings.legacy_streaming);
|
$('#legacy_streaming').prop('checked', oai_settings.legacy_streaming);
|
||||||
$('#openai_show_external_models').prop('checked', oai_settings.show_external_models);
|
$('#openai_show_external_models').prop('checked', oai_settings.show_external_models);
|
||||||
$('#openai_external_category').toggle(oai_settings.show_external_models);
|
$('#openai_external_category').toggle(oai_settings.show_external_models);
|
||||||
|
$('#openrouter_use_fallback').prop('checked', oai_settings.openrouter_use_fallback);
|
||||||
|
|
||||||
if (settings.main_prompt !== undefined) oai_settings.main_prompt = settings.main_prompt;
|
if (settings.main_prompt !== undefined) oai_settings.main_prompt = settings.main_prompt;
|
||||||
if (settings.nsfw_prompt !== undefined) oai_settings.nsfw_prompt = settings.nsfw_prompt;
|
if (settings.nsfw_prompt !== undefined) oai_settings.nsfw_prompt = settings.nsfw_prompt;
|
||||||
|
@ -1323,6 +1328,7 @@ async function saveOpenAIPreset(name, settings) {
|
||||||
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,
|
||||||
temperature: settings.temp_openai,
|
temperature: settings.temp_openai,
|
||||||
frequency_penalty: settings.freq_pen_openai,
|
frequency_penalty: settings.freq_pen_openai,
|
||||||
presence_penalty: settings.pres_pen_openai,
|
presence_penalty: settings.pres_pen_openai,
|
||||||
|
@ -1663,6 +1669,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],
|
||||||
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],
|
||||||
nsfw_toggle: ['#nsfw_toggle', 'nsfw_toggle', true],
|
nsfw_toggle: ['#nsfw_toggle', 'nsfw_toggle', true],
|
||||||
|
@ -2244,6 +2251,11 @@ $(document).ready(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);
|
||||||
|
|
|
@ -3255,6 +3255,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) {
|
||||||
|
|
Loading…
Reference in New Issue