Created
February 11, 2022 16:25
-
-
Save Heath123/d3bc8fbd41a7d29a5c9edf2186a095d0 to your computer and use it in GitHub Desktop.
Natural language to command
This file contains 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
# Add to config.fish | |
function n | |
set completedcommand (natural2command $argv) | |
commandline -i "$completedcommand" | |
end |
This file contains 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 time | |
import sys | |
import subprocess | |
from prompt_toolkit import HTML | |
from prompt_toolkit import print_formatted_text as print_formatted | |
import os | |
import openai | |
openai.api_key = [INSERT API KEY] | |
if len(sys.argv) == 1: | |
print_formatted(HTML('<ansired><b>Need arguments!</b></ansired>'), file=sys.stderr) | |
print_formatted(HTML(f'Example: <ansiblue><b>{sys.argv[0]} print time</b></ansiblue>'), file=sys.stderr) | |
sys.exit(1) | |
searchText = " ".join(sys.argv[1:]) | |
try: | |
print_formatted(HTML('<ansigreen><b>Loading...</b></ansigreen>'), end='', file=sys.stderr) | |
response = openai.Completion.create(engine="davinci-codex", prompt="""#!/bin/bash | |
# List of one-liner shell commands for Arch. | |
# Language: Bash | |
# Operating System: Arch Linux | |
# Get my IP | |
dig +short myip.opendns.com @resolver1.opendns.com | |
# Print the current directory | |
pwd | |
# List files | |
ls -l | |
# Find every file that is not .mp3 | |
find . -name '*' -type f -not -path '*.mp3' | |
# Change directory to /tmp | |
cd /tmp | |
# """ + searchText + "\n", max_tokens=100, temperature=0, stop="\n") | |
print_formatted('\x08' * 12, end='', flush=True, file=sys.stderr) | |
print_formatted(' ' * 12, end = '', file=sys.stderr) | |
print_formatted('\x08' * 12, end='', flush=True, file=sys.stderr) | |
print(response.choices[0].text, end="") | |
except KeyboardInterrupt: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment