From c53e496687521e5c5b5e6303d0dd2e7aa18ab5f1 Mon Sep 17 00:00:00 2001 From: Cohee Date: Tue, 11 Jul 2023 15:46:41 +0300 Subject: [PATCH] Split OpenRouter and Window AI sources --- public/index.html | 22 +-- public/scripts/RossAscends-mods.js | 4 +- public/scripts/openai.js | 218 +++++++++++++++++++---------- 3 files changed, 161 insertions(+), 83 deletions(-) diff --git a/public/index.html b/public/index.html index 27bbd3108..b1f327044 100644 --- a/public/index.html +++ b/public/index.html @@ -564,7 +564,7 @@ -
+
Temperature
@@ -1340,7 +1340,7 @@ - +
@@ -1497,7 +1497,8 @@ @@ -1612,6 +1613,15 @@
+ + +
+
+

OpenRouter Model

+ +

OpenRouter API Key

@@ -1625,10 +1635,6 @@
For privacy reasons, your API key will be hidden after you reload the page.
-
@@ -1648,7 +1654,7 @@
- +
diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js index a892d6dd0..952c51613 100644 --- a/public/scripts/RossAscends-mods.js +++ b/public/scripts/RossAscends-mods.js @@ -406,8 +406,8 @@ function RA_autoconnect(PrevApi) { if ( (secret_state[SECRET_KEYS.OPENAI] && oai_settings.chat_completion_source == chat_completion_sources.OPENAI) || (secret_state[SECRET_KEYS.CLAUDE] && oai_settings.chat_completion_source == chat_completion_sources.CLAUDE) || (secret_state[SECRET_KEYS.SCALE] && oai_settings.chat_completion_source == chat_completion_sources.SCALE) - || (oai_settings.chat_completion_source == chat_completion_sources.WINDOWAI && !oai_settings.use_openrouter) - || (secret_state[SECRET_KEYS.OPENROUTER] && oai_settings.chat_completion_source == chat_completion_sources.WINDOWAI && oai_settings.use_openrouter) + || (oai_settings.chat_completion_source == chat_completion_sources.WINDOWAI) + || (secret_state[SECRET_KEYS.OPENROUTER] && oai_settings.chat_completion_source == chat_completion_sources.OPENROUTER) ) { $("#api_button_openai").click(); } diff --git a/public/scripts/openai.js b/public/scripts/openai.js index 151d85cf6..038f50c92 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -96,6 +96,7 @@ const oai_max_temp = 2.0; const claude_max_temp = 1.0; let biasCache = undefined; +let model_list = []; const tokenCache = {}; export const chat_completion_sources = { @@ -103,6 +104,7 @@ export const chat_completion_sources = { WINDOWAI: 'windowai', CLAUDE: 'claude', SCALE: 'scale', + OPENROUTER: 'openrouter', }; const default_settings = { @@ -131,12 +133,12 @@ const default_settings = { openai_model: 'gpt-3.5-turbo', claude_model: 'claude-instant-v1', windowai_model: '', + openrouter_model: 'openai/gpt-3.5-turbo', jailbreak_system: false, reverse_proxy: '', legacy_streaming: false, chat_completion_source: chat_completion_sources.OPENAI, max_context_unlocked: false, - use_openrouter: false, api_url_scale: '', }; @@ -166,12 +168,12 @@ const oai_settings = { openai_model: 'gpt-3.5-turbo', claude_model: 'claude-instant-v1', windowai_model: '', + openrouter_model: 'openai/gpt-3.5-turbo', jailbreak_system: false, reverse_proxy: '', legacy_streaming: false, chat_completion_source: chat_completion_sources.OPENAI, max_context_unlocked: false, - use_openrouter: false, api_url_scale: '', }; @@ -675,11 +677,35 @@ function getChatCompletionModel() { return oai_settings.windowai_model; case chat_completion_sources.SCALE: return ''; + case chat_completion_sources.OPENROUTER: + return oai_settings.openrouter_model; default: throw new Error(`Unknown chat completion source: ${oai_settings.chat_completion_source}`); } } +function saveModelList(data) { + model_list = data.map((model) => ({ id: model.id, context_length: model.context_length })); + + if (oai_settings.chat_completion_source == chat_completion_sources.OPENROUTER) { + $('#model_openrouter_select').empty(); + model_list.forEach((model) => { + const selected = model.id == oai_settings.openrouter_model; + $('#model_openrouter_select').append( + $('