yohasebe/openai-chat-api-workflow
À propos
🎩 An Alfred 5 Workflow for using OpenAI Chat API to interact with GPT models 🤖💬 It also allows image generation/editing/understanding 🖼️, speech-to-text conversion 🎤, and text-to-speech synthesis 🔈
Design et médiasWhat you can do
- Ask from anywhere: type a question in Alfred, or send text selected in any app. See Asking Questions.
- Keep the whole conversation in view: answers stream into a web UI on your Mac, where you can continue the chat, edit your last message, and export or import the conversation. See The Web UI.
- Ask about files and your screen: attach a PDF, an Office document, an image or code, or select part of the screen and ask about it. See Files and Screen Captures.
- Create and refine images: generate an image, then keep describing changes until it looks right, or edit an image of your own. See Images.
Progression mesurée des étoiles
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- Historique en cours
Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.
README.md
OriginalOpenAI Chat API Workflow for Alfred
🎩 An Alfred 5 workflow that brings OpenAI's models to your Mac: ask questions from Alfred or from any app, continue the conversation in a web UI that runs on your Mac, and work with files, images and your voice.
📦 Download OpenAI Chat API Workflow (version 6.1.0)
📝 See the Change Log for what changed in each version.

What You Can Do
- Ask from anywhere: type a question in Alfred, or send text selected in any app. See Asking Questions.
- Keep the whole conversation in view: answers stream into a web UI on your Mac, where you can continue the chat, edit your last message, and export or import the conversation. See The Web UI.
- Ask about files and your screen: attach a PDF, an Office document, an image or code, or select part of the screen and ask about it. See Files and Screen Captures.
- Create and refine images: generate an image, then keep describing changes until it looks right, or edit an image of your own. See Images.
- Use your voice: speak a prompt, and have answers read aloud. See Voice.
- Keep your key and data under control: requests go from your Mac to OpenAI, the API key can stay in 1Password or the keychain, and no extra software is needed. See Privacy and Data.
Getting Started
Requirements
- Alfred 5 with the Powerpack
- An OpenAI API key
No other software is needed, except the optional 1Password CLI (see API Key) and SoX for the Terminal recorder (see Voice).
Installation
- Download and open OpenAI Chat API Workflow
- Enter your OpenAI API key in the workflow's settings (see API Key to keep it in 1Password or the keychain instead)
- Allow Alfred in
System Settings→Privacy & Security→Accessibility
To replace a saved key later, type the keyword openai-set-key followed by the new key.
Hotkeys
Hotkeys are set in the workflow editor in Alfred Preferences: double-click a light purple hotkey element to assign keys.
- Open webui (recommended)
- OpenAI Direct Query
- Selected text to OpenAI
- Screen capture for image editing
- Screen capture for image understanding
- Speech-to-Text (the Terminal recorder; see Voice)
- Text-to-Speech (Selected Text)
- Stop Text-to-Speech (Selected Text): give it keys different from Text-to-Speech
Asking Questions
From Alfred
- Type
gpt, a space, and your question (e.g., "gpt what is a large language model?"), or use the OpenAI Direct Query hotkey - Type
openai, a space, and your text, then choose a mode - Type your text and choose
OpenAI Queryfrom Alfred's fallback searches
The answer opens in the web UI (in Alfred's Large Type if the Stream output setting is off). A question asked this way starts a new conversation; to continue one, reply on the chat screen.
From selected text
Select text in any app, then press the universal action hotkey and choose OpenAI Query, or use the Selected text to OpenAI hotkey. Pick a mode:
- Direct Query: send the text as it is
- Prepend Text + Query / Append Text + Query: add a line before or after the text, such as "Translate into French:"
- Generate Image: use the text as an image prompt
The Web UI
Open the web UI with the keyword openai-webui or the Open webui hotkey. It runs on a small server inside the workflow and opens in your browser.
Text Query / ChatandImage Generation / Editingswitch between the two modes of the start screenSend Message(or ⌘/Ctrl+Enter in the prompt box) sends the prompt;Cancelstops waiting for a response, though OpenAI may still complete and bill the requestClearempties the prompt box;Start New Chatdiscards the conversation;Edit Messageon your last message lets you rewrite it and send it againImport Fileattaches a file;Voice Inputrecords a prompt;Play TTS/Stop TTSread text aloud and stopSet VoiceandSet Auto Speechchange text-to-speech settings;Open Configopens the workflow settingsExport DataandImport Dataon the chat screen, andImport Chaton the start screen, save a conversation to a JSON file and load it again. The file holds the messages and the conversation's settings, such as the model; attached files and generated images are not included. Importing replaces the current chatClear Cacheremoves cached files (see Privacy and Data)
The model and its reasoning effort are chosen in the workflow settings, and can be changed for a conversation on the start screen.
- The default model is an inexpensive one that handles everyday questions well. Switch to a more capable model for harder tasks.
- Reasoning effort sets how long the model thinks before answering.
noneanswers fastest; higher values, up toxhighormaxwhere the model accepts them, think longer and take longer. The web UI offers only the values the selected model accepts, and the workflow falls back to the model's default if a saved combination is not accepted. - Flagship
promodels and theo-series are not included: this workflow is made for quick turnaround. - When OpenAI retires a model, it is removed from the workflow, and a saved setting naming it falls back to the default.
Light and dark
The Web UI mode setting chooses light, dark, or auto, which follows macOS.
Browser
The web UI opens in your default browser. In the following browsers and in Safari, a tab that already shows the web UI is reused; any other browser opens a new tab each time.
- Google Chrome (Stable, Beta, Dev, etc.)
- Microsoft Edge (Stable, Beta, Dev, etc.)
- Brave Browser
Safari is used if the default browser cannot be detected. If the web UI does not work as expected after you change the default browser, restart its server with the keyword openai-restart-server.
Files and Screen Captures
Attach a file with Import File in the web UI and ask about it.
- Images: PNG, JPG, JPEG, GIF, WebP
- Documents: PDF, Word (.doc, .docx), ODT, RTF
- Spreadsheets: Excel (.xls, .xlsx), CSV, TSV
- Presentations: PowerPoint (.ppt, .pptx)
- Text and code: .txt, .md, .json, .html, .xml, .py, .rb, .js, .ts, .java, .c, .cpp, .go, .rs, .swift, .sql, and many more
Files can be up to 50MB. In Finder, you can also send a file with the OpenAI File Input universal action.
To ask about something on your screen, type openai-vision (or use the Screen capture for image understanding hotkey) and drag over the area. You can then type a question in Alfred, or leave it empty, and the answer opens in the web UI (in Large Type if Stream output is off).
Images
Generating
Choose Image Generation / Editing on the start screen, or use the Generate Image mode from Alfred or selected text. The image settings (model, size, quality, content moderation and background) are below the mode tabs.
An example made with the prompt "A cozy reading nook beside a rainy window: an armchair with a knitted blanket, a stack of books and a mug of tea on a small wooden table. Soft watercolor illustration.":

The image models differ in speed and in how precisely they follow edits; the default is a fast one for everyday images. The xhigh and max qualities use more output tokens and can take over a minute. To use the GPT Image models, you may need to complete the API Organization Verification in your developer console.
Refining
Below a generated image, describe what to change and press Refine Image (or ⌘/Ctrl+Enter). The latest image is used as the starting point each time, and every step stays on the page.
The example above, refined with "Make it evening with warm lamp light, and add an orange cat sleeping curled up on the armchair. Keep everything else the same.":

Editing your own image
Attach an image with Import File on the start screen and describe the change. In Text Query / Chat mode, press Edit Image (Send Message asks about the image instead); in Image Generation / Editing mode, press Send Message. You can also start from Finder with the OpenAI Image Edit universal action, or from a screen capture with the keyword openai-capture-edit or the Screen capture for image editing hotkey.
Voice
Speaking a prompt
Press Voice Input in the web UI, speak, and press Stop. The recording is transcribed into the prompt box, where you can check it before sending. A Save Recording button appears for about 10 seconds if you want to keep the audio. Voice input clears an attached file, so attach files after recording.
There is also a recorder that runs in Terminal, started with the keyword openai-speech or the Speech-to-Text hotkey. It needs SoX (rec).
Transcribing an audio file
Select an mp3, mp4, m4a, wav, flac, webm or ogg file (up to 25MB) in Finder and choose the OpenAI Speech-to-Text universal action. The transcript is plain text.
With the Audio to English setting, transcripts of recordings and audio files are also translated into English, which adds a request to a text model. A transcript over 16,000 bytes (about 5,000 Japanese characters) is not translated. If translation fails, the audio is kept and the message says where the transcript was saved, if it could be.
Having text read aloud
- Press
Play TTSin the web UI, or turn onSet Auto Speechto read every answer - Select text in any app, press the universal action hotkey, and choose
OpenAI Text-to-Speech - Type
openai-tts, a space, and the text
openai-set-voice chooses the voice. Each reading is a separate API request. Speech that departs from the text, such as a reply instead of a reading, is not played, and a message says why.
Settings
Open the settings with Open Config in the web UI or the keyword openai-config. Settings marked (web UI) can also be changed on the web UI's start screen for the conversation you start there. Names below are as they appear in the settings.
OpenAI API key: your key, or a reference to where it is kept. Alfred stores this setting in the workflow's folder, which is synced if you sync your Alfred preferences. A reference keeps the key itself out of that folder:
op://Vault/Item/fieldreads the key from 1Password with the 1Password CLI. The CLI is separate from the 1Password app: install it withbrew install --cask 1password-clion every Mac that runs the workflow, and turn on Settings › Developer › Integrate with 1Password CLI in the app. To check a reference without showing the key:op read "op://Vault/Item/field" >/dev/null && echo OKkeychain:followed by a name reads the key from a generic password in your keychain whose service is that name. For example, withkeychain:openai-api, add it withsecurity add-generic-password -s openai-api -a openai -w(you are prompted for the key) on each Mac that runs the workflow, and check it withsecurity find-generic-password -s openai-api -w >/dev/null && echo OK
A key read through a reference is used for the request and not stored. If it cannot be read, the result says why.
Base URL: change it only if you use a different endpoint. Text-to-speech always goes to OpenAI. (default:
https://api.openai.com/v1)
Chat
- Model and Reasoning effort (web UI): see Choosing a model
- Memory span (web UI): how many recent messages are sent as context, counting the new one. More messages use more tokens. The start screen's value applies to the first request; replies on the chat screen use this setting. (default:
20, range2–100) - System content: instructions sent with every query
- Add emoji to response (web UI): asks the model to add fitting emoji (default: enabled)
- Max characters: the longest prompt accepted (default:
100000) - Timeout (sec): how long to wait for a reply when Stream output is off (default:
240). Raise it for a high reasoning effort with streaming off. Streaming does not use it: a streamed reply may take up to 12 minutes.
Images
- Image generation model, Image size for GPT Image, Image quality for GPT Image, Moderation for GPT Image, Background for GPT Image (web UI): the defaults for new images
Voice
- Text-to-speech model, Text-to-speech voice, Text-to-speech speed (0.25 to 4.0) and TTS instructions (how the text is spoken, such as the tone)
- Automatic text to speech: read every answer aloud (default: disabled)
- Transcription Model
- Audio to English: translate transcripts into English (default: disabled)
- Processes after recording: what the Terminal recorder does when it stops
Web UI and other
- Stream output: show answers as they are written. When off, answers are shown in Alfred's Large Type. (default: enabled)
- Web UI mode:
light,darkorauto(default:auto) - Hide speech buttons: hide the voice and text-to-speech buttons (default: disabled)
- Save folder: if set, text results are saved here as Markdown files and generated images are copied here. The folder must exist, and may not be inside the workflow folder or its cache. (default: not set)
- Sound: play a sound when a response or an error arrives (default: disabled)
- Debug mode: add details to error messages (default: disabled)
- Web UI port and Streaming port: change either if another program uses it (defaults:
8787,8788) - Loopback address:
127.0.0.1orlocalhost; try the other if the web UI does not load (default:127.0.0.1)
Privacy and Data
- The web UI's server listens on this Mac only. Requests go from the workflow to OpenAI (or to the Base URL you set); OpenAI does not use data sent through its API for training by default.
- Files attached to a question are uploaded with OpenAI's Files API, and the workflow asks OpenAI to delete each one after the response. An image sent for editing goes to the image edit request itself and is not stored in your Files storage. If that request fails, for example when the network drops, the file may remain in your OpenAI storage.
- Uploaded files, audio, generated images and pages are cached in the workflow's cache folder. Files older than 7 days are removed when the server starts, and
Clear Cacheremoves them on demand. The current conversation and the images it shows are kept. Generated images are kept only until you start a new image session, whichStart New Chatand reopening the web UI both do, so use the Save folder setting or download the ones you want. - Type
openai-usageto open OpenAI's usage page.
Troubleshooting
- A port is in use: choose another free port above 1023 for Web UI port or Streaming port in the settings.
- The web UI does not load: restart its server with
openai-restart-server, or switch the Loopback address setting. - No error notifications appear: allow notifications for Alfred in
System Settings→Notifications. - Logs:
workflow.login the workflow's cache folder, rotated at about 1MB (up to 5 files). - The server stops after a while: it stops 2 hours after a web UI page was last opened or reloaded; working in a page that is already open does not count. Change this with the
http_keep_aliveenvironment variable (seconds), found under[x]at the top right of the workflow settings.http_server_waitsets how long to wait after starting the server before the page opens (default:2.5).
Author
Yoichiro Hasebe ([email protected])
License
The MIT License
Disclaimer
The author assumes no responsibility for any potential damages arising from the use of this software.
Explorer des projets similaires
Chargement…