An Alfred workflow to help use OpenAI GPT-3.5 and GPT-4 via text-completion API and chat API.
Current version: 1.7.2
Change Log
- 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)
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
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
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
)
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
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.
The input text is directly sent as a prompt to the OpenAI text-completion API.
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.
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.
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
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
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 text in the language specified in the variable first_language
to the language specified in the second_language
.
Translate text in the language specified in the variable second_language
to the language specified in the variable first_language
.
Correct sentences into standard English. See OpenAI's description.
Brainstorm some ideas about a given text.
Provide a topic and get study notes. See OpenAI's description for this example.
Create analogies. See OpenAI's description for this example.
Generate an outline for a research topic. See OpenAI's description for this example.
Summarize text by adding a 'tl;dr:' to the end of a text passage. See OpenAI's description for this example.
Translates complex text into more straightforward concepts. See OpenAI's description for this example.
Extract keywords from a block of text. See OpenAI's description for this example.
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.
- 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
).
- 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
).
- Your First Language: Set your first language (default:
English
). This language is used when using GPT for translation. - Your Second Language: Set your second language (default:
Japanese
). This language is used when using GPT for translation. - 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:
checked
) - Sound: If checked, a notification sound will play when the response is returned.
- Echo: If enabled, the original prompt is contained in the result text.
- Save File Path: If set, the results will be saved in the specified path as a markdown file.
- Text to Speech: If enabled, the results will be read aloud using the system's default text-to-speech language and voice
- 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.
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.
Yoichiro Hasebe ([email protected])
The MIT License
The author of this software takes no responsibility for any damage that may result from using it.