This instruction explains how to create a Quick Action in macOS that can send selected text directly to your preferred large language model.
The workflow is inspired by this Hacker News post of eliya_confiant: https://news.ycombinator.com/item?id=39592297.
To follow this guide, you will need the following tools:
- glow: for rendering markdown from CLI
- Ollama: a local LLM interface (Option 1)
- llm: for CLI integration (Option 2)
Run the following command to install them:
brew install glow
brea install ollama # Option 1
brew install llm # Option 2
Pull a desired language model from Ollama. I recommend trying out different models for personal use.
For example, use llama3.1
for general-purpose tasks or llama3.2:3b
for instant responses.
If you have an OpenAI API key or if you prefer using gpt4all, follow the instructions on llm's README.
- Pull the model files, for example:
ollama pull mistral
- Create
extra-openai-models.yaml
under$HOME/Library/Application Support/io.datasette.llm
. - Add the following settings to the file:
- model_id: mistral
model_name: mistral
api_base: "http://localhost:11434/v1/"
- You can add as many models as you want. Simply change the
model_id
andmodel_name
.
- Open Automator, create a new
Quick Action
. - Find
Run Shell Script
from the sidebar and drag it to the configuration panel. - Copy the script from
llm-agent.sh
, and paste it into theRun Shell Script
action's text area. - Save. Now you can select text from any application, right-click, and choose your new Quick Action to send the text to your preferred LLM.
- Open System Settings.
- Go to
Keyboard
and openKeyboard Shortcuts...
. - From
Services
>Text
, find the Quick Action you just created. - Set your desired keyboard combination, and press
Done
.
The result is automatically copied to your clipboard. If you want to see the result in rendered markdown, remember to keep your terminal app open.