Certainly! I can guide you through creating an iPhone shortcut that accomplishes this task. The shortcut will:
- Take a URL from the Share menu in Safari.
- Retrieve the text content from the webpage.
- Use OpenAI's ChatGPT to extract notable events.
- Add those events to your Reminders app.
Please note: As of my knowledge cutoff in September 2021, direct integration with ChatGPT via an API requires access to OpenAI's API and an API key. Ensure you have access to the API and are aware of any associated costs or usage policies. Additionally, the Shortcuts app must be updated to support any new actions or functionalities available after 2021.
Prerequisites
- OpenAI API Access: Sign up for an API key at OpenAI's website.
- Shortcuts App: Ensure the Shortcuts app is installed and updated on your iPhone.
- Internet Connection: Required for making API calls and fetching webpage content.
Step-by-Step Guide
1. Create a New Shortcut
- Open the Shortcuts app on your iPhone.
- Tap the "+" icon to create a new shortcut.
- Tap "New Shortcut" to begin editing.
2. Configure Shortcut to Accept URLs from Share Sheet
- Tap the settings icon (looks like sliders) at the top right.
- Enable "Show in Share Sheet."
- Under "Accepts", make sure "URLs" is selected.
- Optionally, name your shortcut (e.g., "Extract Events to Reminders").
3. Get the Webpage Content
- Tap "Add Action."
- Search for "Get Contents of URL" and add it.
- This action fetches the HTML content from the shared URL.
- Add the "Get Article from Web Page" action.
- This extracts the main article content from the webpage.
- Add "Get Details of Articles" action.
- Select "Body" to extract the text content.
Alternatively, if "Get Article from Web Page" is unavailable:
- Use "Get Contents of URL".
- Add "Make Markdown from Rich Text" to extract text.
4. Prepare the Prompt for ChatGPT
-
Add a "Text" action.
-
In the text field, write your prompt. For example:
Extract the notable events from the following text and list them as bullet points suitable for reminders:
[Insert Extracted Text Here]
-
Replace [Insert Extracted Text Here] with the variable containing the webpage text.
- Tap the variable magic wand icon, and select the "Body" or the result from the previous action.
5. Set Up the API Call to OpenAI
- Add "Get Contents of URL" action.
- Configure it as follows:
-
URL: https://api.openai.com/v1/chat/completions
-
Method: POST
-
Headers:
Content-Type: application/json
Authorization: Bearer YOUR_API_KEY (Replace YOUR_API_KEY with your actual API key)
-
Request Body: Set to JSON and input:
{
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "user",
"content": "Your Prompt Text Here"
}
]
}
-
Replace "Your Prompt Text Here" with the text from your "Text" action. Tap the variable icon to insert it.
6. Parse the API Response
- The API response will be in JSON format. You need to extract the generated text.
- Add "Get Dictionary Value" action.
- Get the value for the key "choices" from the API response.
- Add "Get Item from List" action.
- Get Item At Index 1 (the first item in the list).
- Add another "Get Dictionary Value" action.
- Get the value for the key "message".
- Add another "Get Dictionary Value" action.
- Get the value for the key "content".
- This should be the text generated by ChatGPT.
7. Split the Text into Individual Events
- Add "Split Text" action.
- Text: The content from the previous action.
- Separator: Choose
New Lines or type \n.
- This will create a list of events.
8. Add Events to Reminders
- Add "Repeat with Each" action.
- Repeat with each item in: the result from "Split Text".
- Inside the repeat loop:
- Add "Add New Reminder" action.
- Title: Repeat Item (the current item from the loop).
- Optionally, set a due date, choose a list, or set alerts as needed.
9. Test the Shortcut
- Tap "Done" to save the shortcut.
- Open Safari and navigate to a webpage.
- Tap the Share button.
- Select your shortcut from the Share Sheet.
- The shortcut should run, process the webpage, and add events to your Reminders app.
Additional Tips
- API Key Security: Do not hardcode your API key if you share this shortcut. Consider storing it securely or prompting for it when the shortcut runs.
- Error Handling: You may want to add actions to handle errors, such as network issues or invalid API responses.
- Prompt Refinement: Adjust the prompt in the "Text" action to better suit the type of content you're processing.
- Usage Costs: Be mindful of API usage costs and monitor your usage on the OpenAI dashboard.
- Privacy Considerations: Ensure you're comfortable sending webpage content to OpenAI's API.
Sample Prompt for the Text Action
Extract the notable events from the following text and list them as bullet points suitable for reminders:
[Webpage Text]
Replace [Webpage Text] with the variable containing the extracted text from the webpage.
Summary of the Shortcut Actions
- Get Contents of URL (from shared URL)
- Get Article from Web Page
- Get Details of Articles (retrieve "Body")
- Text (prepare the prompt for ChatGPT)
- Get Contents of URL (send API request to OpenAI)
- Get Dictionary Value (extract "choices")
- Get Item from List (get first item)
- Get Dictionary Value (extract "message")
- Get Dictionary Value (extract "content")
- Split Text (split response into list)
- Repeat with Each (iterate over events)
- Add New Reminder (for each event)
Example of the Actions in the Shortcuts App
- Shortcut Input (URL from Share Sheet)
- Get Contents of URL (Input: Shortcut Input)
- Get Article from Web Page (Input: Contents of URL)
- Get Details of Articles (Get "Body")
- Text (Prompt with embedded article body)
- Get Contents of URL (POST request to OpenAI API)
- Headers: Content-Type, Authorization
- JSON Body: model, messages
- Get Dictionary Value ("choices")
- Get Item from List (Item at Index 1)
- Get Dictionary Value ("message")
- Get Dictionary Value ("content")
- Split Text (Separator: New Lines)
- Repeat with Each (Items: Split Text)
- Add New Reminder (Title: Repeat Item)
Final Notes
Creating this shortcut requires careful attention to detail, especially when configuring the API request and parsing the response. Be sure to test each part of the shortcut individually to ensure it's working correctly before moving on to the next step.
If you encounter any issues or need further assistance, feel free to ask!