/ffs-ungpt

use chatgpt to summarize selected text on a page... every single page will be 20 times longer than it should.. so just UNGPT it

Primary LanguageJavaScript

example

example

click on options to set your api key

I am preparing for the future when most of the internet is generated, so I wanted an extension that summarises pages, but I don't trust other extensions to inject js in the pages I open, so I had to write one myself. If you are like me and prefer to run only extensions you wrote (and ublock), this one is like 30 lines of code and you can vet it yourself, the gist of the injected code when you press the button:

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('Authorization', 'Bearer ' + api_key);
    document.body.innerHTML = 'asking...'
    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
                ...    

    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);
    ...

The whole experience has been absolutely surreal, I made https://github.com/jackdoe/emacs-chatgpt-jarvis few days ago, and now I speak to emacs, which asks chatgpt with my question and region selection, so I just asked it to write an extension for chrome that does api call on click, there were few mishaps with manifest version 2 and 3 and etc, but in the end in like 15-20 mins I managed to have something working and usable.

This last few months have been crazy, if someone told me I will be talking to emacs and using AI to summarize content on the web half a year ago I would've told them they are crazy.

Using whisper to talk to chatgpt to make a chrome extension that will use chatgpt to summarize text that will be likely generated by chatgpt...