OpenAI Comp services shorcut added. see #378
This commit is contained in:
parent
07957d62c7
commit
d419373515
4 changed files with 118 additions and 1 deletions
|
|
@ -1506,5 +1506,17 @@
|
||||||
"content": "$1"
|
"content": "$1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"prefs_OpenAIComp_AvailableServices": {
|
||||||
|
"message": "Available Services",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"prefs_OpenAIComp_AvailableServices_Info": {
|
||||||
|
"message": "Choose one of the services available for the OpenAI Compatible API or insert one manually.",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"Custom": {
|
||||||
|
"message": "Custom",
|
||||||
|
"description": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
49
js/api/openai_comp_configs.js
Normal file
49
js/api/openai_comp_configs.js
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* ThunderAI [https://micz.it/thunderbird-addon-thunderai/]
|
||||||
|
* Copyright (C) 2024 - 2025 Mic (m@micz.it)
|
||||||
|
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Config properties for OpenAI API Comp
|
||||||
|
id: <unique ID>
|
||||||
|
name: <AI services Name>
|
||||||
|
chat_name: <AI Name used in the API webchat>
|
||||||
|
host: <API endpoint>
|
||||||
|
use_v1: <true/false> (keep "v1" path segment)
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const openAICompConfigs = [
|
||||||
|
{
|
||||||
|
id: 'custom',
|
||||||
|
name: browser.i18n.getMessage('Custom'),
|
||||||
|
chat_name: 'OpenAI Comp API',
|
||||||
|
host: '',
|
||||||
|
use_v1: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'grok',
|
||||||
|
name: 'Grok AI API',
|
||||||
|
chat_name: 'Grok AI',
|
||||||
|
host: 'https://api.x.ai',
|
||||||
|
use_v1: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'mistral',
|
||||||
|
name: 'Mistral AI API',
|
||||||
|
chat_name: 'Mistral AI',
|
||||||
|
host: 'https://api.mistral.ai',
|
||||||
|
use_v1: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
@ -314,6 +314,18 @@
|
||||||
</label>
|
</label>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr class="conntype_openai_comp_api">
|
||||||
|
<td><label>
|
||||||
|
<span class="opt_title">__MSG_prefs_OpenAIComp_AvailableServices__</span>
|
||||||
|
</label></td>
|
||||||
|
<td>
|
||||||
|
<label>
|
||||||
|
<select id="openai_comp_services_shortcut">
|
||||||
|
</select>
|
||||||
|
<br>__MSG_prefs_OpenAIComp_AvailableServices_Info__
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr class="conntype_openai_comp_api">
|
<tr class="conntype_openai_comp_api">
|
||||||
<td><label>
|
<td><label>
|
||||||
<span class="opt_title">__MSG_prefs_API_Host__</span>
|
<span class="opt_title">__MSG_prefs_API_Host__</span>
|
||||||
|
|
@ -322,7 +334,7 @@
|
||||||
<td>
|
<td>
|
||||||
<label>
|
<label>
|
||||||
<input type="text" id="openai_comp_host" name="openai_comp_host" class="option-input" />
|
<input type="text" id="openai_comp_host" name="openai_comp_host" class="option-input" />
|
||||||
<br><i class="small_info">__MSG_prefs_OptionText_openai_comp_info_remote__</i>
|
<br>__MSG_prefs_OptionText_openai_comp_info_remote__
|
||||||
</label>
|
</label>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import { OpenAIComp } from '../js/api/openai_comp.js'
|
||||||
import { GoogleGemini } from '../js/api/google_gemini.js';
|
import { GoogleGemini } from '../js/api/google_gemini.js';
|
||||||
import { Anthropic } from '../js/api/anthropic.js';
|
import { Anthropic } from '../js/api/anthropic.js';
|
||||||
import { ChatGPTWeb_models, checkSparksPresence, isThunderbird128OrGreater, openTab, sanitizeChatGPTModelData, sanitizeChatGPTWebCustomData, validateCustomData_ChatGPTWeb, getChatGPTWebModelsList_HTML } from '../js/mzta-utils.js';
|
import { ChatGPTWeb_models, checkSparksPresence, isThunderbird128OrGreater, openTab, sanitizeChatGPTModelData, sanitizeChatGPTWebCustomData, validateCustomData_ChatGPTWeb, getChatGPTWebModelsList_HTML } from '../js/mzta-utils.js';
|
||||||
|
import { openAICompConfigs } from '../js/api/openai_comp_configs.js';
|
||||||
|
|
||||||
let taLog = new taLogger("mzta-options",true);
|
let taLog = new taLogger("mzta-options",true);
|
||||||
let _isThunderbird128OrGreater = true;
|
let _isThunderbird128OrGreater = true;
|
||||||
|
|
@ -373,6 +374,21 @@ async function disable_GetCalendarEvent(){
|
||||||
no_sparks_text.style.display = (is_spark_present == -1) ? 'inline' : 'none';
|
no_sparks_text.style.display = (is_spark_present == -1) ? 'inline' : 'none';
|
||||||
wrong_sparks_text.style.display = (is_spark_present == 0) ? 'inline' : 'none';
|
wrong_sparks_text.style.display = (is_spark_present == 0) ? 'inline' : 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadOpenAICompConfigs(){
|
||||||
|
let select_openai_comp_model = document.getElementById('openai_comp_services_shortcut');
|
||||||
|
openAICompConfigs.forEach(config => {
|
||||||
|
const option = document.createElement('option');
|
||||||
|
option.value = config.id;
|
||||||
|
option.text = config.name;
|
||||||
|
select_openai_comp_model.appendChild(option);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetOpenAICompConfigs(){
|
||||||
|
let select_openai_comp_model = document.getElementById('openai_comp_services_shortcut');
|
||||||
|
select_openai_comp_model.value = 'custom';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', async () => {
|
document.addEventListener('DOMContentLoaded', async () => {
|
||||||
|
|
@ -518,6 +534,10 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
document.getElementById("chatgpt_web_custom_gpt").addEventListener("input", validateCustomData_ChatGPTWeb);
|
document.getElementById("chatgpt_web_custom_gpt").addEventListener("input", validateCustomData_ChatGPTWeb);
|
||||||
document.getElementById("anthropic_api_key").addEventListener("change", warn_Anthropic_APIKeyEmpty);
|
document.getElementById("anthropic_api_key").addEventListener("change", warn_Anthropic_APIKeyEmpty);
|
||||||
document.getElementById("anthropic_version").addEventListener("change", warn_Anthropic_VersionEmpty);
|
document.getElementById("anthropic_version").addEventListener("change", warn_Anthropic_VersionEmpty);
|
||||||
|
document.getElementById("openai_comp_host").addEventListener("input", resetOpenAICompConfigs);
|
||||||
|
document.getElementById("openai_comp_chat_name").addEventListener("input", resetOpenAICompConfigs);
|
||||||
|
document.getElementById("openai_comp_use_v1").addEventListener("input", resetOpenAICompConfigs);
|
||||||
|
|
||||||
|
|
||||||
let prefs = await browser.storage.sync.get({chatgpt_web_model: '', chatgpt_model: '', ollama_model: '', openai_comp_model: '', google_gemini_model: '', anthropic_model: '', anthropic_version: '', chatgpt_win_height: 0, chatgpt_win_width: 0 });
|
let prefs = await browser.storage.sync.get({chatgpt_web_model: '', chatgpt_model: '', ollama_model: '', openai_comp_model: '', google_gemini_model: '', anthropic_model: '', anthropic_version: '', chatgpt_win_height: 0, chatgpt_win_width: 0 });
|
||||||
|
|
||||||
|
|
@ -827,4 +847,28 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
loadOpenAICompConfigs();
|
||||||
|
let select_openai_comp_services_shortcut = document.getElementById('openai_comp_services_shortcut');
|
||||||
|
select_openai_comp_services_shortcut.addEventListener("change", () => {
|
||||||
|
let selectedOption = select_openai_comp_services_shortcut.options[select_openai_comp_services_shortcut.selectedIndex];
|
||||||
|
const config = openAICompConfigs.find(cfg => cfg.id === selectedOption.value);
|
||||||
|
if (config) {
|
||||||
|
document.getElementById('openai_comp_host').value = config.host || '';
|
||||||
|
// Clear all options from the select except the first (placeholder) one
|
||||||
|
const openaiCompModelSelect = document.getElementById('openai_comp_model');
|
||||||
|
openaiCompModelSelect.value = '';
|
||||||
|
while (openaiCompModelSelect.options.length > 0) {
|
||||||
|
openaiCompModelSelect.remove(0);
|
||||||
|
}
|
||||||
|
document.getElementById('openai_comp_use_v1').checked = !!config.use_v1;
|
||||||
|
document.getElementById('openai_comp_chat_name').value = config.chat_name || '';
|
||||||
|
// Trigger change events if needed
|
||||||
|
document.getElementById('openai_comp_host').dispatchEvent(new Event('change', { bubbles: true }));
|
||||||
|
document.getElementById('openai_comp_model').dispatchEvent(new Event('change', { bubbles: true }));
|
||||||
|
document.getElementById('openai_comp_use_v1').dispatchEvent(new Event('change', { bubbles: true }));
|
||||||
|
document.getElementById('openai_comp_chat_name').dispatchEvent(new Event('change', { bubbles: true }));
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
}, { once: true });
|
}, { once: true });
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue