In this blog post, I’ll walk you through using Apple Shortcuts to harness OpenAI’s Completions API in macOS and iOS to make your everyday tasks, like summarizing text, proofreading, and translating, easier and quicker. Plus, no app required – just a no-code approach to get the job done fast.
My co-worker Hermann developed a Python app, GPT-3 Companion, to streamline his workflows using GPT-3. I, on the other hand, wanted something more integrated with macOS and iOS, so I took the Shortcuts.app route.
The first step is to get an API key from OpenAI. This is a secret key that you should not share with others or expose by sharing your Apple shortcut with your co-workers or friends. You could also route your requests through your own backend server where your API key can be securely stored, but this is out of scope for this blog post.
The second step is to create a shortcut that can send an HTTP request the OpenAI Completions API with the text input and the parameters. You can use the “Get Contents of URL” action in Shortcuts.app to do this. You will need to specify the URL
https://api.openai.com/v1/completions, the HTTP method (POST), the headers (
authorization: Bearer YOUR_API_KEY), and the body (a JSON object with your text input and parameters).
text-davinci-003 or gpt-3.5-turbo?
Most of the time I’m using the
model, it’s way slower than the newer, streamlined model
gpt-3.5-turbo (that is being used for ChatGPT), but provides good results throughout. The chat model needs another API URL and different request body, too. I’m stumped on how to use the streamlined model with the chat completion URL, as Shotcuts.app keeps crashing for me when I try to build a dictionary in the request body. It seems like I’m not the only one experiencing this issue.
You can play around with
temperature, it’s basically what Bing Chat exposes as three buttons: “Creative”, “Moderate”, “Exact”. Be sure to set
max_tokens to a value that’s practical for you.
The third step is to parse the response and display it in a way that suits your needs. You can use the “Get Dictionary from Input” action in your shortcut to convert the JSON response into a dictionary object that you can access. You need to access the key
You can then use other actions such as “Show Result”, “Speak Text”, “Copy to Clipboard”, or “Share” to present or use the output.
Here are some examples of how I’m using shortcuts for different tasks:
Get a nice summary on what a piece of text is all about. Tip: You can send a long text input and set the
max_tokens parameter (the maximum number of tokens in the completion) to a lower value (such as 50) to get a shorter summary of the text.
You can send a text input with errors or typos and it’ll get fixed. Easy as that.
Let the AI act as a professional editor, fix your mistakes, and improve your writing style.
You can send a text input in one language and it’ll get translated to another. Most of the time this works way better than conventional translation tools like Google Translate or Apple Translate. I started with three shortcuts, one for each target language: English, German, Italian. After a while I came up with a single shortcut that asks for the desired target language with a prompt.
How do I integrate it?
The best part about using Apple Shortcuts is that you can integrate it seamlessly into your operating system. On macOS, you can access your shortcuts from the context menu via Services, which lets you select any text on any app and run your shortcut on it. On iOS, you can access your shortcuts from the Share Sheet, which lets you share any content from any app and run your shortcut on it. Oh, did I mention that shortcuts sync to all of your devices via iCloud?
From now on your shortcuts are in reach whereever you select text, be it a web page or a text input where it can even be replaced.
With Apple Shortcuts and OpenAI’s Completions API, you can create powerful tools for working with natural language without writing any code. Think: endless possibilities for creativity, productivity, and fun.
What happens to my data?
When using one of the shortcuts or submitting text to OpenAI’s APIs, their API data usage policies apply. As of March 8th, 2023, there are two key points to keep in mind:
OpenAI will not use data submitted by customers via our API to train or improve our models, unless you explicitly decide to share your data with us for this purpose. You can opt-in to share data.
Any data sent through the API will be retained for abuse and misuse monitoring purposes for a maximum of 30 days, after which it will be deleted (unless otherwise required by law).
It should go without saying, but: don’t send any critical, private, or confidential texts to a third-party without doing the research on how they handle this kind of data. If necessary, anonymize your text beforehand.
You can download my shortcuts at Apple. When importing them you’ll be asked for your OpenAI API key. How are they working for you? Anything that needs improvement? Are the prompts not useful? What are you using OpenAI’s text APIs for? Let me know in the comments below.
Revised: Depending on the language setting of your operating system, it may be necessary to replace the comma in the
temperature parameter with a period. Reddit commenters managed to figure this out.
Sorry for the header image. Couldn’t spare you the AI feet.