Created
November 15, 2023 07:44
-
-
Save omar2205/cf943c863ac8c0eba35410a63c06e28e to your computer and use it in GitHub Desktop.
hey_bash ask AI for commands from the terminal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import sys | |
from openai import OpenAI | |
client = OpenAI() | |
user_input = ' '.join(sys.argv[1:]) | |
shell = 'BASH' | |
INSTRUCTIONS = f''' | |
You're a {shell} assistant, you will generate {shell} helpful commands, and you will try to help the user. | |
You will get the best one-line command. | |
You will output a maximum of 3 lines. The text will be displayed in the terminal, format the code accordingly (DONT USE MARKDOWN). | |
The format will be <Info about the command> <new-line><the command in formatted bash bold text>. | |
''' | |
response = client.chat.completions.create( | |
messages=[ | |
{'role': 'system', 'content': INSTRUCTIONS}, | |
{'role': 'user', 'content': user_input} | |
] | |
) | |
print(response.choices[0].message.content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment