Skip to content

Commit

Permalink
Update interpreter version and add new commands
Browse files Browse the repository at this point in the history
  • Loading branch information
haseeb-heaven committed Jan 8, 2024
1 parent 2725f32 commit 3d4c568
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 14 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ Here are the available commands:
- 📝 `/save` - Save the last code generated.
- ✏️ `/edit` - Edit the last code generated.
- ▶️ `/execute` - Execute the last code generated.
- 🐛 `/debug` - Debug the last code generated.
- 🔄 `/mode` - Change the mode of interpreter.
- 🔄 `/model` - Change the model for interpreter.
- 📦 `/install` - Install a package from npm or pip.
Expand All @@ -224,6 +223,9 @@ Here are the available commands:
- 🆘 `/help` - Display this help message.
- 📝 `/version` - Display the version of the interpreter.
- 🚪 `/exit` - Exit the interpreter.
- 📜 `/log` - Display the log.
-`/upgrade` - Upgrade the interpreter.
- 💻 `/shell` - Access the shell.


## 📖 **Examples**
Expand Down
2 changes: 1 addition & 1 deletion interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def main():
parser.add_argument('--save_code', '-s', action='store_true', help='Save the generated code')
parser.add_argument('--mode', '-md', choices=['code', 'script', 'command','vision'], 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 1.8.1')
parser.add_argument('--version', '-v', action='version', version='%(prog)s 1.8.3')
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', help='Display the code in output')
args = parser.parse_args()
Expand Down
59 changes: 48 additions & 11 deletions libs/interpreter_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
import platform
import subprocess
import time
import webbrowser
from libs.code_interpreter import CodeInterpreter
from litellm import completion
from libs.logger import Logger
from libs.markdown_code import display_code, display_markdown_message
from libs.package_manager import PackageManager
from libs.utility_manager import UtilityManager
from dotenv import load_dotenv

import shlex

class Interpreter:
logger = None
client = None
interpreter_version = "1.8.1"
interpreter_version = "1.8.3"

def __init__(self, args):
self.args = args
Expand Down Expand Up @@ -421,9 +421,46 @@ def interpreter_main(self):
elif task.lower() == '/version':
self.utility_manager.display_version(self.interpreter_version)
continue

# SHELL - Command section.
elif any(command in task.lower() for command in ['/shell ']):
shell_command = shlex.split(task)[1:]
shell_command = ' '.join(shell_command)
shell_output, shell_error = self.code_interpreter.execute_command(shell_command)
if shell_output:
self.logger.info(f"Shell command executed successfully.")
display_code(shell_output)
self.logger.info(f"Output: {shell_output[:100]}")
elif shell_error:
self.logger.info(f"Shell command executed with error.")
display_markdown_message(f"Error: {shell_error}")
continue

# LOG - Command section.
elif task.lower() == '/log':
# open the folder logs/interepreter.log in current working directory and open it in text editor based on OS type
log_file = os.path.join(os.getcwd(), 'logs', 'interpreter.log')
if os.path.isfile(log_file):
if os_name.lower() == 'macos':
self.logger.info(f"Opening log file in default editor {log_file}")
subprocess.call(('open', log_file))
elif os_name.lower() == 'linux':
subprocess.call(('xdg-open', log_file))
elif os_name.lower() == 'windows':
os.startfile(log_file)
continue

# UPGRAGE - Command section.
elif task.lower() == '/upgrade':
command_output,_ = self.code_interpreter.execute_command('pip install open-code-interpreter --upgrade && pip install -r requirements.txt --upgrade')
if command_output:
self.logger.info(f"Command executed successfully.")
display_code(command_output)
self.logger.info(f"Output: {command_output[:100]}")
continue

# EXECUTE - Command section.
elif task.lower() in ['/execute','/exec']:
elif task.lower() == '/execute':
self.execute_last_code(os_name,self.INTERPRETER_LANGUAGE)
continue

Expand All @@ -447,20 +484,20 @@ def interpreter_main(self):
display_markdown_message(f"Open code in **vim** editor (Y/N):")
vim_open = input()
if vim_open.lower() == 'y':
self.logger.info(f"Opening code in **vim** editor {code_file}")
subprocess.call(['vim', code_file])
self.logger.info(f"Opening code in **vim** editor {code_file.name}")
subprocess.call(['vim', code_file.name])
continue
else:
# Open the code in default editor.
if os_platform[0].lower() == 'macos':
self.logger.info(f"Opening code in default editor {code_file}")
subprocess.call(('open', code_file))
subprocess.call(('open', code_file.name))
elif os_platform[0].lower() == 'linux':
subprocess.call(('xdg-open', code_file))
subprocess.call(('xdg-open', code_file.name))
elif os_platform[0].lower() == 'windows':
os.startfile(code_file)
os.startfile(code_file.name)
continue

# DEBUG - Command section.
elif task.lower() == '/debug':

Expand Down Expand Up @@ -535,7 +572,7 @@ def interpreter_main(self):
continue

# LANGUAGE - Command section.
elif any(command in task.lower() for command in ['/language', '/lang']):
elif any(command in task.lower() for command in ['/language','/lang']):
split_task = task.split(' ')
if len(split_task) > 1:
language = split_task[1]
Expand Down
5 changes: 4 additions & 1 deletion libs/utility_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ def display_help(self):
/language - Change the language of the interpreter.\n\
/clear - Clear the screen.\n\
/help - Display this help message.\n\
/version - Display the version of the interpreter.\n")
/version - Display the version of the interpreter.\n\
/log - Display the log.\n\
/upgrade - Upgrade the interpreter.\n\
/shell - Access the shell.\n")

def display_version(self,version):
display_markdown_message(f"Interpreter - {version}")
Expand Down

0 comments on commit 3d4c568

Please sign in to comment.