Connecting Siri to ChatGPT

ChatGPT is great for a lot of things, one of which is answering questions on a broad amount of subjects and categories, and getting expert, detailed answers --- something that Apple's OS: IOS's "personal voice assistant" - Siri doesn't do very well, and most of the times will just answer with: "Here's what I found on the web" - displaying the first few results of a web search of your question.

I find the fact that you have to go to the ChatGPT webpage, log in, and type in a question - a pretty big effort compared to the ease and fast availability of just saying out loud: "Hey Siri" and asking a question.

I kept wondering if there's a way for me to have this connection between ChatGPT and Siri - so that I would be able to ask Siri a question - and let her answer actually be the output of ChatGPT - for that answer. So... I asked ChatGPT how can I make it happen :) and it gave me back a concrete guide about how to achieve it. It had some minor outdated technical details (as is usual with ChatGPT, being based on dataset models that were written up to 2021...).

This guide will detail the steps to make it happen.
You will need your own OpenAI API key - which you can generate on the platform website - the free version is limited in use - so for it to work indefinitely you should sign up for the paid version.

Step-by-step guide

The basis of this method is the Shortcuts app, available by default for free since iOS version 13. This app has a built-in system that uses customizable "actions" that can be defined to run in sequence, with inputs and outputs, including the use of "variables" that reference the outputs of previous steps and be grouped as a single "Shortcut" that can later be re-used on your device.

  1. Start by running the app.

  2. Click the Plus icon on the upper right corner to define a new Action.
    You can rename it to something like: "Ask Chat GPT". The title you use here is going to be the text you need to speak later after triggering Siri, to be able to run this Shortcut.

  3. To add an action - click the "Add Action" button, or use the "Search for actions" bar at the bottom. The first action you need to add is "Dictate text".

  4. Next, add the `Get contents of URL` action - this action will actually start an HTTP network request to the OpenAI API URL. You need to define the right settings and variables:

    • Add a header with Authorization as the key, and the value should be Bearer <your openai API key here>

    • Request body should contain the following keys and values:

      model: text-davinci-003
      max_tokens : 2048 (or any other number to limit the number of tokens that can be used).
      prompt: For the value here you should use the Dictated Text "magic variable" - this variable refers to the output of the previous action step - the Dictate Text action.

  1. The response from the HTTP request of OpenAI's API is a JSON response; To parse it correctly - the next step is to add the Get dictionary from input action - use the magic variable: Contents of URL which is the output of the previous Get contents of URL step.

  2. Next you will need to retrieve the actual text value of ChatGPT's response, this should be in the first item of an array called choices under a property named text - to do that - use the Get Value from Key in Dictionary action. For the value put choices.1.text (the syntax here is 1-based, as opposed to the commonly-used 0-based).

  3. The final action step is to simply have the system/Siri speak the returned answer. Add the Speak action - and use the Dictionary Value magic variable for it.

That's it.

Trying it out

Now, to use the action, trigger Siri by saying "Hey Siri", then simply speak the name of the action (e.g. "Ask Chat GPT") - Siri will then ask: "What is the text?" - then you can simply speak your question - and after a while, you will see a textual representation of the answer from ChatGPT - and Siri will read it out loud for you!

Note that each time you use this Shortcut, as mentioned, an API call is made to OpenAI's API using your API key, and will of course use from your quota - so make sure you don't spend too much of it :)