Skip to content

Commit

Permalink
Added OS Type check for Linux Arch & Debian
Browse files Browse the repository at this point in the history
  • Loading branch information
haseeb-heaven committed Oct 17, 2024
1 parent c5ffe5e commit 3a4e6d7
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
.DS_Store
*.log
*.json
history/history.json
history/
output/*
*.env
.env
history.json
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ If you're interested in contributing to **Code-Interpreter**, we'd love to have
🔥 **v2.1** - Added AnhtorpicAI Claude-3 models powerful _Opus,Sonnet,Haiku_ models.
- **v2.1.1** - Added **Groq-AI** Model _Gemma-7B_ with **700 Tokens/Sec**.
- **v2.1.2** - Added **Prompt Modes** now you can set prompt from file as well just place your prompt in `prompt.txt` file inside `system` directory.
- **v2.1.3** - Updated **OS Type detection** now for Linux **Arch & Debian** and generate accurate commands for all OS types.

## 📜 **License**

Expand Down
24 changes: 19 additions & 5 deletions interpreter
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
"""
This is the main file for the Open-Code-Interpreter.
This is the main file for the Code-Interpreter.
It handles command line arguments and initializes the Interpreter.
Command line arguments:
Expand All @@ -20,29 +20,42 @@ from libs.interpreter_lib import Interpreter
import argparse
import sys
import traceback

import warnings
from libs.markdown_code import display_markdown_message
from libs.utility_manager import UtilityManager

# The main version of the interpreter.
INTERPRETER_VERSION = "2.1.3"

def main():
parser = argparse.ArgumentParser(description='Code - Interpreter')
parser.add_argument('--exec', '-e', action='store_true', default=False, help='Execute the code')
parser.add_argument('--save_code', '-s', action='store_true', default=False, help='Save the generated code')
parser.add_argument('--mode', '-md', choices=['code', 'script', 'command','vision','chat'], help='Select the mode (`code` for generating code, `script` for generating shell scripts, `command` for generating single line commands) `vision` for generating text from images')
parser.add_argument('--model', '-m', type=str, default='code-llama', help='Set the model for code generation. (Defaults to gpt-3.5-turbo)')
parser.add_argument('--version', '-v', action='version', version='%(prog)s 2.1')
parser.add_argument('--version', '-v', action='version', version='%(prog)s '+ INTERPRETER_VERSION)
parser.add_argument('--lang', '-l', type=str, default='python', help='Set the interpreter language. (Defaults to Python)')
parser.add_argument('--display_code', '-dc', action='store_true', default=False, help='Display the code in output')
parser.add_argument('--history', '-hi', action='store_true', default=False, help='Use history as memory')
parser.add_argument('--upgrade', '-up', action='store_true', default=False, help='Upgrade the interpreter')
parser.add_argument('--file', '-f', type=str, nargs='?', const='prompt.txt', default=None, help='Sets the file to read the input prompt from')
args = parser.parse_args()

# Check if only the application name is passed
if len(sys.argv) <= 1:
parser.print_help()
return

warnings.filterwarnings("ignore") # To ignore all warnings

# Upgrade the interpreter if the --upgrade flag is passed.
if args.upgrade:
UtilityManager.upgrade_interpreter()
return

# Create an instance of the Interpreter class and call the main method.
interpreter = Interpreter(args)
interpreter.interpreter_main()
interpreter.interpreter_main(INTERPRETER_VERSION)

if __name__ == "__main__":
try:
Expand All @@ -58,7 +71,8 @@ to setup the interpreter:\n\
1. Create a .env file in the root directory of the project.\n\
2. Add the following line to the .env file:\n\
GEMINI_API_KEY=<your api key>\n\
OPENIA_API_KEY=<your api key>\n\
OPENAI_API_KEY=<your api key>\n\
ANTHROPIC_API_KEY=<your api key>\n\
3. Replace <your api key> with your OpenAI/Gemini API key.\n\
4. Run the interpreter again.")

Expand Down
2 changes: 1 addition & 1 deletion interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from libs.utility_manager import UtilityManager

# The main version of the interpreter.
INTERPRETER_VERSION = "2.1.2"
INTERPRETER_VERSION = "2.1.3"

def main():
parser = argparse.ArgumentParser(description='Code - Interpreter')
Expand Down
6 changes: 4 additions & 2 deletions libs/interpreter_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,15 +371,17 @@ def generate_content(self,message, chat_history: list[tuple[str, str]], temperat
return generated_text

def get_code_prompt(self, task, os_name):
prompt = f"Generate the code in {self.INTERPRETER_LANGUAGE} language for this task '{task} for Operating System: {os_name}'."
prompt = f"Generate the code in {self.INTERPRETER_LANGUAGE} language for this task '{task} \
for Operating System: {os_name}'. Ensure the script is compatible with the specified OS and its version."
return prompt

def get_script_prompt(self, task, os_name):
language_map = {'macos': 'applescript', 'linux': 'bash', 'windows': 'powershell'}
self.INTERPRETER_LANGUAGE = language_map.get(os_name.lower(), 'python')

script_type = 'Apple script' if os_name.lower() == 'macos' else 'Bash Shell script' if os_name.lower() == 'linux' else 'Powershell script' if os_name.lower() == 'windows' else 'script'
prompt = f"\nGenerate {script_type} for this prompt and make this script easy to read and understand for this task '{task} for Operating System is {os_name}'."
prompt = f"\nGenerate {script_type} for this prompt and make this script easy to read and understand for this task \
'{task} for Operating System is {os_name}' Ensure the script is compatible with the specified OS and its version."
return prompt

def get_command_prompt(self, task, os_name):
Expand Down
25 changes: 16 additions & 9 deletions libs/utility_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,26 @@ def _extract_content(self,output):

def get_os_platform(self):
try:
import platform
os_info = platform.uname()
os_name = os_info.system
os_version = os_info.release

os_name_mapping = {
'Darwin': 'MacOS',
'Linux': 'Linux',
'Windows': 'Windows'
}
if os_name == 'Linux':
# Attempt to get distribution info
try:
import distro
distro_info = distro.info()
os_name = f"{os_name} ({distro_info['id']} {distro_info['version_parts']['major']})" # e.g., "Linux (ubuntu 22)"
except ImportError:
self.logger.warning("distro package not found. Linux distribution details will be less specific.")
# Fallback if distro is not installed
os_name = f"{os_name} ({os_version})"
elif os_name == 'Windows':
os_name = f"{os_name} {platform.version()}"
elif os_name == 'Darwin': # macOS
os_name = f"{os_name} {platform.mac_ver()[0]}"

os_name = os_name_mapping.get(os_name, 'Other')

self.logger.info(f"Operating System: {os_name} Version: {os_info.version}")
self.logger.info(f"Operating System: {os_name}")
return os_name, os_info.version
except Exception as exception:
self.logger.error(f"Error in getting OS platform: {str(exception)}")
Expand Down

0 comments on commit 3a4e6d7

Please sign in to comment.