additional_text implemented for api calls. see #153

This commit is contained in:
mic 2024-10-15 23:43:13 +02:00
parent 15fb0c6e72
commit 1d718b3797
3 changed files with 17 additions and 5 deletions

View file

@ -20,10 +20,13 @@
* The original code has been released under the Apache License, Version 2.0.
*/
import { placeholdersUtils } from '../js/mzta-placeholders.js';
// Get the LLM to be used
const urlParams = new URLSearchParams(window.location.search);
const llm = urlParams.get('llm');
const call_id = urlParams.get('call_id');
const ph_def_val = urlParams.get('ph_def_val');
// Data received from the user
let promptData = null;
@ -93,6 +96,7 @@ switch (llm) {
}
}
//let prefs_ph = await browser.storage.sync.get({placeholders_use_default_value: false});
// Event listeners for worker messages
worker.onmessage = function(event) {
@ -126,7 +130,15 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
if(message.do_custom_text=="1") {
let userInput = prompt(browser.i18n.getMessage("chatgpt_win_custom_text"));
if(userInput !== null) {
message.prompt += " " + userInput;
if(!placeholdersUtils.hasPlaceholder(message.prompt, 'additional_text')){
// no additional_text placeholder, do as usual
message.prompt += " " + userInput;
}else{
// we have the additional_text placeholder, do the magic!
let finalSubs = {};
finalSubs["additional_text"] = userInput;
message.prompt = placeholdersUtils.replacePlaceholders(message.prompt, finalSubs, ph_def_val==='1')
}
}
}
promptData = message;

View file

@ -62,7 +62,7 @@ const defaultPlaceholders = [
is_default: "1",
},
{
id: 'additional_text', //TODO
id: 'additional_text',
name: "__MSG_placeholder_additional_text__",
default_value: "",
type: 0,

View file

@ -342,7 +342,7 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
browser.runtime.onMessage.addListener(listener2);
let win_options2 = {
url: browser.runtime.getURL('api_webchat/index.html?llm='+prefs.connection_type+'&call_id='+rand_call_id2),
url: browser.runtime.getURL('api_webchat/index.html?llm='+prefs.connection_type+'&call_id='+rand_call_id2+'&ph_def_val='+(prefs.placeholders_use_default_value?'1':'0')),
type: "popup",
}
@ -399,7 +399,7 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
browser.runtime.onMessage.addListener(listener3);
let win_options3 = {
url: browser.runtime.getURL('api_webchat/index.html?llm='+prefs.connection_type+'&call_id='+rand_call_id3),
url: browser.runtime.getURL('api_webchat/index.html?llm='+prefs.connection_type+'&call_id='+rand_call_id3+'&ph_def_val='+(prefs.placeholders_use_default_value?'1':'0')),
type: "popup",
}
@ -450,7 +450,7 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
browser.runtime.onMessage.addListener(listener4);
let win_options4 = {
url: browser.runtime.getURL('api_webchat/index.html?llm='+prefs.connection_type+'&call_id='+rand_call_id4),
url: browser.runtime.getURL('api_webchat/index.html?llm='+prefs.connection_type+'&call_id='+rand_call_id4+'&ph_def_val='+(prefs.placeholders_use_default_value?'1':'0')),
type: "popup",
}