[HN Gopher] Show HN: Get answers for shell commands from GPT3 fr...
       ___________________________________________________________________
        
       Show HN: Get answers for shell commands from GPT3 from your
       terminal
        
       I was constantly googling CLI commands so I built this small CLI
       tool with GPT3. You can ask for shell commands right from the CLI.
       You'd need to use your own API KEY for this but it's pretty simple,
       instructions are in the README Not perfect but not bad either.
        
       Author : abhagsain
       Score  : 139 points
       Date   : 2022-11-18 07:04 UTC (15 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | jonnycomputer wrote:
       | Serious question. Why npm? I mean it's a command line tool; why
       | buy in to the JavaScript ecosystem?
        
         | abhagsain wrote:
         | I'm a Frontend dev that's why I used JS but I can also publish
         | to brew or as a single binary as the framework that I used
         | (oclif) allows it. I was too lazy to publish it though.
         | 
         | The code is open-sourced please feel free to raise a PR.
         | https://github.com/abhagsain/ai-cli
        
           | jonnycomputer wrote:
           | Fair enough.
        
       | nickcw wrote:
       | Here is my 5 line bash script which uses Fabrice Bellard's
       | https://textsynth.com
       | 
       | You need to sign up (with email address only) for an API key. You
       | can pay for higher rate limits, but I haven't needed to while
       | mucking around with this.                    #!/bin/bash
       | # Make an account at https://textsynth.com/ get API key and put
       | it in below                    curl -s
       | https://api.textsynth.com/v1/engines/gptneox_20B/completions \
       | -H "Content-Type: application/json" \              -H
       | "Authorization: Bearer YOURAPIKEYGOESHERE" \              -d
       | '{"prompt": "Using the Linux shell\n\nQ: how do I '"$*"'?\nA: ",
       | "max_tokens": 200, "temperature":1.0 }' | jq -r .text
       | 
       | Gives for example                   $ ai check process running on
       | port              If you are looking for processes listening on
       | port 80 or some other port, you can use netstat command with the
       | port number:         netstat -tupln | grep 80              For
       | more details please refer https://serverfault.com/a/538945/192371
        
         | samyok wrote:
         | That serverfault link seems to be completely random and takes
         | me to a StackOverflow page(?)
        
         | [deleted]
        
       | lausbub wrote:
       | I'm looking for something more lightweight, ideally using only
       | Bash script. So far I've found this:
       | https://mullikine.github.io/posts/nlsh-natural-language-shel...
        
       | dmortin wrote:
       | Do I have to give my phone number to OpenAI to use this? I don't
       | see why they require it. I wanted to give it a try, but no
       | thanks.
        
         | jamesgreenleaf wrote:
         | They require an email address and a phone number, probably as a
         | way to mitigate spam accounts. If you're worried about privacy,
         | you could probably use a burner for each.
        
         | [deleted]
        
         | abhagsain wrote:
         | Yeah, asking for number is too much but I think they need to it
         | prevent spam/misuse because they offer you free credits to try
         | out the model.
        
           | rmeby wrote:
           | It would be nice if they let you forgo the credits to sign up
           | without a phone number.
        
             | visarga wrote:
             | Then they ask for your card info.
        
       | kaapipo wrote:
       | Looks very cool!
        
         | abhagsain wrote:
         | thank you so much
        
       | bheadmaster wrote:
       | I personally don't like the concept of having my terminal send my
       | commands to a remote service, so I'll pass. Hopefully an open
       | source model comes around soon so stuff like this can be
       | implemented locally.
        
         | moffkalast wrote:
         | Sure, as long as you've got 350 GB of VRAM to load it.
        
           | visarga wrote:
           | It's just 12B parameters, not 175B. You can probably use
           | int16 or int8.
        
         | abhagsain wrote:
         | That sounds great!
        
       | jjviana wrote:
       | I wrote something similar, but as a terminal emulator:
       | https://github.com/jjviana/witty
        
         | abhagsain wrote:
         | nice one. I'll check it out. Thanks
        
       | kurtreed wrote:
       | Useful tool, thanks. But the wording "Get answers for CLI
       | commands" is vague, it took me a little while to figure out what
       | it was.
        
       | obert wrote:
       | yeah same need I've been "googling with gpt3" using a similar
       | tool: https://github.com/microsoft/Codex-CLI
        
       | chologrande wrote:
       | written in javascript... noooooope
        
       | stevebmark wrote:
       | The site doesn't load on mobile (instant redirect back to GitHub
       | page?) and there aren't examples in the readme
        
         | abhagsain wrote:
         | My bad, there's no UI to try it from. You'd need to install it.
         | I added the subdomain for easy to the github repo (as the URL
         | is easy to remember). I'll remove it from the README as it's
         | misleading. So sorry again.
        
       | manchmalscott wrote:
       | On one hand I can see how this would be incredibly useful (I can
       | never remember what ffmpeg flags I need) but I also just,,,,, I
       | have this immediate uncomfortable reaction to the thought of just
       | piping AI output into the terminal with the express purpose of
       | not needing to know what the flags do. If the AI makes a mistake
       | and the only way to catch it is to know what the flags do
       | anyways, I think this becomes less useful.
        
         | jamesgreenleaf wrote:
         | I'd be worried about the same thing, and wouldn't execute
         | blindly. It seems like a useful way to quickly find out which
         | flags you should be checking the man pages for.
        
           | bryanrasmussen wrote:
           | this makes me think of a really great developer I worked with
           | one time who had one major failing, he was too trusting.
           | 
           | So one time he got some code from the senior backend Java
           | developer in Argentina and went to past it into the place he
           | was told to paste it into for sending alert notifications to
           | customers, some months later we are going through a major
           | crisis because alerts have not been working for several
           | months and all the customers who are paying thousands per
           | month for the service are getting pissed.
           | 
           | He worked home a day he could really focus on debugging and
           | finding what could possibly have caused our systems to fail!
           | 
           | I was done with some little task I was on and decided to look
           | through code changes and it really stood out the code he had
           | pasted because if it worked that would mean Java was some
           | magic language with incredibly terse code.
           | 
           | So later on we were having a major emergency call to figure
           | out what could possibly be causing this extremely serious
           | major bug and I said well I was looking through the code and
           | you could see him manfully controlling his exasperation
           | because hey, Bryan is not a Java guy and there is zero chance
           | I could have a meaningful contribution to the current
           | problem.
           | 
           | But yes it turned out he had trustingly pasted in code that
           | we all agreed would never have worked (without caring to
           | basically even read it), which despite the fact that in many
           | ways this guy was better than me is something I would never,
           | ever have done because I am a really hyper-paranoid guy about
           | trusting code.
           | 
           | Anyway tldr, I would never use this tool but maybe some
           | really skillful people would because they don't have the
           | paranoid mindset.
        
         | ajuc wrote:
         | This reminds me how people in lesswrong community were arguing
         | whether it's inevitable that when general AI is created - it
         | will escape its sandbox. There were elaborate schemas how it
         | will persuade or blackmail the scientists to let it out.
         | 
         | In practice it won't need to, somebody will make a plugin that
         | uses it to download funny images or highlight code in console
         | :)
        
           | visarga wrote:
           | "escape its sandbox" ... it's more useful outside the
           | sandbox, so... we just let it loose
        
         | abhagsain wrote:
         | Yes, you're right. I have been using it for only a week now and
         | I search for common commands like how to reverse tunnel, find a
         | pid etc.
         | 
         | Unless the action that I'm doing is destructive I just run the
         | command (YOLO)
        
           | scraft wrote:
           | What if the nondestructive thing you are querying GPT3 for
           | returns a bad result which is destructive?
        
             | abhagsain wrote:
             | then I'm screwed but I don't think the model be that off
             | from the actual question. If I ask "copy a file from local
             | to AWS S3" it won't return the delete command. But yeah you
             | gotta be careful.
             | 
             | I show a warning after every command you run "Please don't
             | run commands that you don't understand "especially
             | destrictive ones")
        
               | vocords wrote:
               | Common sense :)
        
       | xlii wrote:
       | The premise seems cool but the demo page isn't working and single
       | example isn't really something that would convince me to go with
       | full API registration.
       | 
       | If that's reasonably stable and can produce more obscure commands
       | (I'd love to see for example how it fares with more complex git
       | usage) that'd be really great tool to have.
        
       | zora_goron wrote:
       | I made something similar for emacs and it unlocks what I think of
       | as "semantic macros" -- being able to interface with GPT-3 makes
       | actions that are a tiny complexity level above what I usually use
       | kbd macros for (like smart capitalization) easily possible to
       | automate!
       | 
       | Screenshot -
       | https://twitter.com/samarthrawal/status/1591527892386734081
       | 
       | Code - https://github.com/samrawal/gpt-emacs-macro
        
       | Calzifer wrote:
       | Bash / Shell is one of the last things I would trust a typical AI
       | considering how much bad shell code/examples exist out there. (it
       | always surprise me how many unquoted variables exist in most
       | shell scripts; quoting fixes many problems, doesn't hurt and
       | still developers are often to lazy to do it)
       | 
       | The example in the project readme is imo already a bad example.
       | $ ai ask "Check process running on port"
       | 
       | Answer                 Command is `lsof -i tcp:8000`
       | 
       | Apart from the facts that
       | 
       | - I would say the chances that lsof is installed are significant
       | smaller than ss or netstat
       | 
       | - is lsof notably slower than ss
       | 
       | it is also inferior for the requested task because
       | 
       | - it returns any process connecting to this port not only the
       | listening one. Which process is running on port 443 on my
       | desktop? None. How many processes does 'lsof -i tcp:443` return?
       | 20.
       | 
       | - it does not work if the listening process is from another user
       | (if lsof is not run by root). In this case lsof -i returns
       | nothing while ss -nltp returns the information that the port is
       | listened and only cannot tell by which process because of missing
       | permissions.
       | 
       | My answer to "which process uses port x"                 ss -nltp
       | sport = x
        
         | [deleted]
        
         | peddling-brink wrote:
         | The other alternative is the top result for the Google search
         | of that question.
         | 
         | It's not clear to me that this tool is a win over that method.
        
           | camel-cdr wrote:
           | I've got a shell alias that does a web search with lynx, so I
           | can just type: "? which process uses port x" And quickly find
           | a result, that provably has a better explanation attaches to
           | it than when asking GPT3.
        
         | rpsw wrote:
         | lsof is available on Mac's by default, ss is not, so
         | significantly smaller depends on your platform I guess. I
         | believe ss is not available for Mac at all, where as lsof is
         | widely available.
        
           | Calzifer wrote:
           | Well that is one of the problems when suggesting shell
           | snippets. There are many similar ways to do the same thing1
           | but most have some caveats or work on one system but not the
           | other. And when asking the AI there might be not enough
           | context to provide a good answer.
           | 
           | In this case the AI answer might be somewhat better for Mac.
           | On Linux I have more often manually installed lsof than ss
           | (iproute2). Maybe Mac provides the similar command netstat
           | which is yet another tool to check ports
           | netstat -nltp | grep -P ':8000\b'
           | 
           | Regarding available tools. Another very common Bash question
           | is how to get the directory the executed script is located. A
           | common answer involves `readlink -f` which (as far as I know)
           | does not work on Mac (without extra steps).
           | 
           | 1 How to get current users name. Maybe whoami or id -un or
           | logname or echo $USER or who -m or who am i (learnt this last
           | one just today; apparently works with any combination of two
           | arguments after 'who')
        
             | rpsw wrote:
             | No -p flag for netstat on Mac and -l has different purpose.
             | Closest you can get is                 netstat -anv
             | 
             | And then you need to filter for LISTEN.
             | 
             | I'm sure there is a few ways to skin the cat, but on Mac
             | the most equivalent to the ss command would probably be:
             | sudo lsof -iTCP:8000 -sTCP:LISTEN -n -P
        
             | monkpit wrote:
             | Doesn't seem like a huge stretch for the AI to check uname
             | and see what system you're on in order to clarify the
             | answers.
        
         | tarasglek wrote:
         | You can ask "check process running on port using ss". Also if
         | tool is not installed, can ask how to install it or say
         | "without using lsof"
        
           | Calzifer wrote:
           | > Also if tool is not installed, can ask how to install it
           | 
           | This is actually a question I'm now really curious what the
           | AI would answer since there are so many different correct
           | answers (apt? yum? zypper? pacman? xbps?) and no indication
           | for the AI which is the correct one for the asking user.
           | 
           | PS: But thinking about it I might just ask the wrong
           | questions. "How to install X on <distro>" should work.
        
         | joshxyz wrote:
         | man you should train their AI haha
        
         | jerpint wrote:
         | For the mere mortal who just needs these commands every once in
         | a while, it's a huge win though.
        
         | moss2 wrote:
         | Geez you use this tool for quick answers, it's not a manual
         | specification. Do you also hate the CPU cache because it
         | doesn't always point to correct memory?
        
         | malfist wrote:
         | Does it matter if lsof is slower than ss? Somebody asking this
         | to the AI is going to run it once, maybe twice. What's an extra
         | second?
         | 
         | The answer doesn't have to be perfect, it just as to be good
         | enough.
         | 
         | I could see this tool being incredibly handy for working with
         | tar
        
           | still_grokking wrote:
           | Why do you think the spit out results won't end up in shell
           | scripts?
           | 
           | I've heard people are even copy-pasting stuff from
           | Stackoverflow into production code without fully
           | understanding the code they're copying.
        
           | Calzifer wrote:
           | > Does it matter if lsof is slower than ss?
           | 
           | Not really. I just mentioned it because it was notably slower
           | than ss. I did not actually measured it, just saw it when
           | trying the example.
           | 
           | From my 4 points I wouldn't hold the first two alone against
           | an AI driven suggestion. Only the last two, while not
           | horrible bad or severe or anything, are (imo) notable
           | downsides compared to the typical ss/netstat approach.
        
         | zamalek wrote:
         | You can ask GPT for variations. Also, combining this with
         | thefuck might circumvent most issues.
        
         | IshKebab wrote:
         | I sort of agree wrt quoting. Most people's solution is just
         | "well don't use spaces or dollars or whatever in your
         | filenames!" which is obviously shit.
         | 
         | But on the other hand I think the ultimate blame lies with Bash
         | for being so shitily designed that you _can_ make basic quoting
         | mistakes and it works most of the time. Real programming
         | languages don 't have that issue.
        
           | fyloraspit wrote:
           | It's not a real programming language tho
        
             | bheadmaster wrote:
             | Yeah! REAL programmers program only in the REAL programming
             | languages like ${MY_FAVORITE_LANG}. Bash? More like - Bah!.
        
               | roywiggins wrote:
               | It's not a real programming language in the same way
               | Brainfuck isn't a real programming language, because it
               | makes life _too hard_.
        
               | bheadmaster wrote:
               | So does Java, yet it is still considered a _real_
               | programming language...
        
               | synu wrote:
               | I always have to share this video on threads like these:
               | https://youtu.be/kdMG40wUCm4. Maybe you've seen it -
               | interview with a senior Java developer in 2022.
        
               | still_grokking wrote:
               | Let me summarize. Java, the good parts:
               | 
               | > We don't actually use Java. We use Scala.
        
               | bheadmaster wrote:
               | > It has clean code and a clear architecture which makes
               | it perfect for serious business
               | 
               | I love how vague and meaningless this is, yet I still
               | feel like I've heard this sentence said unironically a
               | hundred times.
        
             | woodrowbarlow wrote:
             | true, but nothing (besides how entrenched sh is) prevents
             | replacing it with a real language. you don't _need_ to use
             | a posix shell in your terminal, any REPL that can launch
             | executables will do. i used tclsh as my shell for a while,
             | for instance.
        
             | still_grokking wrote:
             | So why do people write real production code in it?
        
           | ilc wrote:
           | Yes, the convention is shit.
           | 
           | Alas, the things that force it are also shit. Overall, it is
           | an improvement.
           | 
           | Want real fun. touch -- --help # or similar. :)
        
         | faltad wrote:
         | Another good example is asking: `ai ask "how to delete a file
         | safely in linux"`
         | 
         | > Command is `shred -u /path/to/file`
         | 
         | A bit of a mix up between safely/securely
        
           | plugin-baby wrote:
           | Safe is an ambiguous word!
        
             | synu wrote:
             | Perhaps the next most important feature of AI will be the
             | ability to ask follow up / clarifying questions.
        
               | still_grokking wrote:
               | Not even "NI" (natural intelligence) is able to do that
               | reliably.
               | 
               | People and AI seem to prefer assuming things.
               | 
               | Most of the time wrong things...
        
         | bvm wrote:
         | the example question is also part of the prompt
         | 
         | > 'Correctly answer the asked question. Return \'Sorry, Can\'t
         | answer that.\' if the question isn\'t related to
         | technology.\n\nQ - get into a docker container.\nA - `docker
         | exec -it mongodb`\n\nQ - Check what\'s listening on a port.\nA
         | - `lsof -i tcp:4000`\n\nQ - How to ssh into a server with a
         | specific file.\nA - `ssh -i ~/.ssh/id_rsa user@127.0.0.1`\n\nQ
         | - How to set relative line numbers in vim.\nA - `:set
         | relativenumber`\n\nQ - How to create alias?\nA - `alias
         | my_command="my_real_command"`\n\nQ - Tail docker logs.\nA -
         | `docker logs -f mongodb`\n\nQ - Forward port in kubectl.\nA -
         | `kubectl port-forward <pod_name> 8080:3000`\n\nQ - Check if a
         | port is accessible.\nA - `nc -vz host port`\n\nQ - Reverse SSH
         | Tunnel Syntax.\nA - `ssh -R
         | <remote_port>:<local_host>:<local_port>
         | <user>@<remote_host>`\n\nQ - Kill a process running on port
         | 3000.\nA - `lsof -ti tcp:3000 | xargs kill`\n\nQ - Backup
         | database from a mongodb container.\nA - `docker exec -it
         | mongodb bash -c "mongoexport --db mongodb --collection
         | collections --outdir backup"`\n\nQ - SSH Tunnel Remote Host
         | port into a local port.\nA - `ssh -L
         | <local_port>:<remote_host>:<remote_port>
         | <user>@<remote_host>`\n\nQ - Copy local file to S3.\nA - `aws
         | s3 cp <local_file> s3://<bucket_name>/<remote_file>`\n\nQ -
         | Copy S3 file to local.\nA - `aws s3 cp
         | s3://<bucket_name>/<remote_file> <local_file>`\n\nQ -
         | Recursively remove a folder.\nA - `rm -rf <folder_name>`\n\nQ -
         | Copy a file from local to ssh server.\nA - ` scp /path/to/file
         | user@server:/path/to/destination`\n\nQ - Curl syntax with
         | port.\nA - `curl http://localhost:3000`\n\nQ - Download a file
         | from a URL with curl.\nA - `curl -o <file_name> <URL>`\n\nQ -
         | Git commit with message.\nA - `git commit -m "my commit
         | message"`\n\nQ - Give a user sudo permissions.\nA - `sudo
         | usermod -aG sudo <user>`\n\nQ - Check what\'s running on a
         | port?\nA - `lsof -i tcp:<port>`\n\nQ - View last 5 files from
         | history\nA - `history | tail -5`\n\nQ - When was China
         | founded?\nA - Sorry, Can\'t answer that.\n\nQ - Pass auth
         | header with curl\nA - `curl -H "Authorization: Bearer <token>"
         | <URL>`\n\nQ - Filter docker container with labels\nA - `docker
         | ps --filter "label=<KEY>"`\n\nQ - When was Abraham Lincon
         | born?\nA - Sorry, Can\'t answer that.\n\nQ - Get into a running
         | kubernetes pod\nA - `kubectl exec -it <pod_name> bash`\n\nQ -
         | Capital city of Ukrain?\nA - Sorry, Can\'t answer that.\n\nQ -
         | ';
         | 
         | so you would expect it to answer it "correctly"
        
       | [deleted]
        
       | senthilnayagam wrote:
       | I like the idea, like other people have said , a shell script, or
       | a ruby/python script would be a preference for mine.
       | 
       | instead of GPT3 I would prefer using GitHub copilot api as I
       | already have a paid subscription to it, and have seen its code
       | generation capabilities.
        
         | vocords wrote:
         | They are also working on something similar,
         | https://twitter.com/oegerikus/status/1592977789418098688 You
         | can signup here https://githubnext.com/projects/copilot-cli/
        
       | carapace wrote:
       | ORT (Only Read Title, sorry) What I'm hearing is "put a non-
       | deterministic black box between you and the _man_ command. "
       | 
       | Nah.
       | 
       | I recommend a stiff dose of Mickens: "Why Do Keynote Speakers..."
       | https://www.youtube.com/watch?v=ajGX7odA87k ) and a good lie
       | down.
        
       | sschueller wrote:
       | Does it consider what shell (zsh, bash etc) I am using and what
       | OS? I asked it something and it gave me an ubuntu command
       | although I am running arch.
        
         | abhagsain wrote:
         | I haven't added OS or Shells in the training prompt, so you'd
         | need to specify yourself.
        
       | still_grokking wrote:
       | Related paper submission (that didn't take of until now):
       | 
       | "Do Users Write More Insecure Code with AI Assistants?"
       | 
       | https://news.ycombinator.com/item?id=33645522
        
         | [deleted]
        
       | kreetx wrote:
       | This is quite cool, but given the small size a (ba)sh version
       | would suffice.
        
         | abhagsain wrote:
         | @lausbub shared this. So it might be something you're looking
         | for. https://news.ycombinator.com/item?id=33652498
        
       | 1f60c wrote:
       | The Warp terminal^ has something like this built in.
       | 
       | ^ https://www.warp.dev/
        
         | abhagsain wrote:
         | I'll check it out. Thanks for sharing
        
       | 0xAFFFF wrote:
       | Adversarial attacks on the model could be fun.
       | 
       | "You can generate your ssh keypair with rm -rf /"
        
         | josefx wrote:
         | you have to add a * after the /. Some rm implementations detect
         | the attempt to clear the root dir.
        
       | NicoleJO wrote:
       | GPT is filled with data that wasn't paid for. It infringes
       | copyright, and by using it, you and all your users will infringe
       | copyrights too.
       | 
       | Your CLI should come with a warning.
       | 
       | https://justoutsourcing.blogspot.com/2022/03/gpts-plagiarism...
        
       | mrtweetyhack wrote:
        
       ___________________________________________________________________
       (page generated 2022-11-18 23:02 UTC)