shell_gpt is a terminal assistant tool powered by OpenAI's GPT models, designed to allow users to execute Linux commands using natural language. This tool intelligently parses user input, converts it into clear shell commands, and executes them in a secure ARM64 Raspbian sandbox environment.
With shell_gpt, users no longer need to memorize complex Linux commands. By simply typing natural language queries, they can achieve sophisticated tasks quickly and efficiently. This project is perfect for developers, system administrators, and daily Linux users.
Users can input a plain-language description, for example:
gpt install python and pip, than install the model in requirements.txt
Supports both OpenAI GPT-3.5 and GPT-4 models, allowing users to adapt the tool to their specific needs.
Besides, it support poe api which content hundreds of models.
shell_gpt can be easily integrated with other APIs or tools to expand its functionality, such as task automation or multi-user collaboration.
the core logic:
#!/usr/bin/env python3 import openai import subprocess # Initialize OpenAI client client = openai.OpenAI(api_key="sk-xxx") # Define GPT's role role = ''' You are a terminal assistant. The shell commands in your responses will be executed in a secure ARM64 Raspbian sandbox environment. Assume Linux commands by default. ''' # GPT interaction function def gpt(query): messages = [ {"role": "system", "content": role}, {"role": "user", "content": query} ] response = client.chat.completions.create( model="gpt-4-1106-preview", messages=messages, temperature=1, max_tokens=1000 ) return response.choices[0].message['content'] # Example: Parse and execute user command user_query = "update system and install vim" gpt_response = gpt(user_query) print(f"Generated Command: {gpt_response}")
Install required dependencies:
pip install openai==0.27.8
Copy the script:
Save the shell_gpt
code as gpt
and place it in any directory.
Configure the environment:
Edit .bashrc
or .profile
to add the script directory to your PATH:
export PATH="$PATH:/path/to/gpt"
Apply the changes:
source ~/.bashrc
Set execution permissions:
chmod +x /path/to/gpt
Configure OpenAI API Key:
Replace sk-xxx
in the code with your OpenAI API Key. If you're using the free version, switch the model to gpt-3.5-turbo
.
Run the following command and input a natural language query:
gpt install python and pip
Below is a demonstration of shell_gpt
in action:
Input (Natural Language):
gpt write a hello world in python and run it
Generated Shell Command:
echo "print('Hello, World!')" > hello.py && python3 hello.py
Execution Result:
Hello, World!
Real-Time Terminal Logging:
Multi-Language Support:
GUI Interface:
shell_gpt
is licensed under the MIT License. This allows users to freely use, modify, and distribute the code while retaining the original copyright notice.
There are no datasets linked
There are no datasets linked