From 157315cd6890c3738b95f3d164ffc477e3469425 Mon Sep 17 00:00:00 2001 From: NijikaMyWaifu <139055015+NijikaMyWaifu@users.noreply.github.com> Date: Fri, 23 May 2025 01:10:53 +0800 Subject: [PATCH] Add Vertex AI express mode support (#3977) * Add Vertex AI express mode support Split Google AI Studio and Vertex AI * Add support for Vertex AI, including updating default models and related settings, modifying frontend HTML to include Vertex AI options, and adjusting request processing logic in the backend API. * Log API name in the console * Merge sysprompt toggles back * Use Gemma tokenizers for Vertex and LearnLM * AI Studio parity updates * Add link to express mode doc. Also technically it's not a form * Split title * Use array includes * Add support for Google Vertex AI in image captioning feature * Specify caption API name, add to compression list --------- Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com> --- default/content/presets/openai/Default.json | 1 + public/index.html | 59 +++++++++++++---- public/script.js | 1 + public/scripts/RossAscends-mods.js | 1 + public/scripts/extensions/caption/index.js | 1 + .../scripts/extensions/caption/settings.html | 9 ++- public/scripts/extensions/shared.js | 10 ++- public/scripts/openai.js | 65 +++++++++++++++++-- public/scripts/reasoning.js | 1 + public/scripts/secrets.js | 2 + public/scripts/slash-commands.js | 1 + public/scripts/tokenizers.js | 4 ++ public/scripts/tool-calling.js | 1 + src/constants.js | 1 + src/endpoints/backends/chat-completions.js | 47 ++++++++++---- src/endpoints/google.js | 28 ++++++-- src/endpoints/secrets.js | 1 + src/endpoints/tokenizers.js | 2 +- 18 files changed, 193 insertions(+), 42 deletions(-) diff --git a/default/content/presets/openai/Default.json b/default/content/presets/openai/Default.json index 19660ea2d..efd39d5fb 100644 --- a/default/content/presets/openai/Default.json +++ b/default/content/presets/openai/Default.json @@ -15,6 +15,7 @@ "custom_exclude_body": "", "custom_include_headers": "", "google_model": "gemini-pro", + "vertexai_model": "gemini-2.0-flash-001", "temperature": 1, "frequency_penalty": 0, "presence_penalty": 0, diff --git a/public/index.html b/public/index.html index 87c789284..ff8d0ff23 100644 --- a/public/index.html +++ b/public/index.html @@ -691,7 +691,7 @@ -
+
Temperature
@@ -730,7 +730,7 @@
-
+
Top K
@@ -743,7 +743,7 @@
-
+
Top P
@@ -1969,7 +1969,7 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
Reverse Proxy
@@ -2843,7 +2844,7 @@
-
+
@@ -3209,6 +3210,38 @@
+
+

+ + Google Vertex AI API Key + + + (Express mode keys only) + +

+
+ + +
+
+ For privacy reasons, your API key will be hidden after you reload the page. +
+
+

Google Model

+ +
+

MistralAI API Key

diff --git a/public/script.js b/public/script.js index e25c2757f..c91bff5d7 100644 --- a/public/script.js +++ b/public/script.js @@ -5941,6 +5941,7 @@ function extractImageFromData(data, { mainApi = null, chatCompletionSource = nul switch (mainApi ?? main_api) { case 'openai': { switch (chatCompletionSource ?? oai_settings.chat_completion_source) { + case chat_completion_sources.VERTEXAI: case chat_completion_sources.MAKERSUITE: { const inlineData = data?.responseContent?.parts?.find(x => x.inlineData)?.inlineData; if (inlineData) { diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js index 403be2d85..b3e9e92e7 100644 --- a/public/scripts/RossAscends-mods.js +++ b/public/scripts/RossAscends-mods.js @@ -402,6 +402,7 @@ function RA_autoconnect(PrevApi) { || (secret_state[SECRET_KEYS.OPENROUTER] && oai_settings.chat_completion_source == chat_completion_sources.OPENROUTER) || (secret_state[SECRET_KEYS.AI21] && oai_settings.chat_completion_source == chat_completion_sources.AI21) || (secret_state[SECRET_KEYS.MAKERSUITE] && oai_settings.chat_completion_source == chat_completion_sources.MAKERSUITE) + || (secret_state[SECRET_KEYS.VERTEXAI] && oai_settings.chat_completion_source == chat_completion_sources.VERTEXAI) || (secret_state[SECRET_KEYS.MISTRALAI] && oai_settings.chat_completion_source == chat_completion_sources.MISTRALAI) || (secret_state[SECRET_KEYS.COHERE] && oai_settings.chat_completion_source == chat_completion_sources.COHERE) || (secret_state[SECRET_KEYS.PERPLEXITY] && oai_settings.chat_completion_source == chat_completion_sources.PERPLEXITY) diff --git a/public/scripts/extensions/caption/index.js b/public/scripts/extensions/caption/index.js index a9af62b2b..f29455af6 100644 --- a/public/scripts/extensions/caption/index.js +++ b/public/scripts/extensions/caption/index.js @@ -414,6 +414,7 @@ jQuery(async function () { 'openai': SECRET_KEYS.OPENAI, 'mistral': SECRET_KEYS.MISTRALAI, 'google': SECRET_KEYS.MAKERSUITE, + 'vertexai': SECRET_KEYS.VERTEXAI, 'anthropic': SECRET_KEYS.CLAUDE, }; diff --git a/public/scripts/extensions/caption/settings.html b/public/scripts/extensions/caption/settings.html index 31f7762a3..5b3102684 100644 --- a/public/scripts/extensions/caption/settings.html +++ b/public/scripts/extensions/caption/settings.html @@ -22,6 +22,7 @@ + @@ -111,6 +112,12 @@ + + + + + + @@ -170,7 +177,7 @@
The model must be downloaded first! Do it with the ollama pull command or click here.
-