refining how to handle specific api settings. see #102
This commit is contained in:
parent
01142fb582
commit
97b016ab63
7 changed files with 61 additions and 19 deletions
|
|
@ -23,6 +23,7 @@
|
||||||
import { prefs_default, integration_options_config } from '../options/mzta-options-default.js';
|
import { prefs_default, integration_options_config } from '../options/mzta-options-default.js';
|
||||||
import { placeholdersUtils } from '../js/mzta-placeholders.js';
|
import { placeholdersUtils } from '../js/mzta-placeholders.js';
|
||||||
import { getAPIsInitMessageString, convertNewlinesToBr } from '../js/mzta-utils.js';
|
import { getAPIsInitMessageString, convertNewlinesToBr } from '../js/mzta-utils.js';
|
||||||
|
import { loadPrompt } from '../js/mzta-prompts.js';
|
||||||
|
|
||||||
// Get the LLM to be used
|
// Get the LLM to be used
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
|
@ -82,6 +83,22 @@ if (worker) {
|
||||||
|
|
||||||
let prefs_api = await browser.storage.sync.get(prefsToGet);
|
let prefs_api = await browser.storage.sync.get(prefsToGet);
|
||||||
|
|
||||||
|
if (prompt_id) {
|
||||||
|
try {
|
||||||
|
const prompt = await loadPrompt(prompt_id);
|
||||||
|
if (prompt && prompt.api_type === llm) {
|
||||||
|
for (const key in options_config) {
|
||||||
|
const prefKey = `${integration_prefix}_${key}`;
|
||||||
|
if (prompt[prefKey] !== undefined) {
|
||||||
|
prefs_api[prefKey] = prompt[prefKey];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("[ThunderAI] Error loading prompt settings:", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let i18nStrings = {};
|
let i18nStrings = {};
|
||||||
const i18n_msg_key = integration === 'openai_comp' ? 'OpenAIComp_api_request_failed' : `${integration}_api_request_failed`;
|
const i18n_msg_key = integration === 'openai_comp' ? 'OpenAIComp_api_request_failed' : `${integration}_api_request_failed`;
|
||||||
i18nStrings[i18n_msg_key] = browser.i18n.getMessage(i18n_msg_key);
|
i18nStrings[i18n_msg_key] = browser.i18n.getMessage(i18n_msg_key);
|
||||||
|
|
|
||||||
|
|
@ -440,7 +440,6 @@ async function getDefaultPrompts_withProps() {
|
||||||
prompt.chatgpt_web_project = prefs._default_prompts_properties[prompt.id].chatgpt_web_project;
|
prompt.chatgpt_web_project = prefs._default_prompts_properties[prompt.id].chatgpt_web_project;
|
||||||
prompt.chatgpt_web_custom_gpt = (prefs._default_prompts_properties[prompt.id]?.chatgpt_web_custom_gpt || '').trim();
|
prompt.chatgpt_web_custom_gpt = (prefs._default_prompts_properties[prompt.id]?.chatgpt_web_custom_gpt || '').trim();
|
||||||
prompt.api_type = (prefs._default_prompts_properties[prompt.id]?.api_type || '').trim();
|
prompt.api_type = (prefs._default_prompts_properties[prompt.id]?.api_type || '').trim();
|
||||||
prompt.api_model = (prefs._default_prompts_properties[prompt.id]?.api_model || '').trim();
|
|
||||||
}else{
|
}else{
|
||||||
prompt.position_display = pos;
|
prompt.position_display = pos;
|
||||||
prompt.position_compose = pos;
|
prompt.position_compose = pos;
|
||||||
|
|
@ -475,9 +474,6 @@ async function getCustomPrompts() {
|
||||||
if(prompt.api_type === undefined){
|
if(prompt.api_type === undefined){
|
||||||
prompt.api_type = "";
|
prompt.api_type = "";
|
||||||
}
|
}
|
||||||
if(prompt.api_model === undefined){
|
|
||||||
prompt.api_model = "";
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return prefs._custom_prompt;
|
return prefs._custom_prompt;
|
||||||
}
|
}
|
||||||
|
|
@ -495,7 +491,6 @@ export async function setDefaultPromptsProperties(prompts) {
|
||||||
chatgpt_web_project: (prompt.chatgpt_web_project === undefined || prompt.chatgpt_web_project === "undefined") ? "" : prompt.chatgpt_web_project,
|
chatgpt_web_project: (prompt.chatgpt_web_project === undefined || prompt.chatgpt_web_project === "undefined") ? "" : prompt.chatgpt_web_project,
|
||||||
chatgpt_web_custom_gpt: (prompt.chatgpt_web_custom_gpt === undefined || prompt.chatgpt_web_custom_gpt === "undefined") ? "" : prompt.chatgpt_web_custom_gpt,
|
chatgpt_web_custom_gpt: (prompt.chatgpt_web_custom_gpt === undefined || prompt.chatgpt_web_custom_gpt === "undefined") ? "" : prompt.chatgpt_web_custom_gpt,
|
||||||
api_type: (prompt.api_type === undefined || prompt.api_type === "undefined") ? "" : prompt.api_type,
|
api_type: (prompt.api_type === undefined || prompt.api_type === "undefined") ? "" : prompt.api_type,
|
||||||
api_model: (prompt.api_model === undefined || prompt.api_model === "undefined") ? "" : prompt.api_model
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
//console.log('>>>>>>>>>>>>>> default_prompts_properties: ' + JSON.stringify(default_prompts_properties));
|
//console.log('>>>>>>>>>>>>>> default_prompts_properties: ' + JSON.stringify(default_prompts_properties));
|
||||||
|
|
@ -590,7 +585,6 @@ export async function savePrompt(prompt) {
|
||||||
|
|
||||||
export async function clearPromptAPI(id){
|
export async function clearPromptAPI(id){
|
||||||
let _prompt = await loadPrompt(id);
|
let _prompt = await loadPrompt(id);
|
||||||
_prompt.api = "";
|
_prompt.api_type = "";
|
||||||
_prompt.model = "";
|
|
||||||
await savePrompt(_prompt);
|
await savePrompt(_prompt);
|
||||||
}
|
}
|
||||||
|
|
@ -648,7 +648,9 @@ export function getConnectionType(prefsOrType, prompt, prefixOrSpecific = null)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (specificType && specificType !== '') return specificType;
|
if (specificType && specificType !== '') return specificType;
|
||||||
if (prompt && prompt.api && prompt.api !== '') return prompt.api;
|
if (prompt) {
|
||||||
|
if (prompt.api_type && prompt.api_type !== '') return prompt.api_type;
|
||||||
|
}
|
||||||
return defaultType;
|
return defaultType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -371,6 +371,9 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
|
||||||
prefs = checkScreenDimensions(prefs);
|
prefs = checkScreenDimensions(prefs);
|
||||||
//console.log(">>>>>>>>>>>>>>>> prefs: " + JSON.stringify(prefs));
|
//console.log(">>>>>>>>>>>>>>>> prefs: " + JSON.stringify(prefs));
|
||||||
// console.log(">>>>>>>>>>>>>>>> prompt_info: " + JSON.stringify(prompt_info));
|
// console.log(">>>>>>>>>>>>>>>> prompt_info: " + JSON.stringify(prompt_info));
|
||||||
|
|
||||||
|
prefs.connection_type = getConnectionType(prefs, prompt_info);
|
||||||
|
|
||||||
taLog.log("Prompt length: " + promptText.length);
|
taLog.log("Prompt length: " + promptText.length);
|
||||||
let _max_prompt_length = prefs.max_prompt_length;
|
let _max_prompt_length = prefs.max_prompt_length;
|
||||||
if(prefs.connection_type == 'chatgpt_web'){
|
if(prefs.connection_type == 'chatgpt_web'){
|
||||||
|
|
|
||||||
|
|
@ -1022,7 +1022,7 @@ export async function initializeSpecificIntegrationUI({
|
||||||
let prompt = await loadPrompt(promptId);
|
let prompt = await loadPrompt(promptId);
|
||||||
if(!prompt) return;
|
if(!prompt) return;
|
||||||
|
|
||||||
prompt.api = conntype;
|
prompt.api_type = conntype;
|
||||||
|
|
||||||
for (const [integration, options] of Object.entries(integration_options_config)) {
|
for (const [integration, options] of Object.entries(integration_options_config)) {
|
||||||
for (const key of Object.keys(options)) {
|
for (const key of Object.keys(options)) {
|
||||||
|
|
|
||||||
|
|
@ -48,11 +48,11 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
let specialPrompts = await getSpecialPrompts();
|
let specialPrompts = await getSpecialPrompts();
|
||||||
let addtags_prompt = specialPrompts.find(prompt => prompt.id === 'prompt_add_tags');
|
let addtags_prompt = specialPrompts.find(prompt => prompt.id === 'prompt_add_tags');
|
||||||
|
|
||||||
if (addtags_prompt && addtags_prompt.api && addtags_prompt.api !== '') {
|
if (addtags_prompt && addtags_prompt.api_type && addtags_prompt.api_type !== '') {
|
||||||
let update_prefs = {};
|
let update_prefs = {};
|
||||||
update_prefs['add_tags_connection_type'] = addtags_prompt.api;
|
update_prefs['add_tags_connection_type'] = addtags_prompt.api_type;
|
||||||
|
|
||||||
let integration = addtags_prompt.api.replace('_api', '');
|
let integration = addtags_prompt.api_type.replace('_api', '');
|
||||||
if (integration_options_config && integration_options_config[integration]) {
|
if (integration_options_config && integration_options_config[integration]) {
|
||||||
for (const key of Object.keys(integration_options_config[integration])) {
|
for (const key of Object.keys(integration_options_config[integration])) {
|
||||||
if (addtags_prompt[key] !== undefined) {
|
if (addtags_prompt[key] !== undefined) {
|
||||||
|
|
@ -344,14 +344,18 @@ async function restoreOptions() {
|
||||||
let addtags_prompt = specialPrompts.find(prompt => prompt.id === 'prompt_add_tags');
|
let addtags_prompt = specialPrompts.find(prompt => prompt.id === 'prompt_add_tags');
|
||||||
|
|
||||||
if (addtags_prompt) {
|
if (addtags_prompt) {
|
||||||
if (addtags_prompt.api && addtags_prompt.api !== '') {
|
if (addtags_prompt.api_type && addtags_prompt.api_type !== '') {
|
||||||
getting['add_tags_connection_type'] = addtags_prompt.api;
|
getting['add_tags_connection_type'] = addtags_prompt.api_type;
|
||||||
|
} else {
|
||||||
|
getting['add_tags_connection_type'] = getting['connection_type'];
|
||||||
}
|
}
|
||||||
for (const [integration, options] of Object.entries(integration_options_config)) {
|
for (const [integration, options] of Object.entries(integration_options_config)) {
|
||||||
for (const key of Object.keys(options)) {
|
for (const key of Object.keys(options)) {
|
||||||
const propName = `${integration}_${key}`;
|
const propName = `${integration}_${key}`;
|
||||||
if (addtags_prompt[propName] !== undefined) {
|
if (addtags_prompt[propName] !== undefined && addtags_prompt[propName] !== '') {
|
||||||
getting[`add_tags_${propName}`] = addtags_prompt[propName];
|
getting[`add_tags_${propName}`] = addtags_prompt[propName];
|
||||||
|
} else {
|
||||||
|
getting[`add_tags_${propName}`] = getting[propName];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,10 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { prefs_default, integration_options_config } from '../../options/mzta-options-default.js';
|
import {
|
||||||
|
prefs_default,
|
||||||
|
integration_options_config
|
||||||
|
} from '../../options/mzta-options-default.js';
|
||||||
import { taLogger } from '../../js/mzta-logger.js';
|
import { taLogger } from '../../js/mzta-logger.js';
|
||||||
import {
|
import {
|
||||||
getSpecialPrompts,
|
getSpecialPrompts,
|
||||||
|
|
@ -42,6 +45,21 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
let specialPrompts = await getSpecialPrompts();
|
let specialPrompts = await getSpecialPrompts();
|
||||||
let spamfilter_prompt = specialPrompts.find(prompt => prompt.id === 'prompt_spamfilter');
|
let spamfilter_prompt = specialPrompts.find(prompt => prompt.id === 'prompt_spamfilter');
|
||||||
|
|
||||||
|
if (spamfilter_prompt && spamfilter_prompt.api_type && spamfilter_prompt.api_type !== '') {
|
||||||
|
let update_prefs = {};
|
||||||
|
update_prefs['spamfilter_connection_type'] = spamfilter_prompt.api_type;
|
||||||
|
|
||||||
|
let integration = spamfilter_prompt.api_type.replace('_api', '');
|
||||||
|
if (integration_options_config && integration_options_config[integration]) {
|
||||||
|
for (const key of Object.keys(integration_options_config[integration])) {
|
||||||
|
if (spamfilter_prompt[key] !== undefined) {
|
||||||
|
update_prefs[`spamfilter_${integration}_${key}`] = spamfilter_prompt[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await browser.storage.sync.set(update_prefs);
|
||||||
|
}
|
||||||
|
|
||||||
await initializeSpecificIntegrationUI({
|
await initializeSpecificIntegrationUI({
|
||||||
prefix: 'spamfilter',
|
prefix: 'spamfilter',
|
||||||
promptId: 'prompt_spamfilter',
|
promptId: 'prompt_spamfilter',
|
||||||
|
|
@ -313,14 +331,18 @@ async function restoreOptions() {
|
||||||
let spamfilter_prompt = specialPrompts.find(prompt => prompt.id === 'prompt_spamfilter');
|
let spamfilter_prompt = specialPrompts.find(prompt => prompt.id === 'prompt_spamfilter');
|
||||||
|
|
||||||
if (spamfilter_prompt) {
|
if (spamfilter_prompt) {
|
||||||
if (spamfilter_prompt.api && spamfilter_prompt.api !== '') {
|
if (spamfilter_prompt.api_type && spamfilter_prompt.api_type !== '') {
|
||||||
getting['spamfilter_connection_type'] = spamfilter_prompt.api;
|
getting['spamfilter_connection_type'] = spamfilter_prompt.api_type;
|
||||||
|
} else {
|
||||||
|
getting['spamfilter_connection_type'] = getting['connection_type'];
|
||||||
}
|
}
|
||||||
for (const [integration, options] of Object.entries(integration_options_config)) {
|
for (const [integration, options] of Object.entries(integration_options_config)) {
|
||||||
for (const key of Object.keys(options)) {
|
for (const key of Object.keys(options)) {
|
||||||
const propName = `${integration}_${key}`;
|
const propName = `${integration}_${key}`;
|
||||||
if (spamfilter_prompt[propName] !== undefined) {
|
if (spamfilter_prompt[propName] !== undefined && spamfilter_prompt[propName] !== '') {
|
||||||
getting[`spamfilter_${propName}`] = spamfilter_prompt[propName];
|
getting[`spamfilter_${propName}`] = spamfilter_prompt[propName];
|
||||||
|
} else {
|
||||||
|
getting[`spamfilter_${propName}`] = getting[propName];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue