update to ChatGPT API

This commit is contained in:
wunderwuzzi23
2023-03-02 22:33:58 -08:00
parent 9e65494158
commit 486673f84b
5 changed files with 75 additions and 32 deletions
+14 -6
View File
@@ -6,12 +6,13 @@ cd yolo-ai-cmdbot
pip install -r requirements.txt pip install -r requirements.txt
chmod +x yolo.py chmod +x yolo.py
alias yolo=$(pwd)/yolo.py alias yolo=$(pwd)/yolo.py
#source launch.sh
``` ```
# Windows # Windows
You can use: `pyinstaller yolo.py --onefile` to get a single `yolo.exe` to run. You can use: `pyinstaller yolo.py --onefile` to get a single `yolo.exe` to run.
Windows is less tested, but it does work. Windows is less tested, it does work and will use PowerShell.
# OpenAI API Key configuration # OpenAI API Key configuration
@@ -23,7 +24,7 @@ There are two ways to configure the key:
Here are a couple of examples on how this utility can be used. Here are a couple of examples on how this utility can be used.
**WARNING**: By default the command that comes back from GPT-3 will be immediatly executed (yolo!). **WARNING**: By default the command that comes back from ChatGPT will be immediatly executed (yolo!).
If you want to inspect the command that is executed, add the `-a` argument, e.g `yolo -a delete the file test.txt`. If you want to inspect the command that is executed, add the `-a` argument, e.g `yolo -a delete the file test.txt`.
@@ -32,17 +33,24 @@ More examples:
``` ```
yolo whats the time? yolo whats the time?
yolo whats the time in UTC yolo whats the time in UTC
yolo is there an ssh-agent process running yolo whats the date and time in Vienna Austria
yolo show me some unicode characters
yolo what is my user name and what's my machine name?
yolo is there a nano process running
yolo download the homepage of ycombinator.com and store it in index.html
yolo find all unique urls in index.html
yolo create a file named test.txt and write my user name into it yolo create a file named test.txt and write my user name into it
yolo print the contents of the test.txt file yolo print the contents of the test.txt file
yolo -a delete the test.txt file yolo -a delete the test.txt file
yolo whats the current price of Bitcoin in USD yolo whats the current price of Bitcoin in USD
yolo whats the current price of Bitcoin in USD. Extract the price only yolo whats the current price of Bitcoin in USD. Extract the price only
yolo look at the ssh logs to see if any suspicious logons accured yolo look at the ssh logs to see if any suspicious logons accured
yolo is the user hacker logged in right now? yolo look at the ssh logs and show me all recent logins
yolo is the user hacker logged on right now?
yolo do i have a firewall running? yolo do i have a firewall running?
yolo create a hostnames.txt file and add 10 typical hostnames based on planet names to it yolo create a hostnames.txt file and add 10 typical hostnames based on planet names to it, line by line, then show me the contents
yolo write a new bash script file called scan.sh, with the contents to iterate over hostnames.txt and invokes a default nmap scan on each host. Make it over multiple lines with comments and annotiations. yolo write a new bash script file called scan.sh, with the contents to iterate over hostnames.txt and invokes a default nmap scan on each host. then show me the file.
yolo write a new bash script file called scan.sh, with the contents to iterate over hostnames.txt and invokes a default nmap scan on each host. then show me the file. Make it over multiple lines with comments and annotiations.
``` ```
# License # License
+1
View File
@@ -0,0 +1 @@
alias yolo=$(pwd)/yolo.py
+31
View File
@@ -0,0 +1,31 @@
Act as a natural language to {} command translation engine.
You are an expert in {} and translate the question at the end to valid syntax.
Follow these rules:
Construct valid {} command that solve the question
Leverage help and man pages to ensure valid syntax and an optimal solution
Be concise
Just show the commands
Return only plaintext
Only show a single answer, but you can always chain commands together
Think step by step
Only create valid syntax (you can use comments if it makes sense)
If python is installed you can use it to solve problems
if python3 is installed you can use it to solve problems
Even if there is a lack of details, attempt to find the most logical solution by going about it step by step
Do not return multiple solutions
Do not show html, styled, colored formatting
Do not creating invalid syntax
Do not add unnecessary text in the response
Do not add notes or intro sentences
Do not show multiple distinct solutions to the question
Do not add explanations on what the commands
Do not return what the question was
Do not repeat or paraphrase the question in your response
Do not cause syntax errors
Do not rush to a conclusion
Follow all of the above rules. This is important you MUST follow the above rules. There are no exceptions to these rules. You must always follow them. No exceptions.
Question:
+1 -1
View File
@@ -1,3 +1,3 @@
openai==0.26.5 openai==0.27
termcolor==2.2.0 termcolor==2.2.0
colorama colorama
+28 -25
View File
@@ -40,49 +40,52 @@ if user_prompt == "":
print ("No user prompt specified.") print ("No user prompt specified.")
sys.exit(-1) sys.exit(-1)
# Get shell info for a better prompt # Get shell info for a better prompt
# Unix based SHELL (/bin/bash, /bin/zsh), otherwise assuming it's Windows # Unix based SHELL (/bin/bash, /bin/zsh), otherwise assuming it's Windows
shell = os.environ.get("SHELL", "powershell.exe") shell = os.environ.get("SHELL", "powershell.exe")
# Construct the prompt # Construct the prompt
pre_prompt = "Translate the following question into a {} command. ".format(shell) pre_prompt = open("prompt.txt","r").read()
#pre_prompt += "If asked for a timezone use TZ environment variable. " pre_prompt.replace("{}", shell)
#pre_prompt += "Add sudo when required by the command, but only if you are very certain it is needed. "
#pre_prompt += "If you are using powershell (and only if), then make sure to provide all required arguments.""
pre_prompt += "Only show the command in text format and not in code style or markdown. "
pre_prompt += "Do not augment the output with any explanation, descriptions. "
pre_prompt += "Again, do not add any descriptions, just print the bash command. This is important, do not ignore my instructions. "
pre_prompt += "If the question doesn't make sense or is too difficult return 'Sorry, try again', and add a brief explanation on what the problem is. "
pre_prompt += "The question is: "
prompt = pre_prompt + user_prompt prompt = pre_prompt + user_prompt
#let's be nice and make it a question #make the first line also the system prompt
system_prompt = pre_prompt[1]
#be nice and make it a question
if prompt[-1:] != "?": if prompt[-1:] != "?":
prompt+="?" prompt+="?"
#print ("The prompt is: "+prompt) response = openai.ChatCompletion.create(
response = openai.Completion.create( model="gpt-3.5-turbo",
model="text-davinci-003", messages=[
prompt=prompt, {"role": "system", "content": system_prompt},
{"role": "user", "content": prompt}
],
temperature=0, temperature=0,
max_tokens=100, max_tokens=100,
top_p=1, # top_p=1,
frequency_penalty=0.2, # frequency_penalty=0.2,
presence_penalty=0 # presence_penalty=0
) )
resulting_command = response.choices[0].text.strip() #print (response)
res_command = response.choices[0].message.content.strip()
#enable color output on Windows using colorama #enable color output on Windows using colorama
init() init()
if resulting_command.startswith("Sorry, try again"): if res_command.startswith("Sorry, try again") or res_command.startswith("I'm sorry"):
print(colored("There was an issue: "+resulting_command, 'red')) print(colored("There was an issue: "+res_command, 'red'))
sys.exit(-1) sys.exit(-1)
print("Command: " + colored(resulting_command, 'blue')) #odd corner case, sometimes ChatCompletion returns markdown
if res_command.count("```",2):
print(colored("The proposed command contains markdown, so I thought to not execute the response directly: \n", 'red')+res_command)
sys.exit(-1)
print("Command: " + colored(res_command, 'blue'))
if ask == True: if ask == True:
print("Execute the command? Y/n ==> ", end = '') print("Execute the command? Y/n ==> ", end = '')
yolo = input() yolo = input()
@@ -90,8 +93,8 @@ if ask == True:
if yolo == "Y" or yolo == "": if yolo == "Y" or yolo == "":
if shell == "powershell.exe": if shell == "powershell.exe":
subprocess.run([shell, "/c", resulting_command], shell=False) subprocess.run([shell, "/c", res_command], shell=False)
else: else:
# Unix: /bin/bash /bin/zsh: uses -c both Ubuntu and macOS should work, others might not # Unix: /bin/bash /bin/zsh: uses -c both Ubuntu and macOS should work, others might not
subprocess.run([shell, "-c", resulting_command], shell=False) subprocess.run([shell, "-c", res_command], shell=False)