Summarize current Safari tab with ChatGPT

Hallo,
I was wondering if it is possible to "Summarize the current website Safari tab" with the BTT ChatGPT action somehow (as we in Europe do not have Apple intelligence yet)

Thx a lot,
Christian

many things are possible, but I'm not sure whether that is a good idea :wink:

Here is a example, it uses this simple script but requires "Allow Java Script From Apple Events" to be enabled in the Safari Developer Settings

async function summarizeSafari() {

 let result = await runAppleScript('tell application id ("com.apple.Safari") to tell the front document to if it exists then set html to the do JavaScript "document.body.innerHTML;"');
 
 let chatgptResult = await chat_gpt({"user": `can you summarize the content of this webpage?: ${result}`});
 
 await set_string_variable({variableName: "website_summary", to: chatgptResult});
	return chatgptResult;
}

In a real world example you'd probably want to show the result in a floating menu or similar.
This summarizes when pressing cmd+opt+ctrl+0:
summarize.bttpreset (5.9 KB)

The chat_gpt function call is not really documented outside of BTT's Apple Script definition:

<command name="chat_gpt" code="BttChaTG" description="Call ChatGPT">
            <cocoa class="BTTAppleScriptHandler"/>
            
            <parameter name="identifier" code="iDTf" description="An identifier to keep history" type="text" optional="yes">
                <cocoa key="identifier"/>
            </parameter>
            <parameter name="user" code="uSRq" description="The user request (what you ask chatgpt to do)" type="text" optional="yes">
                <cocoa key="user"/>
            </parameter>
            <parameter name="system" code="sSRq" description="Tell ChatGPT how it should behave" type="text" optional="yes">
                <cocoa key="system"/>
            </parameter>
            <parameter name="input" code="iSRq" description="Additional input for your request" type="text" optional="yes">
                <cocoa key="input"/>
            </parameter>
            <parameter name="maxHistory" code="mNRq" description="Max number of history items to include" type="number" optional="yes">
                <cocoa key="maxHistory"/>
            </parameter>
            
            <parameter name="stream" code="StST" description="Stream reply" type="boolean" optional="yes">
                <cocoa key="stream"/>
            </parameter>
            
            
            <parameter name="customURL" code="iuRl" description="Custom URL (to use API compatible services)" type="text" optional="yes">
                <cocoa key="customURL"/>
            </parameter>
            <parameter name="apiKey" code="iSRq" description="API Key (will be saved, so you don't need to pass it every time)" type="text" optional="yes">
                <cocoa key="apiKey"/>
            </parameter>
            <parameter name="model" code="moDl" description="The model to use (default is gpt-4o-mini), others only work if you provide an API key" type="text" optional="yes">
                <cocoa key="model"/>
            </parameter>
            
            <parameter name="shared_secret" code="btSs" description="You can specify a shared secret which must be contained in all Apple Script calls in the advanced BTT preferences." type="text" optional="yes">
                <cocoa key="shared_secret"/>
            </parameter>
            <result type="text" description="The badge label"/>
            
        </command>
        

Thanks a lot Andreas,
I will try that one !

In the meantime I have found a way and used your "text-selction menu" preset examples and got it working. What I did not yet found is a "better" way to get the current URL from the Safari tab.
Thx,
Christian

@Andreas_Hegenberg one other issue I noticed.
When saving the ChatGPT response to a variable (GPTGeneratedTransformation) the output is saved twice like below. Not sure whether that is a small bug ?