diff --git a/README.md b/README.md index a23de80..0dd5ede 100644 --- a/README.md +++ b/README.md @@ -1,122 +1,20 @@ -# PyShell - Python Based CLI -### (developed by @ansh.mn.soni) +# 🧠 PyBot – Natural Language to Shell Command Converter -## πŸ‘‰ Introduction: -PyShell is a custom-built command-line interface (CLI) that serves as a lightweight yet powerful terminal, developed using Python. It allows users to interact with their system, manage files, process system commands, and perform various utility functions. With a focus on simplicity, speed, and usability, PyShell enhances the standard terminal experience by integrating automation, process management, and network utilities. +> A terminal-based assistant that converts natural language into safe and efficient Linux shell commands using OpenAI’s LLM. -## πŸ”‘ Key Advantages: -#### 0️⃣ User Login for Security -###### Preview

-![image](https://github.com/user-attachments/assets/d9dacb15-f89c-4fd1-a28c-ef0b8915c4f5) +## πŸš€ Features -#### 1️⃣ Task Scheduling -###### Preview

-![image](https://github.com/user-attachments/assets/d0cf8b40-52ca-47a4-a60c-26278e65bc69) +- πŸ” **LLM Conversion**: Translates English queries into shell commands using OpenAI's Chat API. +- 🧠 **Few-shot Prompting**: Uses example inputs and outputs from `prompt_templates.json`. +- πŸ” **Secure API key management** with `.env` and `python-dotenv`. +- βœ… **Safe & extendable**: Designed to integrate with memory and safety checker modules. -#### 2️⃣ Weather Tracking -###### Preview

-![image](https://github.com/user-attachments/assets/953cbd34-397b-45be-a274-4e0d2e584c4b) -#### 3️⃣ in-built Calculator -###### Preview

-![image](https://github.com/user-attachments/assets/f65045b0-9e4c-43e8-a46c-403344480542) +## πŸ“ Project Structure -#### 4️⃣ Automate Password Generator -###### Preview

-![image](https://github.com/user-attachments/assets/0ad4ac81-66dc-495f-a897-2cb27f3997e0) - -#### 5️⃣ Supports all basic linux commands -- `ls` -- `ls -all` -- `mkdir` -- `touch` -- `rm` -- `sysinfo` -- `network` etc... - -#### 6️⃣ Supports synchronization -- `list process` -- `kill process` -- `force stop` -- `renaming file` in between the program - -#### 7️⃣ Simple and Clean Terminal -###### Preview

-![Screenshot 2025-05-18 125323](https://github.com/user-attachments/assets/55692d28-4f35-4236-b9ac-c976e85d5891) - -#### 8️⃣ Play Song right through terminal -###### Preview

-![Screenshot 2025-05-18 132600](https://github.com/user-attachments/assets/d254ab8b-da7f-4d78-b5c3-45233a9ffd96) - -![Screenshot 2025-05-18 132534](https://github.com/user-attachments/assets/f1c38833-bed4-47ab-8b20-ce046474c1e0) - -#### 9️⃣ Change terminal Functionality -###### Preview

-![Screenshot 2025-05-18 130106](https://github.com/user-attachments/assets/da67e659-b3ec-4a57-9cf9-a25558248b9c) - -![Screenshot 2025-05-18 130126](https://github.com/user-attachments/assets/84487e3f-4d4e-43e2-9172-9bf1490dbdaf) - -![Screenshot 2025-05-18 130147](https://github.com/user-attachments/assets/94dd78a3-b3e7-467e-9aa2-a480c494d053) - -![Screenshot 2025-05-18 130201](https://github.com/user-attachments/assets/d59e18b1-c88b-44cf-badb-7eabd787aff7) - -![Screenshot 2025-05-18 130227](https://github.com/user-attachments/assets/2fd1dda3-8e27-4ffc-b3a5-44dcd04765b3) - -![Screenshot 2025-05-18 130301](https://github.com/user-attachments/assets/9fba52c3-b1a2-417e-9180-a5a1935cbb33) - -#### πŸ”Ÿ Calculus Operations in Calculator -###### Preview

-![Screenshot 2025-05-18 131128](https://github.com/user-attachments/assets/964a179f-0cf6-457a-b12e-b3c9021f9bf0) - -![Screenshot 2025-05-18 131248](https://github.com/user-attachments/assets/2f6dcd75-5a90-4f9f-802b-b36fbbe6a25e) - -![Screenshot 2025-05-18 131424](https://github.com/user-attachments/assets/a34d24c1-1a6b-4be2-88b8-1d1abd43f801) - -#### and many more... - -## πŸ§‘β€πŸ’» How to use: -1️⃣ Clone the Repository:
-```sh -git clone https://github.com/AnshMNSoni/PyShell.git -``` - -2️⃣ Install all require dependencies:
-```sh -pip install -r requirements.txt -``` - -3️⃣ SignUp to Open Weather For weather API: [Visit](https://openweathermap.org/) - -4️⃣ Replace you API_KEY: -- Inside `get_weather` function -- api_key = "YOUR_API_KEY"
- -###### Preview

-![image](https://github.com/user-attachments/assets/b6928f38-0319-48ba-aaaf-39d1f7b873e7) -
- -5️⃣ Lastly, Open you terminal and run:
-```sh -python main.py -``` - -## πŸ”Ž Future Work: -1️⃣ Upscale it to the Operating system (i.e. MyOS) - -## 🀝 Contributing to PyShell - -Thank you for considering contributing! Please follow these steps: - -1. **Fork** the repository. -2. **Create a new branch** (`git checkout -b feature-branch`). -3. **Commit your changes** (`git commit -m "Add new feature"`). -4. **Push to your fork** (`git push origin feature-branch`). -5. **Submit a Pull Request** and wait for review. - -### πŸ”— Connect with Me: -`GitHub` - [Visit](https://github.com/AnshMNSoni)
-`LinkedIn` - [Visit](https://linkedin.com/in/anshsoni)
-`Follow Us` - [Visit](https://linkedin.com/company/py-shell) - -## Thankyou πŸ˜€
+pybot/ +β”œβ”€β”€ llm_converter.py # Main logic to convert input β†’ shell command +β”œβ”€β”€ prompt_templates.json # Few-shot examples used in prompts +β”œβ”€β”€ .env # Stores OpenAI API key (not committed to Git) +└── README.md # You are here diff --git a/llmconverter.py b/llmconverter.py new file mode 100644 index 0000000..b56d89d --- /dev/null +++ b/llmconverter.py @@ -0,0 +1,62 @@ +import openai +import json +import os +from dotenv import load_dotenv + + +load_dotenv() +openai.api_key = os.getenv("OPENAI_API_KEY") + +def few_shot_examples(file_path='prompt_templates.json'): + try: + with open(file_path, 'r') as f: + examples = json.load(f) + return examples + except FileNotFoundError: + print('Few-shot examples file not found.') + return [] + +def build_prompt(user_input, examples): + msgs = [] + + msgs.append({ + "role": "system", + "content": "You are a helpful assistant that converts natural language into safe and efficient Linux shell commands. Only return the commandβ€”no explanations." + }) + + for ex in examples: + msgs.append({"role": "user", "content": ex["input"]}) + msgs.append({"role": "assistant", "content": ex["output"]}) + + msgs.append({ + "role": "user", + "content": user_input + }) + + return msgs + + +def generate_command(user_input): + examples = few_shot_examples() + messages = build_prompt(user_input, examples) + + try: + response = openai.ChatCompletion.create( + model='gpt-4', + messages=messages, + max_tokens=100, + temperature=0.2 + ) + return response + + except Exception as e: + print("Command generation failed:", e) + return 'Error generating command.' + +if __name__ == "__main__": + while True: + query = input("Enter your natural language (or 'exit'): ") + if query.lower() == "exit": + break + result = generate_command(query) + print("Generated shell command:", result) \ No newline at end of file diff --git a/prompt_templates.json b/prompt_templates.json new file mode 100644 index 0000000..2e640b6 --- /dev/null +++ b/prompt_templates.json @@ -0,0 +1,15 @@ +[ + { "input": "show hidden files", "output": "ls -a" }, + { "input": "list all files including subdirectories", "output": "ls -R" }, + { "input": "go to the home directory", "output": "cd 'name of the directory' " }, + { "input": "delete all .log files", "output": "rm *.log" }, + { "input": "create a folder named test", "output": "mkdir test" }, + { "input": "copy file.txt to the backup folder", "output": "cp file.txt backup/" }, + { "input": "move all .jpg files to images directory", "output": "mv *.jpg images/" }, + { "input": "show current directory path", "output": "pwd" }, + { "input": "find files with .py extension", "output": "find . -name \"*.py\"" }, + { "input": "display content of a file called notes.txt", "output": "cat notes.txt" }, + { "input": "clear the output " , "output" : "clear"}, + { "input": "extract a zip file", "output": "unzip file.zip" }, + { "input": "check available memory", "output": "free -h" } +] \ No newline at end of file