├── LICENSE ├── README.md └── src └── ruv.sh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 ruv 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ruvbot - Devops using OpenAi ChatGPT Model 2 | This script is a command-line tool that utilizes OpenAI's GPT-3.5 Turbo to generate shell commands based on user input. The script also features a loading animation and provides summaries of command outputs. 3 | 4 | ## More details 5 | This script serves as a valuable tool for server administrators and DevOps professionals who want to simplify their daily tasks and improve their workflow. By leveraging the OpenAI API and ChatGPT model, the script generates shell command suggestions based on user input, allowing users to perform a wide range of operations with ease. 6 | 7 | The key advantage of using this script is its ability to understand natural language input and translate it into relevant shell commands. This not only saves time but also reduces the likelihood of human error when performing complex tasks. Moreover, the script provides multiple command options, empowering users to make informed decisions while executing their tasks. 8 | 9 | Here's a breakdown of the script: 10 | 11 | * Define a show_loading function to display a loading animation. 12 | * Print a welcome message with an ASCII art logo representing "rUvbot". 13 | * Define a show_help function that displays usage instructions and script options. 14 | * Check for the -h or --help arguments to show the help message if needed. 15 | * Collect user input and save the current working directory. 16 | * Start the loading animation in the background. 17 | * Define a get_response function to make an API call to OpenAI, passing the user input and a temperature setting for the GPT-3.5 Turbo model. 18 | * Make two API calls with different temperature settings and extract the generated commands from the API responses. 19 | * Stop the background loading animation and clear the loading animation line. 20 | * Display the generated commands as options for the user to choose from. 21 | * Prompt the user to choose a command option or cancel. 22 | * Execute the selected command and store the output in a temporary file. 23 | * Display the command output and, if there is any output, start the loading message again in the background. 24 | * Request a summary of the command output from the GPT-3.5 Turbo model by sending another API call. 25 | * Stop the background loading message and display the summary provided by the model. 26 | * Remove the temporary output file. 27 | 28 | ## Install & Usage Instructions: 29 | 30 | This script was made for linux or the linux subsystem on windows. 31 | 32 | Update the OpenAI API Key: Replace in the get_response() function with your actual OpenAI API key. There are two instances where you need to replace this placeholder. The lines are: 33 | 34 | ### -H 'Authorization: ' \ 35 | Replace with your API key, like this: 36 | 37 | ### -H 'Authorization: Bearer sk-yourapikeyhere' \ 38 | Save the updated script and make it executable. In the terminal, navigate to the directory containing the script and run: 39 | 40 | ### chmod +x script_name.sh 41 | Replace script_name.sh with the actual name of the script. 42 | 43 | ### Run the script with user input: 44 | 45 | ### ./script_name.sh [OPTIONS] 46 | Replace script_name.sh with the actual name of the script and with your desired input. 47 | 48 | ## Available options: 49 | 50 | ### -h or --help: Show the help message and exit. 51 | For example, to run the script with the user input "create a new directory called test", you would execute the following command: 52 | 53 | ## Sample Script Usage 54 | ### ./script_name.sh create a new directory called test 55 | 56 | The script will then provide you with two shell command options generated by the GPT-3.5 Turbo model, based on your input. Choose one of the options or cancel the 57 | operation. If you proceed, the script will execute the chosen command and provide you with a summary of the command output. 58 | 59 | ### Networking: 60 | ### ./script_name.sh check the IP address of my local machine 61 | 62 | The script will provide shell command options to retrieve the IP address of your local machine. 63 | 64 | ### NPM: 65 | ### ./script_name.sh install the express package globally 66 | 67 | The script will provide shell command options to install the Express package globally using npm. 68 | 69 | ### Application deployments: 70 | ### ./script_name.sh create a tarball of a directory called my_project 71 | 72 | The script will provide shell command options to create a tarball (compressed archive) of a directory named my_project. 73 | -------------------------------------------------------------------------------- /src/ruv.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # DAA - Decentralized Autonomous Application 3 | # /\__/\ - daa.rs 4 | # ( o.o ) - v0.0.1 5 | # >^< - by @rUv 6 | 7 | # Function to display a loading animation 8 | show_loading() { 9 | local delay=0.1 10 | while true; do 11 | for i in '-' '\\' '|' '/'; do 12 | printf "\r\033[0;34m 🤖ruvBot Fetching Data %s\033[0m" "$i" # Change the text here 13 | sleep "$delay" 14 | done 15 | done 16 | } 17 | 18 | echo "" 19 | echo " ___T_ " 20 | echo " | o o | " 21 | echo " |__-__| " 22 | echo " /| []|\ " 23 | echo " ()/|___|\() " 24 | echo " | | " 25 | echo " rUvbot v0.01" 26 | echo "" 27 | # echo "Loading OpenAi Data - Please Wait" 28 | 29 | 30 | show_help() { 31 | echo "Usage: $(basename "$0") [OPTIONS] " 32 | echo "" 33 | echo "Options:" 34 | echo " -h, --help Show this help message and exit" 35 | echo "" 36 | echo "This script takes user input and generates shell commands based on the input using OpenAI's GPT-3.5 Turbo." 37 | echo "" 38 | echo "Common Commands:" 39 | echo " File Management & Storage:" 40 | echo " ls List files and directories in the current directory" 41 | echo " cd Change the current working directory" 42 | echo " mkdir Create a new directory" 43 | echo " touch Create a new file" 44 | echo " rm Remove a file or directory" 45 | echo " cp Copy a file or directory" 46 | echo " mv Move or rename a file or directory" 47 | echo "" 48 | echo " Networking:" 49 | echo " ping Test network connectivity to a host" 50 | echo " curl Transfer data from or to a server" 51 | echo " ssh Connect to a remote server securely" 52 | echo "" 53 | echo " Coding:" 54 | echo " Rust:" 55 | echo " cargo Package manager for Rust" 56 | echo " rustc Rust compiler" 57 | echo "" 58 | echo " Python:" 59 | echo " pip Package installer for Python" 60 | echo " python Python interpreter" 61 | echo "" 62 | echo " NPM:" 63 | echo " npm Package manager for Node.js" 64 | echo " node Node.js runtime environment" 65 | echo "" 66 | echo " AWS:" 67 | echo " awscli Command-line interface for AWS" 68 | } 69 | 70 | # Check for help argument 71 | for arg in "$@"; do 72 | case $arg in 73 | -h|--help) 74 | show_help 75 | exit 0 76 | ;; 77 | esac 78 | done 79 | 80 | 81 | # get user cli arguments as a string 82 | args=$* 83 | 84 | # save the current working directory to a variable 85 | cwd=$(pwd) 86 | 87 | if [ -z "$args" ]; then 88 | echo "⚠️ Error: No input provided." 89 | exit 1 90 | fi 91 | 92 | # Start the loading animation in the background 93 | show_loading & 94 | 95 | # Save the process ID of the background loading animation 96 | loading_pid=$! 97 | 98 | 99 | # function to make an API call with a given temperature 100 | get_response() { 101 | local temperature=$1 102 | curl -s https://api.openai.com/v1/chat/completions \ 103 | -H 'Content-Type: application/json' \ 104 | -H 'Authorization: ' \ 105 | -d '{ 106 | "model": "gpt-3.5-turbo", 107 | "messages": [{"role": "system", "content": "You are a helpful assistant. You will generate '"$SHELL"' commands based on user input. Your response should contain ONLY the command and NO explanation. Do NOT ever use newlines to separate commands, instead use ; or &&. The current working directory is '"$cwd"'."}, {"role": "user", "content": "'"$args"'"}], 108 | "temperature": '"$temperature"', 109 | "max_tokens": 200, 110 | "top_p": 0.1, 111 | "stream": false 112 | }' 113 | } 114 | 115 | # make two API calls with different temperatures 116 | response1=$(get_response 0) 117 | response2=$(get_response 1.8) 118 | 119 | # extract the generated commands 120 | cmd1=$(echo $response1 | jq '.choices[0].message.content' | sed -e 's/^.//' -e 's/.$//') 121 | cmd2=$(echo $response2 | jq '.choices[0].message.content' | sed -e 's/^.//' -e 's/.$//') 122 | 123 | 124 | # After receiving the responses, stop the background loading animation 125 | kill -15 $loading_pid 126 | wait $loading_pid 2>/dev/null 127 | 128 | # Clear the loading animation line 129 | echo -e "\r\e[2K" 130 | 131 | echo "⭐ Option 1: $cmd1" 132 | echo "⭐ Option 2: $cmd2" 133 | 134 | # make the user confirm the command 135 | read -p "Choose an option (1/2) or type 'c' to cancel: " choice 136 | 137 | case $choice in 138 | 1) selected_cmd=$cmd1 ;; 139 | 2) selected_cmd=$cmd2 ;; 140 | [Cc]) echo "Aborted."; exit 0 ;; 141 | *) echo "⚠️ Invalid choice. Aborted."; exit 1 ;; 142 | esac 143 | 144 | echo "Executing command: $selected_cmd" 145 | echo "" 146 | 147 | # save command to file, execute the command from file, remove the file 148 | echo "$selected_cmd" > ".tempplscmd" 149 | source ".tempplscmd" 150 | cd "$cwd" 151 | rm ".tempplscmd" 152 | 153 | 154 | # Execute the command and store the output in a temporary file 155 | temp_output_file=".temp_output_file" 156 | bash -c "$selected_cmd" > "$temp_output_file" 157 | 158 | # Read the contents of the temporary file and display the output 159 | output=$(cat "$temp_output_file") 160 | echo "Command output:" 161 | echo "$output" 162 | echo "" 163 | 164 | 165 | if [ -z "$output" ]; then 166 | echo "No output to summarize." 167 | else 168 | # Start the loading message in the background 169 | show_loading "🤖 Loading OpenAI Data - Please Wait" & 170 | 171 | # Save the process ID of the background loading message 172 | loading_pid=$! 173 | 174 | # Remove newlines and escape double quotes in the output to prevent JSON parsing errors 175 | output=$(echo "$output" | tr '\n' ' ' | sed 's/"/\\"/g') 176 | 177 | # Request a summary of the output from the AI model 178 | summary_request='{ 179 | "model": "gpt-3.5-turbo", 180 | "messages": [ 181 | {"role": "system", "content": "You are a helpful assistant. Summarize the following command output in a clear and concise manner."}, 182 | {"role": "user", "content": "'"$output"'"} 183 | ], 184 | "temperature": 0.5, 185 | "max_tokens": 2000, 186 | "top_p": 0.9, 187 | "stream": false 188 | }' 189 | 190 | summary_response=$(curl -s https://api.openai.com/v1/chat/completions \ 191 | -H 'Content-Type: application/json' \ 192 | -H 'Authorization: ' \ 193 | -d "$summary_request") 194 | 195 | # Stop the background loading message by sending a SIGTERM signal 196 | kill -15 $loading_pid 197 | wait $loading_pid 2>/dev/null 198 | 199 | # Extract and display the summary, overwriting the loading message 200 | summary=$(echo $summary_response | jq '.choices[0].message.content' | sed -e 's/^.//' -e 's/.$//') 201 | echo -e "\r\e[2KSummary of the output:" 202 | echo "" 203 | echo "$summary" 204 | echo "" 205 | fi 206 | 207 | # Remove the temporary output file 208 | rm "$temp_output_file" 209 | --------------------------------------------------------------------------------