5 ms·
ChatGPT API can be a lot more useful when you use it in context. Like selecting a chunk of text on any web page, right-click, and select summarize/translate/ELI
by 1xdevloper 4y ago
ChatGPT API can be a lot more useful when you use it in context. Like selecting a chunk of text on any web page, right-click, and select summarize/translate/ELI5. Or executing your own custom prompt.
I'm building a chrome extension called SublimeGPT[1] to do exactly that. Right now, you can log in to your existing ChatGPT account, go to any page, and open a chat overlay. Next version will have the context options.
[1] https://sublimegpt.com https://sublimegpt.com
- throwaway71271 4y agoyou can also just use bookmarklet (or multiple defining different prompts): function __summarize(api_key) { var selection = window.getSelection().toString(); if (selection.length == 0) return; var xhr = new XMLHttpRequest(); xhr.open("POST", "https://api.openai.com/v1/chat/completions"); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.setRequestHeader('Authorization', 'Bearer ' + api_key); window.scrollTo({top: 0}) document.body.innerHTML = 'asking...' document.body.style.backgroundColor = "white"; document.body.style.color = "black"; document.body.style.fontFamily = 'monospace' document.body.style.fontSize = "16px" document.body.style.margin = "auto" document.body.style.padding = "1rem" document.body.style.maxWidth = "60rem" xhr.onreadystatechange = function() { if (xhr.readyState == 4) { if (xhr.status == 200) { var response = JSON.parse(xhr.responseText); var summary = response.choices[0].message.content; document.body.innerHTML = summary } else { try { var e = JSON.parse(xhr.responseText); document.body.innerHTML = e.error.message } catch(e) { document.body.innerHTML = 'error asking.. check the console' console.log(xhr) } } } } var data = JSON.stringify({ "model": "gpt-3.5-turbo", "messages": [ {"role": "system", "content": "Summarize the following text as if you are Richard Feynman"}, {"role": "user", "content": selection} ] }); xhr.send(data); } (i have it as bookmarklet here https://gist.github.com/jackdoe/ce5a60b97e6d8487553cb00aa43fe0c6#file-chatgpt-summarize-bookmarklet https://gist.github.com/jackdoe/ce5a60b97e6d8487553cb00aa43f... change "YOUR API KEY HERE" with your key)
- 1xdevloper 4y agoAnd when you want to create/edit/delete/import custom prompts? AI is a commodity now and a great UX drives adoption.
- throwaway71271 4y agothen you download 1xdeveloper's extension :) though i just copy and paste the bookmarklet and change the prompt
- 1xdevloper 4y agoHehe, I'll put it on github when it reaches 1.0.
- weird-eye-issue 4y agoSorry but I have to ask why the XMLHttpRequest instead of fetch?
- throwaway71271 4y agono reason really, at the time i was not sure if the api will be too slow (like the chat web ui) and i will need progress bar, but by the time i found out i dont, the code was already written
- weird-eye-issue 4y agoYou can use streaming