Skip to content

Commit

Permalink
v0.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
giosilvi committed Nov 30, 2022
1 parent c6f97a5 commit 3ebc7c4
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 31 deletions.
6 changes: 3 additions & 3 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ chrome.runtime.onInstalled.addListener(function () {
for (var i = 0; i < items.customprompt.length; i++) {
// modify each one of them to become a dictionary
items.customprompt[i] = {
"model": "text-davinci-002",
"model": "text-davinci-003",
"temperature": 0,
"max_tokens": 1024,
"prompt": items.customprompt[i],
Expand All @@ -110,7 +110,7 @@ chrome.runtime.onInstalled.addListener(function () {
}
}
else { // if the prompt does not exist, create the default one
items.customprompt = [{ "model": "text-davinci-002", "temperature": 0, "max_tokens": 1024, "prompt": 'Tell me more about "#TEXT#":' }];
items.customprompt = [{ "model": "text-davinci-003", "temperature": 0, "max_tokens": 1024, "prompt": 'Tell me more about "#TEXT#":' }];
}
// save the new_prompt_list
chrome.storage.sync.set({ 'customprompt': items.customprompt });
Expand Down Expand Up @@ -212,7 +212,7 @@ chrome.contextMenus.onClicked.addListener((info, tabs) => {

// here we want to create a minipop-up to ask the user to insert the prompt
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, { message: 'showPopUpOnTheFly', text: selectionText, body_data: { "model": "text-davinci-002", "temperature": 0, "max_tokens": 1024 } });
chrome.tabs.sendMessage(tabs[0].id, { message: 'showPopUpOnTheFly', text: selectionText, body_data: { "model": "text-davinci-003", "temperature": 0, "max_tokens": 2048 } });
});
// check if there is a selection
// if (info.selectionText) {
Expand Down
4 changes: 2 additions & 2 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ chrome.runtime.onMessage.addListener(function (request) {
else if (request.message == 'GPTprompt') {
popUpShadow.updatePopupHeader(request, id_popup);
}
else if (request.message == 'GPTStream_answer') {
else if (request.message == 'GPTStream_completion') {
// split over 'data: ' in case there are multiple streams concatenated
var data = request.text.split('data: ');

Expand Down Expand Up @@ -164,7 +164,7 @@ chrome.runtime.onMessage.addListener(function (request) {
popUpShadow.updatepopup(request, id_popup, false); // the end of the stream
}
else {
popUpShadow.ignore_next_stop = false;
popUpShadow.ignore_next_stop = false; // reset the flag
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions gpt3.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function sendStream(message, id, string, body_data, idpopup) {
text: string,
body_data: body_data,
id_popup: idpopup
}); //send the answer to the content script
}); //send the completion to the content script
}

function checkTabsAndSendStream(message, tabs, string, body_data, idpopup) {
Expand Down Expand Up @@ -70,14 +70,14 @@ async function promptGPT3Prompting(prompt, items, tabs) {
var stream = new TextDecoder().decode(value);//.substring(6);
// console.log(string, typeof string);
// if tabs.id == -1 then use querySelector to get the tab
checkTabsAndSendStream("GPTStream_answer", tabs, stream, str_body_data, popupID);
checkTabsAndSendStream("GPTStream_completion", tabs, stream, str_body_data, popupID);
return pump();
});
}
}
).catch(err => {
console.log("error" + err);
checkTabsAndSendStream("GPTStream_answer", tabs, "Error:" + err, str_body_data, popupID);
checkTabsAndSendStream("GPTStream_completion", tabs, "Error:" + err, str_body_data, popupID);

});
}
Expand Down
4 changes: 2 additions & 2 deletions history.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<div class="row">
<div class="col-md-2 ml-auto" style="display:flex; padding: 40px;"><img src="icons\iconA128.png"></div>
<div class="col-md-10 mr-auto" style="margin: top 20px; text-align: left; margin:auto;">
<h1 style="margin-bottom: -1.5rem;">History: Prompts & Answer </h1><br><span
style="margin: top -50px;">Here you can see your prompt & answers, as well as costs</span>
<h1 style="margin-bottom: -1.5rem;">History: Prompts & completion </h1><br><span
style="margin: top -50px;">Here you can see your prompt & completions, as well as costs</span>
</div>
</div>

Expand Down
16 changes: 8 additions & 8 deletions history.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ function makeHistoryList(items) {
}
}
// var cleanAns = items.history[i][1].replace(prompt["prompt"], '');
freshList += 'answer:' + items.history[i][1] + '<br>'
freshList += 'Cost: ' + items.history[i][2] + '$ <button class="save" id="eraseItem' + i.toString() + '" > Delete </button></li>';
freshList += 'completion:' + items.history[i][1] + '<br>'
freshList += 'cost: ' + items.history[i][2] + '$ <button class="save" id="eraseItem' + i.toString() + '" > Delete </button></li>';
totalCost += parseFloat(items.history[i][2]);
}
document.getElementById('totCost').innerHTML = 'Total cost: ' + totalCost.toFixed(2) + '$';
Expand Down Expand Up @@ -117,13 +117,13 @@ function export_history() {
for (var i = 0; i < li.length; i++) {
// if li element is not hidden
if (li[i].style.display != 'none') {
// from li[i].innerHTML get the prompt, answer , and remove any <br> element
var prompt = li[i].innerHTML.split('prompt:')[1].split('answer:')[0].replace(/<br>/g, '');
var answer = li[i].innerHTML.split('answer:')[1].split('Cost:')[0].replace(/<br>/g, '');
// combine the prompt and answer to dictionary
var prompt_answer = { 'prompt': prompt, 'answer': answer };
// from li[i].innerHTML get the prompt, completion , and remove any <br> element
var prompt = li[i].innerHTML.split('prompt:')[1].split('completion:')[0].replace(/<br>/g, '');
var completion = li[i].innerHTML.split('completion:')[1].split('Cost:')[0].replace(/<br>/g, '');
// combine the prompt and completion to dictionary
var prompt_completion = { 'prompt': prompt, 'completion': completion };
// add the dictionary to the history_to_save array
history_to_save.push(prompt_answer);
history_to_save.push(prompt_completion);
}

}
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ "name": "GPT-Prompter",
"version": "0.0.0.5",
"version": "0.0.0.6",
"description": "Fast custom prompts to GPT-3 API",
"manifest_version": 3,
"icons": {
Expand Down
4 changes: 3 additions & 1 deletion popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ <h5 class="card-title"><img src="icons\iconA48.png" alt="logo" class="logo"> GPT
<label class="input-group-text" for="inputmodel" style="border:0">Model</label>
</div>
<select class="custom-select" id="inputmodel">
<option selected value="text-davinci-002" title="Most capable GPT-3 model, most expensive ($0.02/ 1k tokens)">🅳
<option selected value="text-davinci-003" title="Most capable GPT-3 model, most expensive ($0.02/ 1k tokens)">
text-davinci-003</option>
<option value="text-davinci-002" title="Capable GPT-3 model, most expensive ($0.02/ 1k tokens)">🅳
text-davinci-002</option>
<option value="text-curie-001" title="Very capable, but faster and lower cost than Davinci. ($0.002/ 1k tokens)">🅲
text-curie-001</option>
Expand Down
23 changes: 13 additions & 10 deletions popup_world.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// import symbolFromModel from './sharedfunctions.js'; //TODO:fix this
var models = {
"text-davinci-003": "ↁ",
"text-davinci-002": "🅳",
"text-curie-001": "🅲",
"text-babbage-001": "🅑",
Expand All @@ -25,7 +26,9 @@ const AdaCost = 0.0004 / 1000;

function computeCost(tokens, model) {
var cost = 0;
if (model == "text-davinci-002")
if (model == "text-davinci-003")
cost = tokens * DaVinciCost;
else if (model == "text-davinci-002")
cost = tokens * DaVinciCost;
else if (model == "text-curie-001")
cost = tokens * CurieCost;
Expand All @@ -50,7 +53,7 @@ const minipopup = (id, { left = 0, top = 0 }) => `
<button class='minibuttons' id="mclose${id}">&#128473;&#xFE0E;</button>
</div>
</div>
<p id="${id}text" class='popupanswer'></p>
<p id="${id}text" class='popupcompletion'></p>
</div>
`;

Expand All @@ -70,7 +73,7 @@ const flypopup = (id, { text = "none", left = 0, top = 0 }) => `
<div contentEditable="true" id="${id}textarea" class='textarea'> ${text}</div>
<button type="button" id="${id}submit" class="submitbutton">Submit</button>
<button type="button" id="${id}stop" class="submitbutton hide" style='background-color: red;'>Stop</button>
<p id="${id}text" class='popupanswer'></p>
<p id="${id}text" class='popupcompletion'></p>
</div>
`;

Expand Down Expand Up @@ -108,7 +111,7 @@ const styled = `
.onylonthefly{
border: 2px solid rgb(16, 163, 127);
}
.popupanswer {
.popupcompletion {
clear: left;
cursor: text;
white-space: pre-wrap;
Expand Down Expand Up @@ -275,7 +278,7 @@ class popUpClass extends HTMLElement {
console.log('Prompt on-the-fly launched from', id_target)
var promptDict = {
"prompt": this.shadowRoot.getElementById(id_target + "textarea").innerHTML,
"model": "text-davinci-002",
"model": "text-davinci-003",
"temperature": 0.1,
"max_tokens": 1000,
"popupID": id_target,
Expand Down Expand Up @@ -366,17 +369,17 @@ class popUpClass extends HTMLElement {
var type = message.error.type
this.shadowRoot.getElementById(target_id + "text").innerHTML += type + "<br>" + text;
this.tokens = 0;
// show stop button and hide run button
//show run button and hide stop button
this.toggleRunStop(target_id);
}
// each message should be 1 token
this.tokens++;

}
else {
// show stop button and hide run button
// show run button and hide stop button
this.toggleRunStop(target_id);
var complete_answer = this.shadowRoot.getElementById(target_id + "text").innerHTML
var complete_completion = this.shadowRoot.getElementById(target_id + "text").innerHTML

//save prompt to local storage

Expand All @@ -388,11 +391,11 @@ class popUpClass extends HTMLElement {
// save the result.choices[0].text in the storage
chrome.storage.local.get('history', function (items) {
if (typeof items.history !== 'undefined') {
items.history.push([message.body_data, complete_answer, cost]);// add the result to the history
items.history.push([message.body_data, complete_completion, cost]);// add the result to the history
chrome.storage.local.set({ 'history': items.history });
}
else {
items.history = [[message.body_data, complete_answer, cost]]; // initialize the history array
items.history = [[message.body_data, complete_completion, cost]]; // initialize the history array
chrome.storage.local.set({ 'history': items.history });
}
});
Expand Down
1 change: 1 addition & 0 deletions sharedfunctions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var models = {
"text-davinci-003": "ↁ",
"text-davinci-002": "🅳",
"text-curie-001": "🅲",
"text-babbage-001": "🅑",
Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Theme Name: GPT3
Description: The first theme for GPT3 responder
Version: 0.1
Author: Paoloart
Template: 42 is the answer to everything
Template: 42 is the completion to everything
*/

Expand Down

0 comments on commit 3ebc7c4

Please sign in to comment.