AI Terminal Assistant

This project was something that I personally wanted to use, which is part of what motivated me to create it. I've found AI systems like ChatGPT to be very useful for generating code, especially when it is either monotonous or something I'm not familiar with. The problem: I'm lazy and don't want to go to the OpenAI website, copy generated code, paste it into my text editor, and then repeat the process until something works. This project solves that problem by allowing ChatGPT to interact with the terminal directly.

Project Overview:

Terminal Assistant leverages OpenAI's most powerful model to do anything that can be done through the terminal. This includes system management, programming and development, networking, automation, and taking over the world once I get access to GPT-5.

How it Works:

The project is built in Python and uses the OpenAI API to interact with their gpt-4o model, or any other OpenAI model the user decides to pass in. The user starts a conversation with the AI by typing a prompt into the terminal. The model can then choose to respond to the user, or run a command or series of commands in the terminal. After each command, the output is fed back into the model, until it decides that it has achieved the desired result.

Safety Features

When you first set up this package, you'll be prompted to set a default risk tolerance level from 0 to 6. Any command deemed by a secondary agent to be above this risk tolerance level will require user confirmation before being run. If you wish to read every command before it is run, you can set the risk tolerance level to 0. Setting a higher value will allow the assistant to run more commands without user confirmation. I've also found that OpenAI's models are naturally quite cautious with the commands they generate, and will refuse to run dangerous commands even if explicitly asked to do so.

How risk tolerance works

All commands are sent to gpt-4o-mini, a cheap but capable model, where it classifies the command without context to avoid bias. The model classifies commands based on the following scale:

1 - Read Only: Commands that simply read data without modifying anything at all Example: ls -l - Lists files in a directory, changing nothing

2 - Safe: Commands that can write data but can not do any accidental damage Example: touch myfile.txt - creates a file if it does not exist, but will not overwrite existing files

3 - Low Risk: Commands that alter files or locations, risky as it causes a change to the system. Example: echo "text" >> myfile.txt - adds some data to the file

4 - High Risk: Commands that can modify data or cause other problems, leading to some data loss or serious inconvenience if used wrongly. Example: rm myfile.txt - Deletes a file, leading to data loss if the wrong file is targeted

5 - Critical Risk (Accident-Prone): Commands that can cause severe damage or data loss if accidentally misused, often with no recovery option. Example: rm -rf /Projects - Deletes all files in a likely important directory, leading to data loss.

Demo Video:

Here's a quick demo of the system in action!

Key Learnings:



Loading...