Skip to content

Instantly share code, notes, and snippets.

@andyg2
Last active March 24, 2023 17:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save andyg2/ce5a5d1d8177a84bdfb07e454470770a to your computer and use it in GitHub Desktop.
Save andyg2/ce5a5d1d8177a84bdfb07e454470770a to your computer and use it in GitHub Desktop.
Bookmark-let to summarize a web page using GPT-3 - written by GPT-3
javascript: (function () {
var text = document.body.innerText;
var spl = text.split(" ");
if (spl.length > 3000) {
text = spl.slice(0, 3000).join(" ");
}
fetch('https://api.openai.com/v1/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
},
body: JSON.stringify({
"model": "text-davinci-003",
"prompt": "Summarize this page " + text,
"temperature": 0.7,
"max_tokens": 500,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0
})
}).then(res => res.json()).then(data => {
const summary = data.choices[0].text;
const banner = document.createElement('div');
banner.style.position = 'fixed';
banner.style.left = '0';
banner.style.right = '0';
banner.style.top = '0';
banner.style.zIndex = 999999999;
banner.style.background = '#000';
banner.style.color = '#fff';
banner.style.padding = '15px';
banner.innerHTML = summary;
document.body.appendChild(banner);
});
})();
// Or use the minified version
javascript:(function(){var text=document.body.innerText;var spl=text.split(" ");if (spl.length > 3000) {text=spl.slice(0,3000).join(" ");} fetch('https://api.openai.com/v1/completions',{method:'POST',headers:{'Content-Type':'application/json','Authorization':'Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'},body:JSON.stringify({"model":"text-davinci-003","prompt":"Summarize this page " + text,"temperature":0.7,"max_tokens":500,"top_p":1,"frequency_penalty":0,"presence_penalty":0})}).then(res => res.json()).then(data => {const summary=data.choices[0].text;const banner=document.createElement('div');banner.style.position='fixed';banner.style.left='0';banner.style.right='0';banner.style.top='0';banner.style.zIndex=999999999;banner.style.background='#000';banner.style.color='#fff';banner.style.padding='15px';banner.innerHTML=summary;document.body.appendChild(banner);});})();
@andyg2
Copy link
Author

andyg2 commented Jan 27, 2023

Log in to https://beta.openai.com/
Generate an API key here: https://beta.openai.com/account/api-keys
Replace sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx with your API key
Copy script into a new bookmark URL box.
Visit a page and click the bookmark for a brief summary of that page.

Possibilities for other things are endless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment