Skip to content

Commit

Permalink
fixing few bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
giosilvi committed May 26, 2024
1 parent b180e13 commit 68488b6
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 28 deletions.
14 changes: 3 additions & 11 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,14 @@ chrome.runtime.onInstalled.addListener(function (details) {
model: "gpt-4-turbo",
temperature: 0.1,
max_tokens: 4096,
prompt: JSON.stringify([{"role":"user", "content":"Try not to use headings.. Tell me more about #TEXT#:"}]),
prompt: JSON.stringify([{"role":"system", "content":"You are a helpful assistant"},{"role":"user", "content":"Tell me more about #TEXT#:"}]),
twoStage: false,
},
{
model: "gpt-4-turbo",
temperature: 0.1,
max_tokens: 4096,
prompt: JSON.stringify([{"role":"user", "content":"Please create an Anki card for: #TEXT#:"}]),
twoStage: false,
},
{
model: "gpt-4-turbo",
temperature: 0.1,
max_tokens: 4096,
prompt: JSON.stringify([{"role":"user", "content":"Please create an Anki card for the concept below. Explain any intuitions and be sure to include formulas if necessary: #TEXT#"}]),
prompt: JSON.stringify([{"role":"system", "content":"You are a helpful assistant"},{"role":"user", "content":"Please create an Anki card for: #TEXT#:"}]),
twoStage: false,
},
{
Expand Down Expand Up @@ -215,8 +208,7 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
else if (message.text === "launchGPT") {
// Get the tab from the sender
const { tab } = sender; // this line is equivalent to const tab = sender.tab;
console.log("Received prompt object.");
console.log(typeof message.prompt.prompt, message.prompt);

// Launch GPT
chrome.storage.sync.get("APIKEY", function (items) {
(async () => {
Expand Down
2 changes: 0 additions & 2 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ function processJsonObject(jsonStr, uuid, request) {
try {
// Check for the [DONE] marker
if (jsonStr === "[DONE]") {
console.log("Received [DONE] marker for", uuid);
popUpShadow.updatepopup(request, uuid, false);
return;
}
Expand Down Expand Up @@ -240,7 +239,6 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
break;
case "showPopUpChatGPT":
handleShowPopUp();
console.log("ChatGPT");
popUpShadow.chatGPTpopup(request.text, request.bodyData, request.cursorPosition);
addListenersForDrag();
break;
Expand Down
2 changes: 1 addition & 1 deletion src/gpt3.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async function promptGPT3Prompting(prompt, items, tabs) {
return;
}
// Enqueue the next data chunk into our target stream
console.log(value);
// console.log(value);
var stream = new TextDecoder().decode(value); //.substring(6);
// console.log(string, typeof string);
// if tabs.id == -1 then use querySelector to get the tab
Expand Down
12 changes: 6 additions & 6 deletions src/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @return {string} - The HTML list.
*/

import {CHAT_API_MODELS} from "./gpt3.js";
import { CHAT_API_MODELS } from "./gpt3.js";

function makeHistoryList(items) {
// create empty list and total cost variables
Expand Down Expand Up @@ -43,7 +43,9 @@ function createListItem(item, index) {
if (key !== "stream" && key !== "prompt" && key !== "messages") {
var value = prompt[key];
// wrap key in 'strong' element
promptContent += `<strong>${key}:</strong> ${value}<br>`;
if (value !== undefined){
promptContent += `<strong>${key}:</strong> ${value}<br>`;
}
}
}
// add prompt key and value to prompt content string
Expand Down Expand Up @@ -106,8 +108,7 @@ function erasePrompt(index) {
if (index <= items.history.length) {
// remove the prompt from the array
items.history.splice(index, 1);
freshList = makeHistoryList(items);
document.getElementById("history-of-prompts").innerHTML = freshList;
document.getElementById("history-of-prompts").innerHTML = makeHistoryList(items);
update_lower_buttons(items);
chrome.storage.local.set({ history: items.history }, function () {
// Notify that is erased
Expand All @@ -126,8 +127,7 @@ function load_history() {
if (typeof items.history !== "undefined") {
// check if it is not empty
if (items.history.length > 0) {
freshList = makeHistoryList(items);
document.getElementById("history-of-prompts").innerHTML = freshList;
document.getElementById("history-of-prompts").innerHTML = makeHistoryList(items);
update_lower_buttons(items);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "GPT-Prompter",
"version": "0.0.4.3",
"description": "Fast custom prompts to GPT-3, GPT-4 and ChatGPT API",
"version": "0.0.4.4",
"description": "Fast custom prompts to GPT-3.5, GPT-4 and ChatGPT API",
"manifest_version": 3,
"icons": {
"16": "icons/iconA16.png",
Expand Down
16 changes: 10 additions & 6 deletions src/popup_world.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,15 @@ class popUpClass extends HTMLElement {
}

render() {
this.attachShadow({ mode: "open" }); // here we create the shadow DOM
if (!this.shadowRoot) {
this.attachShadow({ mode: "open" });
}
const style = document.createElement("style");
style.textContent = styled;
this.shadowRoot.appendChild(style); // here append the style to the shadowRoot
// add script to the shadowRoot that points at local src="dist/markdown.bundle.js"
// add script to the shadowRoot that points at local src="dist/markdown.bundle.js" 
// const script = document.createElement("script");
// script.src = chrome.runtime.getURL("dist/markdown.bundle.js"); // Use getURL to resolve the correct path
// script.src = chrome.runtime.getURL("dist/markdown.bundle.js"); // Use getURL to resolve the correct path 
// this.shadowRoot.appendChild(script);
this.ids = 0;
this.tokens = 0;
Expand Down Expand Up @@ -1243,7 +1245,7 @@ class popUpClass extends HTMLElement {
const symbol = symbolFromModel(request.bodyData.model);
this.shadowRoot.getElementById(`${targetId}symbol`).innerHTML = symbol;
this.shadowRoot.getElementById(`${targetId}symbol`).title = request.bodyData.model;
this.shadowRoot.getElementById(`${targetId}header`).innerHTML = `<i> ${JSON.stringify(request.text)} </i>`;
this.shadowRoot.getElementById(`${targetId}header`).innerHTML = `<i> ${JSON.stringify(request.text[0]["content"])} </i>`;

if (this.shadowRoot.getElementById(`regenerate${targetId}`)) {
if (!this.alreadyCalled[targetId]) {
Expand Down Expand Up @@ -1293,7 +1295,7 @@ class popUpClass extends HTMLElement {
var probs = Math.exp(logprobs);
// add to list this.probabilities
// check that probs is not NaN
if (!isNaN(probs)) {
if (probs !== undefined) {
this.probabilities.push(probs);
}
}
Expand Down Expand Up @@ -1416,7 +1418,9 @@ class popUpClass extends HTMLElement {
const model = bodyData.model;
const cost = computeCost(this.tokens + this.tokens_sent, model);
// update in bodyData the final probability in logprobs
bodyData.logprobs = final_prob + " %";
if (final_prob !== undefined){
bodyData.logprobs = final_prob + " %";
}

// focus depending on the case
if (textarea) {
Expand Down

0 comments on commit 68488b6

Please sign in to comment.