Using Apple Shortcuts, Perplexity's API and OpenAI API to generate cards and link them

Hi, everyone I am new here although I have been dabbing with Supernotes for a while now and I like it, I am just kind of waiting for it to click for me fully ;). However, I built this workflow yesterday and thought I would share it in case parts of it were useful to anyone else. I am also not sure it aligns with Tobas and Connors thinking on AI however as the principles can be modified I thought it was worth it.

What are we aiming to do?

The aim of this workflow is to:

  1. Take a webpage URL
  2. Obtain a summary of the page
  3. Obtain an expansion on the base subject
  4. Get a list of upto 5 follow up questions
  5. Obtain answers to those questions

The tools we are going to use

  1. Apple Shortcuts
  2. Actions - This is an add-on to Shortcuts and makes things easier
  3. Perplexity - AI Web Search
  4. OpenAI - ChatGPT
  5. Supernotes - of course

Note: I wanted this workflow to work on MacOS as well as Mobile so I have used the API for Perplexity and OpenAI if you only need it to work on Mobile it is way easier as the ChatGPT and Perplexity Apps tie into Shortcuts.

The Shortcut

Apple Shortcuts is amazing in at least two ways:

  1. It is very powerful and makes some things easy
  2. It is horrible to use!

I will go through the Shortcut step by step:

  1. We start with what and how the Shortcut will accept:

  2. I have used Actions to store my API Keys as Global Variables so we are going to retrieve those, you can get them into the Shortcut however works best for you:


    3. We need the body and the title for the webpage, again we are going to use Actions this time to get the title (it just seems a little more reliable than the built-in option):

  3. This section just sets the API URLs we are going to use:

  4. Now we get into the nitty gritty, here we want to get the page summary so we are going to send the body of the page to OpenAI and ask it to summarise the page


    As you can see I am using gpt-3.5, 4o works better for this part of the workflow if the added expense is not an issue.

  5. Now we need to actually get the summary out of the response to be honest I had never done this in Shortcuts before and it was painful there may be an easier way but I tried a few and this five-step process is what worked for me:


    A. We Parse the response into a dictionary I have used Actions parser as it was more reliable than the Shortcuts one.
    B. We next get the value for the choices key which is an array
    C. As choices is an array we need the first item from that list
    D. Now we need the message key
    E. Finally we can get the content key which is the part you want

For those that are interested what you get back from OpenAI that we have just pulled apart looks like this:

{
"object": "chat.completion",
"id": "chatcmpl-9YDz4OvK3IUDcJyjZJsXOGPUchhEY",
"model": "gpt-3.5-turbo-1106",
"system_fingerprint": "fp_482d920018",
"created": 1717943934,
"choices": [
{
"index": 0,
"message": {
"content": "# Summary of \"Electronic Signatures for Small Businesses Guide\"\n\nElectronic signatures have become a crucial tool for small businesses, streamlining the signing process, saving time, and reducing costs. They are legally recognized and can be used for various purposes, including sales contracts, vendor agreements, and HR processes. Implementing electronic signatures can save a business time, reduce costs, enhance security, and simplify contract management.\n\nWhen choosing an electronic signature solution, businesses should consider factors such as automation, security, scalability, integration, and pricing. The guide highlights seven top electronic signature tools for small businesses, along with their relevant features, pricing, pros, and cons. The tools featured include SignWell, Jotform Sign, Foxit eSign, DocuSign, Formstack Sign, OneSpan Sign, and Signable.\n\nThe guide emphasizes the importance of selecting the right electronic signature solution to improve document management, with SignWell highlighted as a solution that offers features like workflow automation, reminders, and audit trails to streamline document processes and ensure quick and secure document signing.\n\nOverall, the guide provides a comprehensive overview of electronic signatures for small businesses, showcasing how choosing the right solution can enhance efficiency and productivity for businesses of all sizes.",

"role": "assistant"
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 3139,
"completion_tokens": 242,
"total_tokens": 3381
}
}
  1. With the summary we now create our first Supernotes card first off we create the body of our new card in a text block:

  2. We now have all the parts we need to create the card

  3. We want the Card ID of our new card as we are going to use it later on in the workflow so we need to pull it from the response, thankfully it is not hidden quite as deep as the OpenAI content and it only needs three steps to retrieve:


    A. We Parse the response
    B. As there are no arrays we can get to the Key we want in one request
    C. I found it easier to put the card ID in a variable for use later.

  4. The next stage is to prepare for our first Perplexity call for those who don’t know it is a search engine and AI combined and it also provides API access


    A. When tidied my Shortcut I failed to move this block to the top it is just the URL we are going to send the Perplexity request to.
    B. This is the prompt we are going to send to Perplexity as with any AI the better your prompt the better the information you will get back and I am not great at writing in general so others will be able to write a much better prompt than me.

  5. Armed with our URL and prompt we can now send our request:


    You may notice that the request is very similar to the OpenAI one which is useful.

  6. Also, the response has the same structure (good and bad):

  7. We now have what we need to make our next Supernotes card, we also want to make it a child of our first card (remember we extracted the CardID):

  8. We want the card ID from this card as well so we extract that as we did for the first card:

  9. You may remember we asked Perplexity for a list of upto 5 follow up questions well we should really do something with them but they are buried in the body of our ‘expansion’ text which is next to useless to us so we make our final call to ChatGPT and send the Perplexity generated content off and ask for the questions to be extracted and put in a list for us:

Note: There is another way around this which is to ask the AI to separate the list on the initial ask by requesting that it respond in JSON with the body in one key and the list as a separate array however this is more reliable with more complex prompts including examples and also the new AI models have started wrapping the JSON object in code blocks which you then need to remove so with the cost of gpt3.5 these days and Shortcuts limitations this is the easier way to achieve the same thing.

  1. Now we have a list of questions we are going to loop through each one and ask Perplexity to answer it however before we do that we need to tidy our list and make sure there are no blank lines, to do this we again use Actions as that has a pre-built tool for the job, we then split our list by line:
  2. The final step in our workflow is to create cards in Supernotes with the question answers and make them children of our original summary card and our expansion card we do that in a loop:

    Everything is basically duplications of what we have done before except this time we are linking to two parents rather than one (I have done this mainly as a demonstration):

What do we end up with


Issues and Limitations

  • The Perplexity API does not seem at the moment to return valid sources, I believe this feature is in Beta.
  • Permissions, I seem to get asked for a lot of permissions this has something to do with Apple Shortcuts interacting with URLs and not sure if it has to do with my setup or a general thing.

Hopefully, there is something useful in the above I have tried to explain all the parts but if anything is unclear please do feel free to reach out

5 Likes

Awesome walkthrough! Thank you for putting it together.

Although yes, I’d say this might not 100% align with the direction we plan to take AI in Supernotes going forward, the whole reason we made the Supernotes API open from the beginning is because we want people like you to be able to do whatever they want with their cards, including powerful generative AI workflows like this one.

It would be cool if you could get the LLM to try to pick a suitable color for the cards based on content, rather than just hard-coding it.

I especially like how you’ve decided to create an entire mini-hierarchy from a single initial source. I probably would’ve just made it a single card, but I actually like this solution much better!

3 Likes