additional_text implemented for api calls. see #153
This commit is contained in:
parent
15fb0c6e72
commit
1d718b3797
3 changed files with 17 additions and 5 deletions
|
|
@ -20,10 +20,13 @@
|
||||||
* The original code has been released under the Apache License, Version 2.0.
|
* 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
|
// Get the LLM to be used
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
const llm = urlParams.get('llm');
|
const llm = urlParams.get('llm');
|
||||||
const call_id = urlParams.get('call_id');
|
const call_id = urlParams.get('call_id');
|
||||||
|
const ph_def_val = urlParams.get('ph_def_val');
|
||||||
|
|
||||||
// Data received from the user
|
// Data received from the user
|
||||||
let promptData = null;
|
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
|
// Event listeners for worker messages
|
||||||
worker.onmessage = function(event) {
|
worker.onmessage = function(event) {
|
||||||
|
|
@ -126,7 +130,15 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||||
if(message.do_custom_text=="1") {
|
if(message.do_custom_text=="1") {
|
||||||
let userInput = prompt(browser.i18n.getMessage("chatgpt_win_custom_text"));
|
let userInput = prompt(browser.i18n.getMessage("chatgpt_win_custom_text"));
|
||||||
if(userInput !== null) {
|
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;
|
promptData = message;
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ const defaultPlaceholders = [
|
||||||
is_default: "1",
|
is_default: "1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'additional_text', //TODO
|
id: 'additional_text',
|
||||||
name: "__MSG_placeholder_additional_text__",
|
name: "__MSG_placeholder_additional_text__",
|
||||||
default_value: "",
|
default_value: "",
|
||||||
type: 0,
|
type: 0,
|
||||||
|
|
|
||||||
|
|
@ -342,7 +342,7 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
|
||||||
browser.runtime.onMessage.addListener(listener2);
|
browser.runtime.onMessage.addListener(listener2);
|
||||||
|
|
||||||
let win_options2 = {
|
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",
|
type: "popup",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -399,7 +399,7 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
|
||||||
browser.runtime.onMessage.addListener(listener3);
|
browser.runtime.onMessage.addListener(listener3);
|
||||||
|
|
||||||
let win_options3 = {
|
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",
|
type: "popup",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -450,7 +450,7 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
|
||||||
browser.runtime.onMessage.addListener(listener4);
|
browser.runtime.onMessage.addListener(listener4);
|
||||||
|
|
||||||
let win_options4 = {
|
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",
|
type: "popup",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue