Last active
March 24, 2023 17:48
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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);});})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 keyCopy 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.