OpenAI Text-Completion Workflow for Alfred
Alfred 5 Workflow for using OpenAI GPT-3.5 and GPT-4 with Text Completion/Chat API. It also allows image generation using the DALL-E API.
Downloads
Current version: 1.10.3
Change Log
- 1.10.2:
Enhance Prompt
supports bothgpt-4
andgpt-3.5-turbo
. - 1.10.0:
Enhance Prompt
option for image generation mode added - 1.9.1: 1024x1024 image generation issue fixed
- 1.9.0: Image generation using DALLΒ·E API supported
- 1.8.2: New models (
gpt-3.5-turbo-0613
,gpt-3.5-turbo-16k-0613
,gpt-4-0613
) supported - 1.8.1: Added option to change base URL of the OpenAI API
- 1.8.0: Custom CSS feature added
- 1.7.0: Improved UI
- 1.6.9: GPT-4 models (e.g.,
gpt-4
) supported - 1.6.7: Fixed an error that occurred for some users
- 1.6.6: Debug mode added that outputs error messages when problems occur
- 1.6.5: Automatic detection of Pandoc installation
- 1.6.4: Supress "Please Wait" message feature
- 1.6.3: OpenAI Textbox feature updated
- 1.6.0:
GPT-3.5-turbo
model is set to the default - 1.6.0: ChatGPT API support
- 1.6.0: HTML output option (using Pandoc) is enabled by default
- 1.6.0: check-for-update command removed (in preparation for Alfred Gallery inclusion)
Dependencies
To start using this workflow, you must set the environment variable apikey
, which you can get by creating a new OpenAI account. See also the Configuration section below.
You will also need to install the pandoc
command. This will allow this workflow to convert the Markdown response from OpenAI to HTML and display the result in your default web browser with syntax highlighting enabled (especially useful when using this workflow to generate program code).
Installing Pandoc will be just a few clicks once this workflow has been included in the Alfred Gallery. For now, install Pandoc using homebrew. Once homebrew is installed, run the following command.
brew install pandoc
How to Execute This Workflow
π Using Selected Text
You can select any text on your Mac and send it to the workflow:
- Method 1: select text β universal action hotkey β select
OpenAI Query
- Method 2: set up a custom hotkey to
Send selected text to OpenAI
β¨οΈ Using Alfred Textbox
You can enter a query text directly into Alfred textbox:
- Method 1: Alfred textbox β keyword (
openai
) β tab β input query text - Method 2: Alfred textbox β input query text β select fallback search (
OpenAI Query
)
π Using Text Box in Default Web-browser
You can open a web interface (see the figure below).
- Method 1: Alfred textbox β keyword (
openai-textbox
) - Method 2: set up a custom hotkey to
Open web interface
General Query
The input text is used as a prompt to the OpenAI text-completion API. The original input text can be prepended or postfixed with instructional text to compose a complex query to be given to the API.
Direct Query
The input text is directly sent as a prompt to the OpenAI text-completion API.
Prepend Text + Query
After the initial text is entered, the user is prompted for additional text. The additional text is added before the initial text, and the resulting text is used as the query.
Append Text + Query
After the initial text is entered, the user is prompted for additional text. The additional text is added after the initial text and the resulting text is used as the query.
Generate Image
The DALL-E API is used to generate images according to the prompts entered. In general, the more detailed the prompt, the closer the content and quality of the output image will be to what is desired.
Rugby players are playing in a match using a huge watermelon as a ball
When the Enhance Prompt
option is enabled, a short prompt, for example the following, is expanded by GPT into more detailed text, which is then used to generate images.
View of downtown Austin from across the river
Write Program Code
GPT will generate program code and example output according to the text entered. Specify the purpose of the program, its function, the language and technology to be used, etc.
Example Input
Create a command line program that takes an English sentence and returns syntactically parsed output. Provide program code in Python and example usage.
Example Output
More Specific Commands
These are features mainly based on OpenAI's example usage of its text-completion API. The user-specified values to the following user settings are ignored when running these commands:
temperature
frequency_penalty
presence_penalty
Language-related
Ask in Your Language
You can ask questions in the language set to the variable first_language
.
Note: If the value of first_language
is not English
(e.g. Japanese
), the query may result in a more or less inaccurate response.
Translate L1 to L2
Translate text in the language specified in the variable first_language
to the language specified in the second_language
.
Translate L2 to L1
Translate text in the language specified in the variable second_language
to the language specified in the variable first_language
.
Grammar Correction
Correct sentences into standard English. See OpenAI's description.
Idea-related
Brainstorm
Brainstorm some ideas about a given text.
Create Study Notes
Provide a topic and get study notes. See OpenAI's description for this example.
Analogy Maker
Create analogies. See OpenAI's description for this example.
Essay Outline
Generate an outline for a research topic. See OpenAI's description for this example.
Summarization-related
TL;DR Summarization
Summarize text by adding a 'tl;dr:' to the end of a text passage. See OpenAI's description for this example.
Summarize for a 2nd Grader
Translates complex text into more straightforward concepts. See OpenAI's description for this example.
Keywords
Extract keywords from a block of text. See OpenAI's description for this example.
Check API Usage
You can check how many tokens you have used in the current billing period on OpenAI Usage Page--type in the keyword openai-usage
. See also OpenAI's Billing page.
Configuration
Required Settings
- OpenAI API Key: Set your secret API key for OpenAI. Sign up for OpenAI and get your API key at https://platform.openai.com/account/api-keys/.
- Model: OpenAI's chat/completion model that generates the completion. (default:
gpt-3.5-turbo
) - Base URL: The base URL of the OpenAI chat/completion API. (default:
https://api.openai.com/v1
)
Text Query Parameters
- Max Tokens: See OpenAI's documentation. (default:
2048
) - Temperature: See OpenAI's documentation. (default:
0.3
) - Top P: See OpenAI's documentation. (default:
1.0
) - Frequency Penalty: See OpenAI's documentation. (default:
0.0
) - Presence Penalty: See OpenAI's documentation. (default:
0.0
)
Image Generation Parameters
- Number of Images: Set the number of images to generate in image generation mode from
1
to10
. (default:1
) - Image Size: Set the size of images to generate from
256x256
,512x512
,1024x1024
. (default:512x512
) - Enhance Prompt: When enabled, the prompt to the image generation API is automatically enhanced using a GPT-4 model specified in the configuration. This variable is only enabled when the
model
is set to one of the "gpt-4" series.
Optional Settings
- Your First Language: Set your first language. This language is used when using GPT for translation. (default:
English
) - Your Second Language: Set your second language. This language is used when using GPT for translation.(default:
Japanese
) - Max Characters: Maximum number of characters that can be included in a query (default:
10000
). - Timeout: Number of seconds before the timeout (default:
180
). - "Please Wait" Message: If disabled, the "Please Wait" message is suppressed. (default:
enabled
) - Sound: If checked, a notification sound will play when the response is returned. (default:
disabled
) - Echo: If enabled, the original prompt is contained in the result text. (default:
enabled
) - Save File Path: If set, the results will be saved in the specified path as a markdown file. (default:
not set
) - Text to Speech: If enabled, the results will be read aloud using the system's default text-to-speech language and voice. (default:
disabled
) - Output HTML Using Pandoc: Show results in the default web browser if pandoc is installed. If unchecked (or Pandoc is not installed), Alfred's "Large Type" feature is used to display the result. (default:
enabled
) - Custom CSS: You can specify CSS for the query results HTML. (default:
not set
)
Text to Speech
If the Text to Speech
option is enabled, the result text will be read aloud in the system's standard language and voice. To change the language and speech, go to [Accessibility] - [Vision] -[Spoken Content] in the Mac Settings panel.
Custom CSS
You can define the CSS for the HTML that will be displayed as a result of the query. For example, you can freely change the maximum text width, font size and type, background color, etc.
Author
Yoichiro Hasebe ([email protected])
License
The MIT License
Disclaimer
The author of this software takes no responsibility for any damage that may result from using it.