Use this command to get suggestions on how to do things on the command line.
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
#!/bin/bash | |
TOKEN=< OpenAI token from https://platform.openai.com/account/api-keys > | |
PROMPT="You are the best at writing shell commands. Assume the OS is Ubuntu. I want you to respond with only the shell commands separated by semicolons and no commentary. Here is what I want to do: $@" | |
RESULT=`curl -s https://api.openai.com/v1/chat/completions \ | |
-H 'Content-Type: application/json' \ | |
-H "Authorization: Bearer $TOKEN" \ | |
-d "{ | |
\"model\": \"gpt-3.5-turbo\", | |
\"messages\": [{\"role\": \"user\", \"content\": \"$PROMPT\"}] | |
}" | jq '.choices[] | .message.content' -r` | |
echo $RESULT | |
read -rp "Execute? [n]: " input_var | |
input_var=${input_var:-n} | |
[ "$input_var" = "y" ] && bash -c "$RESULT" |
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
$TOKEN="< OpenAI token from https://platform.openai.com/account/api-keys >" | |
$concatArgs = "" | |
for($i=0;$i -lt $args.count;$i++) { | |
# Concatenate the argument to the variable with a space added in between | |
$concatArgs += $args[$i] + " " | |
} | |
$PROMPT = "You are the best at writing shell commands. Assume the OS is Windows and you are using PowerShell. I want you to respond with only the shell commands separated by semicolons and no commentary. Here is what I want to do: $concatArgs" | |
$RESULT = Invoke-RestMethod -Method Post -Uri "https://api.openai.com/v1/chat/completions" -ContentType "application/json" -Headers @{'Authorization' = "Bearer $TOKEN"} -Body (ConvertTo-Json @{'model' = 'gpt-3.5-turbo'; 'messages' = @(@{'role' = 'user'; 'content' = $PROMPT})}) | Select-Object -ExpandProperty choices | Select-Object -ExpandProperty message | Select-Object -ExpandProperty content | |
Write-Host $RESULT | |
$input_var = Read-Host -Prompt "Execute? [n]" | |
$input_var = $input_var -replace "\s+", "" | |
if ([String]::IsNullOrEmpty($input_var)) {$input_var = "n"} | |
if ($input_var -eq "y") {Invoke-Expression $RESULT} |
Wonder if you get better results if the prompt starts with:
PROMPT="You are the best at writing shell commands. The output to uname -a is ${uname -a}. [...]"
Wonder if you get better results if the prompt starts with:
PROMPT="You are the best at writing shell commands. The output to uname -a is ${uname -a}. [...]"
What is the intent of this change?
"I know.... PowerShell" (keanu voice) c/o @beatty
What is the intent of this change?
I wonder if, for example, it could correctly provide different arguments for linux/bsd variants of commands.
Got it. Let me see what the best way to do that would be.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: