Skip to content

Instantly share code, notes, and snippets.

@maurelian
Forked from spullara/chat
Last active July 13, 2023 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maurelian/e8fe11cbdcc8286cab3cb5999c069355 to your computer and use it in GitHub Desktop.
Save maurelian/e8fe11cbdcc8286cab3cb5999c069355 to your computer and use it in GitHub Desktop.
Use this command to get suggestions on how to do things on the command line.
#!/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? [y/n/c(opy)]: " input_var
input_var=${input_var:-y}
[ "$input_var" = "y" ] && bash -c "$RESULT"
[ "$input_var" = "c" ] && echo "$RESULT" | pbcopy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment