├── README.md └── sample.sh /README.md: -------------------------------------------------------------------------------- 1 | # ai-bash-response 2 | 3 | # Usage 4 | **Just test for Debian/Ubuntu** 5 | 6 | Put the code in the simple.sh into the end of `.bashrc` and replace the placeholder texts. Restart bash. 7 | -------------------------------------------------------------------------------- /sample.sh: -------------------------------------------------------------------------------- 1 | command_not_found_handle() { 2 | # Call OpenAI API 3 | local input="$*" 4 | local formatted="" 5 | local arg 6 | 7 | # Loop over each argument in the input string 8 | for arg in $input; do 9 | # If the argument contains spaces, enclose it in quotes 10 | if [[ $arg == *[[:space:]]* ]]; then 11 | arg="\"$arg\"" 12 | fi 13 | 14 | # Append the argument to the formatted string 15 | formatted+="$arg " 16 | done 17 | local api_URL="http:\\xxxxxx" 18 | local api_key="" 19 | # Remove the trailing space 20 | formatted=${formatted%?} 21 | local response=$(curl -s --request POST \ 22 | --url "$api_URL" \ 23 | --header "Authorization: Bearer $api_key" \ 24 | --header 'accept: application/json' \ 25 | --header 'content-type: application/json' \ 26 | --data "{\"model\":\"mistralai/Mixtral-8x7B-Instruct-v0.1\", \"max_tokens\": 100,\"temperature\": 0.7,\"messages\": [{\"role\": \"user\",\"content\": \"you are a linux shell in teenager tone. She said '$formatted' to you. If she wants to chat with you just answer her, if it seems like she used the wrong command just tell her the correct one.\"}],\"stream\": false}") 27 | 28 | # Parse the response and echo the generated text 29 | 30 | local generated_text=$(echo $response | jq -r '.choices[0].message.content') 31 | echo "Error: '$formatted' Command doesn't exist." 32 | echo 33 | echo -e "\033[36m$generated_text\033[0m" 34 | return 127 35 | } 36 | export -f command_not_found_handle 37 | --------------------------------------------------------------------------------