abhagsain / ai-cli

Get answers for CLI commands from ChatGPT right from your terminal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature Request] Support for windows powershell

luiz00martins opened this issue · comments

It seems like the commands delivered currently are linux (bash) only. It'd be cool to have the option for the model to deliver powershell commands when asking on a terminal running powershell.

Hey @luiz00martins
Yeah, I didn't add PowerShell-specific examples in the prompt, it's maybe because of that, but adding that would increase the cost for all the users or we'd need different prompts for diff use cases which is a lot of trial and error.

Since it's hard to satisfy every use case. I'm looking into fine-tuning a model just for the CLI command completion with different env, the goal is better results, lower costs, and a few other features device sync, history search, etc.

But in that case, users will have to input our API Key.
Now I want to do it in a way that's sustainable for me as well since the most powerful model is the most expensive (duh!)

So yeah it's still research in progress but in the meantime, please feel free to try out different prompts for your use case, here's the current prompt

Thank you for the link. I'll try manually changing the prompt and see if I can get some results.

With the following prompt (basically the same prompt, but with unix commands substituted for their powershell counterparts, and some things such as curl commands removed) :

const getDefaultCommandPrompt = () => '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 <container>`\n\nQ - Check what\'s listening on a port.\nA - `netstat -ano | findstr :<port>`\n\nQ - How to ssh into a server with a specific file.\nA - `ssh -i <file_path> <user>@<port>`\n\nQ - How to set relative line numbers in vim.\nA - `:set relativenumber`\n\nQ - How to create alias?\nA - `Set-Alias <new_command> <old_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 - `Test-NetConnection -ComputerName <host_name> -Port <port>`\n\nQ - Kill a process running on port 3000.\nA - `Get-Process -Id (Get-NetTCPConnection -LocalPort 3000).OwningProcess | Stop-Process`\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 - `Remove-Item -Recurse <folder_name>`\n\nQ - Copy a file from local to ssh server.\nA - ` scp /path/to/file user@server:/path/to/destination`\n\nQ - Download a file from a URL.\nA - `Invoke-WebRequest -Uri <url> -OutFile <file_name>`\n\nQ - Git commit with message.\nA - `git commit -m "my commit message"`\n\nQ - Give a user sudo permissions.\nA - `Add-LocalGroupMember -Group "Administrators" -Member <user>`\n\nQ - Check what\'s running on a port?\nA - `Get-Process -Id (Get-NetTCPConnection -LocalPort <port>).OwningProcess`\n\nQ - View last 5 files from history\nA - `Get-History -Count 5`\n\nQ - When was China founded?\nA - Sorry, Can\'t answer that.\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 - ';

I got these answers:

> ai ask 'Forcibly delete file'
> Command is `Remove-Item -Force <file_name>`

> ai ask 'Raise script to administrator priviledge'
> Command is `Start-Process powershell -Verb runAs`

> ai ask 'Return whether the current script has administrator priviledges'
> Command is `([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] “Administrator”)`

Yep, working as expected :)

It'd be nice if the script could detect whether it is running under a unix shell or powershell, and pick the prompt accordingly.

With the following prompt (basically the same prompt, but with unix commands substituted for their powershell counterparts, and some things such as curl commands removed) :

const getDefaultCommandPrompt = () => '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 <container>`\n\nQ - Check what\'s listening on a port.\nA - `netstat -ano | findstr :<port>`\n\nQ - How to ssh into a server with a specific file.\nA - `ssh -i <file_path> <user>@<port>`\n\nQ - How to set relative line numbers in vim.\nA - `:set relativenumber`\n\nQ - How to create alias?\nA - `Set-Alias <new_command> <old_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 - `Test-NetConnection -ComputerName <host_name> -Port <port>`\n\nQ - Kill a process running on port 3000.\nA - `Get-Process -Id (Get-NetTCPConnection -LocalPort 3000).OwningProcess | Stop-Process`\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 - `Remove-Item -Recurse <folder_name>`\n\nQ - Copy a file from local to ssh server.\nA - ` scp /path/to/file user@server:/path/to/destination`\n\nQ - Download a file from a URL.\nA - `Invoke-WebRequest -Uri <url> -OutFile <file_name>`\n\nQ - Git commit with message.\nA - `git commit -m "my commit message"`\n\nQ - Give a user sudo permissions.\nA - `Add-LocalGroupMember -Group "Administrators" -Member <user>`\n\nQ - Check what\'s running on a port?\nA - `Get-Process -Id (Get-NetTCPConnection -LocalPort <port>).OwningProcess`\n\nQ - View last 5 files from history\nA - `Get-History -Count 5`\n\nQ - When was China founded?\nA - Sorry, Can\'t answer that.\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 - ';

I got these answers:

> ai ask 'Forcibly delete file'
> Command is `Remove-Item -Force <file_name>`

> ai ask 'Raise script to administrator priviledge'
> Command is `Start-Process powershell -Verb runAs`

> ai ask 'Return whether the current script has administrator priviledges'
> Command is `([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] “Administrator”)`

Yep, working as expected :)

It'd be nice if the script could detect whether it is running under a unix shell or powershell, and pick the prompt accordingly.

Nice! Yup, we can add that. I'll try publishing a new version this weekend. Also need to migrate a few apps from Heroku :P
Thank you for the prompt