Skip to content

saiavinash05/Python_Terminal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐍 Python AI Terminal

Project Description

This is a custom terminal application built in Python that combines traditional command-line functionality with a powerful natural language interface. Instead of just typing commands, users can describe what they want to do in plain English, and the terminal will translate the request into the correct command, execute it, and provide the result.

The project was developed as a submission for the Gemini API Challenge, showcasing the ability to integrate advanced AI capabilities into a practical, real-world application.

Key Features

  • Natural Language Processing (NLP): Translate conversational commands into a list of executable terminal commands.
  • Dynamic Command Execution: A robust system that maps natural language queries to supported file system and system monitoring commands.
  • File System Commands: Includes ls, cd, pwd, mkdir, rm, mv, touch, and echo for file and directory management.
  • System Monitoring: Commands like cpu, mem, and ps to check system performance.
  • Robust Error Handling: The system is designed to handle common issues like invalid API responses and missing commands gracefully.

Setup and Installation

1. Clone the Repository

git clone [https://github.com/your-username/your-project-repo.git](https://github.com/your-username/your-project-repo.git)
cd your-project-repo

2. Install Required Libraries

Install the necessary Python packages using pip.

pip install -r requirements.txt

Note: Make sure your requirements.txt file includes google-generativeai, colorama, and psutil.

3. Set up the Gemini API Key

You must set your Gemini API key as an environment variable to allow the application to access the AI.

On Windows:

setx GEMINI_API_KEY "YOUR_API_KEY"

On macOS/Linux:

export GEMINI_API_KEY="YOUR_API_KEY"

After setting the variable, you must restart your terminal for the changes to take effect.


Usage

To start the terminal, run the main.py script from your project's root directory:

python main.py

You can then enter both traditional terminal commands and natural language queries.

Examples:

  • Traditional Command: ls
  • Natural Language Query: create a new folder called projects
  • Complex Query: create a text file named notes.txt in the documents folder and add the text "initial notes" to it

Key Learnings & Challenges

This project presented several real-world debugging challenges that were successfully overcome:

  • Environment Variable Issues: Initial setup was blocked by the ValueError for the GEMINI_API_KEY. This was resolved by correctly setting and verifying the environment variable.
  • API Integration & Parsing: The Gemini API sometimes returned non-JSON data (e.g., Markdown blocks), causing a JSONDecodeError. This was fixed by implementing a custom fallback parser to extract the commands.
  • Command Handling: Several commands, like touch and echo, were not initially supported. These were added and registered in the command map. The echo command required a robust parser to handle quoted strings and redirection symbols (>), which was addressed by updating the core parsing logic.

This iterative debugging process was a core part of the project's development and is a testament to the code's resilience.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages