Skip to content

Commit

Permalink
v0.0.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
giosilvi committed Oct 15, 2022
1 parent 5962381 commit fad382f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 55 deletions.
4 changes: 2 additions & 2 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ function createContextMenu() {
id: 'GPT-Prompter',
title: 'GPT-Prompter ',
documentUrlPatterns: ["https://*/*", "http://*/*"],
contexts: ["selection", "page","frame"]
contexts: ["selection", "page", "frame"]
});

// create a sub-context menu
chrome.contextMenus.create({
id: 'On-the-fly',
title: '★ (NEW!) Prompt On-the-fly',
parentId: 'GPT-Prompter',
contexts: ["selection", "page","frame"]
contexts: ["selection", "page", "frame"]
});

// retrieve from storage the list of custom prompts
Expand Down
26 changes: 10 additions & 16 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,37 +142,31 @@ chrome.runtime.onMessage.addListener(function (request) {

// console.log('split:' + data.length);
for (var m = 1; m < data.length; m++) {// in case of multiple stream in one, loop over them
if (data[m].indexOf("[DONE]") == -1)
{ // if there is not "[DONE]" in the text, it`s a stream
if (data[m].indexOf("[DONE]") == -1) { // if there is not "[DONE]" in the text, it`s a stream
var json = JSON.parse(data[m]);
var stream_id = json.id;
// in case has been asked to stop the stream, add the id to the list,
// if the stream is not in the list of undesired streams
if (popUpShadow.stop_stream == true && popUpShadow.listOfUndesiredStreams.indexOf(stream_id) == -1)
{
if (popUpShadow.stop_stream == true && popUpShadow.listOfUndesiredStreams.indexOf(stream_id) == -1) {
popUpShadow.listOfUndesiredStreams.push(stream_id);
console.log('stop stream', stream_id);
popUpShadow.stop_stream = false;
popUpShadow.clearnewlines = true;
popUpShadow.ignore_next_stop = true;
}
// if the stream id is not in the list of undesired streams, add the text to the popup
if (popUpShadow.listOfUndesiredStreams.indexOf(stream_id) == -1)
{
if (popUpShadow.listOfUndesiredStreams.indexOf(stream_id) == -1) {
popUpShadow.updatepopup(json, id_popup, true);
}
}
else
{
if (popUpShadow.ignore_next_stop == false)
{
popUpShadow.updatepopup(request, id_popup, false); // the end of the stream
}
else
{
popUpShadow.ignore_next_stop = false;
}
else {
if (popUpShadow.ignore_next_stop == false) {
popUpShadow.updatepopup(request, id_popup, false); // the end of the stream
}
else {
popUpShadow.ignore_next_stop = false;
}
}
}
// in case of error, the split will not produce more than one element
if (data.length == 1) {
Expand Down
12 changes: 7 additions & 5 deletions gpt3.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ async function promptGPT3Prompting(prompt, items, tabs) {
console.log(text, model, temperature, max_tokens);
console.log('Tabs', tabs);
const url = "https://api.openai.com/v1/completions";
var body_data = { "model": model,
"temperature": temperature,
"max_tokens": max_tokens,
"prompt": text,
"stream": true };
var body_data = {
"model": model,
"temperature": temperature,
"max_tokens": max_tokens,
"prompt": text,
"stream": true
};
// remove stream from body_data
var str_body_data = JSON.stringify(body_data);

Expand Down
64 changes: 32 additions & 32 deletions popup_world.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function computeCost(tokens, model) {



const minipopup = (id, {left = 0, top = 0 }) => `
const minipopup = (id, { left = 0, top = 0 }) => `
<div class="popuptext" id="${id}" style="left: ${left}px; top:${top}px">
<div id="${id}prompt" class="popupprompt">
<div id="${id}header" class="grabbable" style='width: 90%;'>
Expand Down Expand Up @@ -223,7 +223,7 @@ class popUpClass extends HTMLElement {
this.shadowRoot.getElementById(this.ids + "textarea").focus();
}

pinButtons(id_target,id_button) {
pinButtons(id_target, id_button) {
this.shadowRoot.getElementById(id_button).addEventListener("click", () => {
// if the element is in listOfUnpinnedPopups, remove it from there. If not, add it to the list
if (this.listOfUnpinnedPopups.includes(id_target)) {
Expand All @@ -235,9 +235,9 @@ class popUpClass extends HTMLElement {
//toggle class to invertcolor
this.shadowRoot.getElementById(id_button).classList.toggle('invertcolor');
});
}
}


minimizeButtons(id_target, id_button) {
this.shadowRoot.getElementById(id_button).addEventListener("click", () => {
this.shadowRoot.getElementById(id_target + "text").classList.toggle('hide');
Expand Down Expand Up @@ -267,37 +267,37 @@ class popUpClass extends HTMLElement {

runClick(id_target) {
// if id_target + "submit" has no listener, add one
this.shadowRoot.getElementById(id_target + "submit").addEventListener("click", () => {
// show stop button and hide run button
this.toggleRunStop(id_target);

this.shadowRoot.getElementById(id_target + "text").innerHTML = "";
console.log('Prompt on-the-fly launched from', id_target)
var promptDict = {
"prompt": this.shadowRoot.getElementById(id_target + "textarea").innerHTML,
"model": "text-davinci-002",
"temperature": 0.1,
"max_tokens": 1000,
"popupID": id_target,
}
chrome.runtime.sendMessage({ text: "launchGPT", prompt: promptDict });
this.shadowRoot.getElementById(id_target + "submit").addEventListener("click", () => {
// show stop button and hide run button
this.toggleRunStop(id_target);

});
// make the same listener, but for the ctrl+enter key combination
this.shadowRoot.getElementById(id_target + "textarea").addEventListener("keydown", (e) => {
if (e.ctrlKey && e.key === 'Enter') {
this.shadowRoot.getElementById(id_target + "submit").click();
}
this.shadowRoot.getElementById(id_target + "text").innerHTML = "";
console.log('Prompt on-the-fly launched from', id_target)
var promptDict = {
"prompt": this.shadowRoot.getElementById(id_target + "textarea").innerHTML,
"model": "text-davinci-002",
"temperature": 0.1,
"max_tokens": 1000,
"popupID": id_target,
}
);
chrome.runtime.sendMessage({ text: "launchGPT", prompt: promptDict });

});
// make the same listener, but for the ctrl+enter key combination
this.shadowRoot.getElementById(id_target + "textarea").addEventListener("keydown", (e) => {
if (e.ctrlKey && e.key === 'Enter') {
this.shadowRoot.getElementById(id_target + "submit").click();
}
}
);
}

stopButton(id_target) {
this.shadowRoot.getElementById(id_target + "stop").addEventListener("click", () => {
console.log('Prompt on-the-fly stopped from', id_target)
this.stop_stream=true;
this.stop_stream = true;
this.toggleRunStop(id_target);

});
// // make the same listener, but for the ctrl+enter key combination
// this.shadowRoot.getElementById(id_target + "textarea").addEventListener("keydown", (e) => {
Expand All @@ -310,8 +310,8 @@ class popUpClass extends HTMLElement {

toggleRunStop(id_target) {
if (this.shadowRoot.getElementById(id_target + "submit")) {
this.shadowRoot.getElementById(id_target + "submit").classList.toggle('hide');
this.shadowRoot.getElementById(id_target + "stop").classList.toggle('hide');
this.shadowRoot.getElementById(id_target + "submit").classList.toggle('hide');
this.shadowRoot.getElementById(id_target + "stop").classList.toggle('hide');
}
}

Expand All @@ -321,10 +321,10 @@ class popUpClass extends HTMLElement {
//
var id_target = popUpShadow.listOfActivePopups[i];
// const id_target =this.ids
const id_pin = "pin"+id_target;
const id_pin = "pin" + id_target;
const id_close = "mclose" + id_target;
const id_minimize = "minimize" + id_target;
this.pinButtons(id_target,id_pin);
this.pinButtons(id_target, id_pin);
this.minimizeButtons(id_target, id_minimize);
this.closeButtons(id_target, id_close);
this.doubleClick(id_target + "prompt");
Expand Down

0 comments on commit fad382f

Please sign in to comment.