Add region option for vertex express mode to access more models (#4155)

* add region option for vertex express mode to access more models

* add region option for vertex express mode to access more models

* fix: Consolidate duplicate 'vertexai_region' input

* feat: add vertex region suggestion datalist & update caption endpoint to correctly handle region

* Adjust global projectless Vertex endpoint

* Remove pointless slash trim

* Skill issue

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
This commit is contained in:
Compass
2025-06-15 15:26:12 +03:00
committed by GitHub
co-authored by Cohee
parent 441dffc0da
commit 083f92b2b2
5 changed files with 93 additions and 24 deletions
+62 -21
View File
@@ -3257,19 +3257,38 @@
<!-- Express Mode Configuration -->
<div id="vertexai_express_config" class="vertexai-auth-section" data-mode="express">
<h4>
<span data-i18n="Google Vertex AI API Key">
Google Vertex AI API Key
<span data-i18n="Google Vertex AI Configuration">
Google Vertex AI Configuration
</span>
<a href="https://cloud.google.com/vertex-ai/generative-ai/docs/start/express-mode/overview" data-i18n="(Express mode)" target="_blank" rel="noopener noreferrer">
(Express mode)
</a>
</h4>
<div class="flex-container">
<input id="api_key_vertexai" name="api_key_vertexai" class="text_pole flex1" value="" type="text" autocomplete="off">
<div title="Manage API keys" data-i18n="[title]Manage API keys" class="menu_button fa-solid fa-key fa-fw manage-api-keys" data-key="api_key_vertexai"></div>
<!-- API Key -->
<div class="flex-container flexFlowColumn">
<label for="api_key_vertexai" data-i18n="API Key">API Key:</label>
<div class="flex-container">
<input id="api_key_vertexai" name="api_key_vertexai" class="text_pole flex1" value="" type="text" autocomplete="off">
<div title="Manage API keys" data-i18n="[title]Manage API keys" class="menu_button fa-solid fa-key fa-fw manage-api-keys" data-key="api_key_vertexai"></div>
</div>
<div data-for="api_key_vertexai" class="neutral_warning" data-i18n="For privacy reasons, your API key will be hidden after you click 'Connect'.">
For privacy reasons, your API key will be hidden after you click 'Connect'.
</div>
</div>
<div data-for="api_key_vertexai" class="neutral_warning" data-i18n="For privacy reasons, your API key will be hidden after you click 'Connect'.">
For privacy reasons, your API key will be hidden after you click 'Connect'.
<!-- Project ID -->
<div class="flex-container flexFlowColumn marginTop10">
<label for="vertexai_express_project_id">
<span data-i18n="Project ID">Project ID:</span>
</label>
<div class="flex-container">
<input id="vertexai_express_project_id" name="vertexai_express_project_id" class="text_pole flex1" value="" type="text" autocomplete="off" placeholder="Enter your Project ID">
</div>
<div class="toggle-description justifyLeft marginBot5">
<small data-i18n="Project ID is required when selecting regions other than the default (us-central1). You can find this in a model 404 error message.">
`Project ID` is only required when selecting regions other than the default (us-central1).<br>
You can find this in a model 404 error message.
</small>
</div>
</div>
</div>
@@ -3283,20 +3302,6 @@
<i class="fa-solid fa-circle-question"></i>
</a>
</h4>
<!-- Region -->
<div class="flex-container flexFlowColumn">
<label for="vertexai_region">
<span data-i18n="Region">
Region:
</span>
<a href="https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations" target="_blank" rel="noopener noreferrer" title="View available regions and models" data-i18n="[title]View available regions and models" class="notes-link">
<span class="fa-solid fa-circle-question note-link-span"></span>
</a>
</label>
<input id="vertexai_region" name="vertexai_region" class="text_pole flex1" value="us-central1" type="text" autocomplete="off" placeholder="e.g., global, us-central1, europe-west1, asia-northeast1">
</div>
<!-- Service Account JSON Content -->
<div class="flex-container flexFlowColumn">
<label for="vertexai_service_account_json" data-i18n="Service Account JSON Content">Service Account JSON Content:</label>
@@ -3316,12 +3321,48 @@
</div>
</div>
<!-- Region -->
<div class="flex-container flexFlowColumn">
<label for="vertexai_region">
<span data-i18n="Region">
Region:
</span>
<a href="https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations" target="_blank" rel="noopener noreferrer" title="View available regions and models" data-i18n="[title]View available regions and models" class="notes-link">
<span class="fa-solid fa-circle-question note-link-span"></span>
</a>
</label>
<input id="vertexai_region" name="vertexai_region" class="text_pole flex1" value="us-central1" type="text" autocomplete="off" placeholder="e.g., global, us-central1, europe-west1, asia-northeast1" list="vertexai_region_suggestions">
<datalist id="vertexai_region_suggestions">
<option value="global">global</option>
<option value="us-central1">us-central1</option>
<option value="us-east1">us-east1</option>
<option value="us-east4">us-east4</option>
<option value="us-west1">us-west1</option>
<option value="us-west2">us-west2</option>
<option value="us-west3">us-west3</option>
<option value="us-west4">us-west4</option>
<option value="europe-west1">europe-west1</option>
<option value="europe-west2">europe-west2</option>
<option value="europe-west3">europe-west3</option>
<option value="europe-west4">europe-west4</option>
<option value="europe-west6">europe-west6</option>
<option value="europe-central2">europe-central2</option>
<option value="asia-northeast1">asia-northeast1</option>
<option value="asia-northeast3">asia-northeast3</option>
<option value="asia-southeast1">asia-southeast1</option>
<option value="asia-south1">asia-south1</option>
<option value="australia-southeast1">australia-southeast1</option>
</datalist>
</div>
<!-- Model Selection -->
<div>
<h4 data-i18n="Google Model">Google Model</h4>
<select id="model_vertexai_select">
<!-- Express Mode Models -->
<optgroup id="vertexai_express_models" label="Express Mode Models" data-mode="express">
<option value="gemini-2.5-pro-preview-06-05">gemini-2.5-pro-preview-06-05 (global region, Project ID required)</option>
<option value="gemini-2.5-pro-preview-05-06">gemini-2.5-pro-preview-05-06</option>
<option value="gemini-2.5-pro-preview-03-25">gemini-2.5-pro-preview-03-25</option>
<option value="gemini-2.5-flash-preview-05-20">gemini-2.5-flash-preview-05-20</option>
+1
View File
@@ -60,6 +60,7 @@ export async function getMultimodalCaption(base64Img, prompt) {
if (extension_settings.caption.multimodal_api === 'vertexai') {
requestBody.vertexai_auth_mode = oai_settings.vertexai_auth_mode;
requestBody.vertexai_region = oai_settings.vertexai_region;
requestBody.vertexai_express_project_id = oai_settings.vertexai_express_project_id;
}
if (isOllama) {
+13
View File
@@ -240,6 +240,7 @@ const sensitiveFields = [
'custom_exclude_body',
'custom_include_headers',
'vertexai_region',
'vertexai_express_project_id',
];
/**
@@ -314,6 +315,7 @@ export const settingsToUpdate = {
use_makersuite_sysprompt: ['#use_makersuite_sysprompt', 'use_makersuite_sysprompt', true, false],
vertexai_auth_mode: ['#vertexai_auth_mode', 'vertexai_auth_mode', false, true],
vertexai_region: ['#vertexai_region', 'vertexai_region', false, true],
vertexai_express_project_id: ['#vertexai_express_project_id', 'vertexai_express_project_id', false, true],
use_alt_scale: ['#use_alt_scale', 'use_alt_scale', true, true],
squash_system_messages: ['#squash_system_messages', 'squash_system_messages', true, false],
image_inlining: ['#openai_image_inlining', 'image_inlining', true, false],
@@ -399,6 +401,7 @@ const default_settings = {
use_makersuite_sysprompt: true,
vertexai_auth_mode: 'express',
vertexai_region: 'us-central1',
vertexai_express_project_id: '',
use_alt_scale: false,
squash_system_messages: false,
image_inlining: false,
@@ -487,6 +490,7 @@ const oai_settings = {
use_makersuite_sysprompt: true,
vertexai_auth_mode: 'express',
vertexai_region: 'us-central1',
vertexai_express_project_id: '',
use_alt_scale: false,
squash_system_messages: false,
image_inlining: false,
@@ -2319,6 +2323,7 @@ async function sendOpenAIRequest(type, messages, signal) {
if (isVertexAI) {
generate_data['vertexai_auth_mode'] = oai_settings.vertexai_auth_mode;
generate_data['vertexai_region'] = oai_settings.vertexai_region;
generate_data['vertexai_express_project_id'] = oai_settings.vertexai_express_project_id;
}
}
@@ -3552,6 +3557,7 @@ function loadOpenAISettings(data, settings) {
oai_settings.inline_image_quality = settings.inline_image_quality ?? default_settings.inline_image_quality;
oai_settings.video_inlining = settings.video_inlining ?? default_settings.video_inlining;
oai_settings.bypass_status_check = settings.bypass_status_check ?? default_settings.bypass_status_check;
oai_settings.vertexai_express_project_id = settings.vertexai_express_project_id ?? default_settings.vertexai_express_project_id;
oai_settings.show_thoughts = settings.show_thoughts ?? default_settings.show_thoughts;
oai_settings.reasoning_effort = settings.reasoning_effort ?? default_settings.reasoning_effort;
oai_settings.enable_web_search = settings.enable_web_search ?? default_settings.enable_web_search;
@@ -3589,6 +3595,7 @@ function loadOpenAISettings(data, settings) {
if (settings.use_makersuite_sysprompt !== undefined) oai_settings.use_makersuite_sysprompt = !!settings.use_makersuite_sysprompt;
if (settings.vertexai_auth_mode !== undefined) oai_settings.vertexai_auth_mode = settings.vertexai_auth_mode;
if (settings.vertexai_region !== undefined) oai_settings.vertexai_region = settings.vertexai_region;
if (settings.vertexai_express_project_id !== undefined) oai_settings.vertexai_express_project_id = settings.vertexai_express_project_id;
if (settings.use_alt_scale !== undefined) { oai_settings.use_alt_scale = !!settings.use_alt_scale; updateScaleForm(); }
$('#stream_toggle').prop('checked', oai_settings.stream_openai);
$('#api_url_scale').val(oai_settings.api_url_scale);
@@ -3650,6 +3657,7 @@ function loadOpenAISettings(data, settings) {
$('#use_makersuite_sysprompt').prop('checked', oai_settings.use_makersuite_sysprompt);
$('#vertexai_auth_mode').val(oai_settings.vertexai_auth_mode);
$('#vertexai_region').val(oai_settings.vertexai_region);
$('#vertexai_express_project_id').val(oai_settings.vertexai_express_project_id);
// Don't display Service Account JSON in textarea - it's stored in backend secrets
$('#vertexai_service_account_json').val('');
updateVertexAIServiceAccountStatus();
@@ -3980,6 +3988,7 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) {
use_makersuite_sysprompt: settings.use_makersuite_sysprompt,
vertexai_auth_mode: settings.vertexai_auth_mode,
vertexai_region: settings.vertexai_region,
vertexai_express_project_id: settings.vertexai_express_project_id,
use_alt_scale: settings.use_alt_scale,
squash_system_messages: settings.squash_system_messages,
image_inlining: settings.image_inlining,
@@ -6378,6 +6387,10 @@ export function initOpenAI() {
oai_settings.vertexai_region = String($(this).val());
saveSettingsDebounced();
});
$('#vertexai_express_project_id').on('input', function () {
oai_settings.vertexai_express_project_id = String($(this).val());
saveSettingsDebounced();
});
$('#vertexai_service_account_json').on('input', onVertexAIServiceAccountJsonChange);
$('#vertexai_validate_service_account').on('click', onVertexAIValidateServiceAccount);
$('#vertexai_clear_service_account').on('click', onVertexAIClearServiceAccount);
+8 -1
View File
@@ -493,7 +493,14 @@ async function sendMakerSuiteRequest(request, response) {
if (authType === 'express') {
// For Express mode (API key authentication), use the key parameter
const keyParam = authHeader.replace('Bearer ', '');
url = `${apiUrl.toString().replace(/\/$/, '')}/v1/publishers/google/models/${model}:${responseType}?key=${keyParam}${stream ? '&alt=sse' : ''}`;
const region = request.body.vertexai_region || 'us-central1';
const projectId = request.body.vertexai_express_project_id;
const baseUrl = region === 'global'
? 'https://aiplatform.googleapis.com'
: `https://${region}-aiplatform.googleapis.com`;
url = projectId
? `https://aiplatform.googleapis.com/v1/projects/${projectId}/locations/${region}/publishers/google/models/${model}:generateContent?key=${keyParam}${stream ? '&alt=sse' : ''}`
: `${baseUrl}/v1/publishers/google/models/${model}:generateContent?key=${keyParam}${stream ? '&alt=sse' : ''}`;
} else if (authType === 'full') {
// For Full mode (service account authentication), use project-specific URL
// Get project ID from Service Account JSON
+9 -2
View File
@@ -104,6 +104,7 @@ export async function getAccessToken(jwtToken) {
throw new Error(`Failed to get access token: ${error}`);
}
/** @type {any} */
const data = await response.json();
return data.access_token;
}
@@ -149,8 +150,14 @@ router.post('/caption-image', async (request, response) => {
if (authType === 'express') {
// Express mode: use API key parameter
const keyParam = authHeader.replace('Bearer ', '');
const apiUrl = trimTrailingSlash(request.body.reverse_proxy || API_VERTEX_AI);
url = `${apiUrl}/v1/publishers/google/models/${model}:generateContent?key=${keyParam}`;
const region = request.body.vertexai_region || 'us-central1';
const projectId = request.body.vertexai_express_project_id;
const baseUrl = region === 'global'
? 'https://aiplatform.googleapis.com'
: `https://${region}-aiplatform.googleapis.com`;
url = projectId
? `https://aiplatform.googleapis.com/v1/projects/${projectId}/locations/${region}/publishers/google/models/${model}:generateContent?key=${keyParam}`
: `${baseUrl}/v1/publishers/google/models/${model}:generateContent?key=${keyParam}`;
} else if (authType === 'full') {
// Full mode: use project-specific URL with Authorization header
// Get project ID from Service Account JSON