Skip to content

Commit 3a4e6d7

Browse files
committed
Added OS Type check for Linux Arch & Debian
1 parent c5ffe5e commit 3a4e6d7

File tree

6 files changed

+43
-18
lines changed

6 files changed

+43
-18
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
.DS_Store
66
*.log
77
*.json
8-
history/history.json
8+
history/
99
output/*
1010
*.env
1111
.env
12+
history.json

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ If you're interested in contributing to **Code-Interpreter**, we'd love to have
320320
🔥 **v2.1** - Added AnhtorpicAI Claude-3 models powerful _Opus,Sonnet,Haiku_ models.
321321
- **v2.1.1** - Added **Groq-AI** Model _Gemma-7B_ with **700 Tokens/Sec**.
322322
- **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.
323+
- **v2.1.3** - Updated **OS Type detection** now for Linux **Arch & Debian** and generate accurate commands for all OS types.
323324

324325
## 📜 **License**
325326

interpreter

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22
"""
3-
This is the main file for the Open-Code-Interpreter.
3+
This is the main file for the Code-Interpreter.
44
It handles command line arguments and initializes the Interpreter.
55
66
Command line arguments:
@@ -20,29 +20,42 @@ from libs.interpreter_lib import Interpreter
2020
import argparse
2121
import sys
2222
import traceback
23-
23+
import warnings
2424
from libs.markdown_code import display_markdown_message
25+
from libs.utility_manager import UtilityManager
26+
27+
# The main version of the interpreter.
28+
INTERPRETER_VERSION = "2.1.3"
2529

2630
def main():
2731
parser = argparse.ArgumentParser(description='Code - Interpreter')
2832
parser.add_argument('--exec', '-e', action='store_true', default=False, help='Execute the code')
2933
parser.add_argument('--save_code', '-s', action='store_true', default=False, help='Save the generated code')
3034
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')
3135
parser.add_argument('--model', '-m', type=str, default='code-llama', help='Set the model for code generation. (Defaults to gpt-3.5-turbo)')
32-
parser.add_argument('--version', '-v', action='version', version='%(prog)s 2.1')
36+
parser.add_argument('--version', '-v', action='version', version='%(prog)s '+ INTERPRETER_VERSION)
3337
parser.add_argument('--lang', '-l', type=str, default='python', help='Set the interpreter language. (Defaults to Python)')
3438
parser.add_argument('--display_code', '-dc', action='store_true', default=False, help='Display the code in output')
3539
parser.add_argument('--history', '-hi', action='store_true', default=False, help='Use history as memory')
40+
parser.add_argument('--upgrade', '-up', action='store_true', default=False, help='Upgrade the interpreter')
41+
parser.add_argument('--file', '-f', type=str, nargs='?', const='prompt.txt', default=None, help='Sets the file to read the input prompt from')
3642
args = parser.parse_args()
3743

3844
# Check if only the application name is passed
3945
if len(sys.argv) <= 1:
4046
parser.print_help()
4147
return
48+
49+
warnings.filterwarnings("ignore") # To ignore all warnings
4250

51+
# Upgrade the interpreter if the --upgrade flag is passed.
52+
if args.upgrade:
53+
UtilityManager.upgrade_interpreter()
54+
return
55+
4356
# Create an instance of the Interpreter class and call the main method.
4457
interpreter = Interpreter(args)
45-
interpreter.interpreter_main()
58+
interpreter.interpreter_main(INTERPRETER_VERSION)
4659

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

interpreter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from libs.utility_manager import UtilityManager
2525

2626
# The main version of the interpreter.
27-
INTERPRETER_VERSION = "2.1.2"
27+
INTERPRETER_VERSION = "2.1.3"
2828

2929
def main():
3030
parser = argparse.ArgumentParser(description='Code - Interpreter')

libs/interpreter_lib.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,17 @@ def generate_content(self,message, chat_history: list[tuple[str, str]], temperat
371371
return generated_text
372372

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

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

381382
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'
382-
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}'."
383+
prompt = f"\nGenerate {script_type} for this prompt and make this script easy to read and understand for this task \
384+
'{task} for Operating System is {os_name}' Ensure the script is compatible with the specified OS and its version."
383385
return prompt
384386

385387
def get_command_prompt(self, task, os_name):

libs/utility_manager.py

+16-9
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,26 @@ def _extract_content(self,output):
5656

5757
def get_os_platform(self):
5858
try:
59-
import platform
6059
os_info = platform.uname()
6160
os_name = os_info.system
61+
os_version = os_info.release
6262

63-
os_name_mapping = {
64-
'Darwin': 'MacOS',
65-
'Linux': 'Linux',
66-
'Windows': 'Windows'
67-
}
63+
if os_name == 'Linux':
64+
# Attempt to get distribution info
65+
try:
66+
import distro
67+
distro_info = distro.info()
68+
os_name = f"{os_name} ({distro_info['id']} {distro_info['version_parts']['major']})" # e.g., "Linux (ubuntu 22)"
69+
except ImportError:
70+
self.logger.warning("distro package not found. Linux distribution details will be less specific.")
71+
# Fallback if distro is not installed
72+
os_name = f"{os_name} ({os_version})"
73+
elif os_name == 'Windows':
74+
os_name = f"{os_name} {platform.version()}"
75+
elif os_name == 'Darwin': # macOS
76+
os_name = f"{os_name} {platform.mac_ver()[0]}"
6877

69-
os_name = os_name_mapping.get(os_name, 'Other')
70-
71-
self.logger.info(f"Operating System: {os_name} Version: {os_info.version}")
78+
self.logger.info(f"Operating System: {os_name}")
7279
return os_name, os_info.version
7380
except Exception as exception:
7481
self.logger.error(f"Error in getting OS platform: {str(exception)}")

0 commit comments

Comments
 (0)