Alfred is a popular productivity app for macOS that allows you to launch apps, search for files, and automate tasks using custom workflows. If you would like to integrate OpenAI's GPT-3 based ChatGPT with Alfred, you can do so by building a custom workflow in Alfred.
Here's a step-by-step guide on how to integrate ChatGPT with Alfred, written by ChatGPT itself:
- Install the Alfred app on your Mac if you haven't already.
- Create a new workflow in Alfred by clicking on the "Workflows" tab in the Alfred preferences and then clicking the "+" button in the bottom left corner.
- Add a "Script Filter" object to the workflow by double-clicking on it in the left panel and dragging it to the right panel.
- In the "Script Filter" object, paste the following Python code, which uses the OpenAI API to send a request to the ChatGPT model and returns the response as a list of Alfred results:
import os
import requests
query = "{query}"
def send_query_to_openai(prompt):
response = requests.post("https://api.openai.com/v1/engines/davinci/jobs",
headers={
"Content-Type": "application/json",
"Authorization": "Bearer "+ os.environ["OPENAI_API_KEY"]
},
json={
"prompt": prompt,
"max_tokens": 1024,
"temperature": 0.5,
},
)
if response.status_code != 200:
raise ValueError("Failed to send query to OpenAI")
response_json = response.json()
return response_json['choices'][0]['text'].strip()
def main():
response = send_query_to_openai(query)
print(response)
main()
- In the "Script Filter" object, set the "Keyword" to "chatgpt" and the "Argument Placeholder" to "{query}".
- Add an "Environment Variable" object to the workflow by double-clicking on it in the left panel and dragging it to the right panel.
- In the "Environment Variable" object, set the "Name" to "OPENAI_API_KEY" and the "Value" to your OpenAI API key.
- Save the workflow and give it a name, such as "ChatGPT".
Now, you can activate the ChatGPT workflow by typing "chatgpt" followed by your query in the Alfred search bar. The response from the ChatGPT model will be displayed in the Alfred results.
Note: This is just a basic example of how to integrate ChatGPT with Alfred, and you can customize the workflow further to better suit your needs.
In my specific case that wasn't working, but it's still a cool experiment. YMMV.