33import platform
44import re
55import subprocess
6+ from libs .code_interpreter import CodeInterpreter
67from libs .logger import Logger
78import csv
89import glob
910from datetime import datetime
1011
11- from libs .markdown_code import display_markdown_message
12+ from libs .markdown_code import display_code , display_markdown_message
1213
1314class UtilityManager :
15+ logger = None
1416 def __init__ (self ):
1517 try :
1618 if not os .path .exists ('logs' ):
@@ -222,17 +224,46 @@ def clear_screen(self):
222224
223225 # method to download file from Web and save it
224226
225- def download_file (self ,url ,file_name ):
227+ @staticmethod
228+ def _download_file (url ,file_name ):
226229 try :
230+ logger = Logger .initialize_logger ("logs/interpreter.log" )
227231 import requests
228- self . logger .info (f"Downloading file: { url } " )
232+ logger .info (f"Downloading file: { url } " )
229233 response = requests .get (url , allow_redirects = True )
230234 response .raise_for_status ()
231235
232236 with open (file_name , 'wb' ) as file :
233237 file .write (response .content )
234- self . logger .info (f"Reuquirements.txt file downloaded." )
238+ logger .info (f"Reuquirements.txt file downloaded." )
235239 return True
236240 except Exception as exception :
237- self . logger .error (f"Error in downloading file: { str (exception )} " )
241+ logger .error (f"Error in downloading file: { str (exception )} " )
238242 return False
243+
244+ @staticmethod
245+ def upgrade_interpreter ():
246+ code_interpreter = CodeInterpreter ()
247+ logger = Logger .initialize_logger ("logs/interpreter.log" )
248+ # Download the requirements file
249+ requirements_file_url = 'https://raw.githubusercontent.com/haseeb-heaven/code-interpreter/main/requirements.txt'
250+ requirements_file_downloaded = UtilityManager ._download_file (requirements_file_url ,'requirements.txt' )
251+
252+ # Commands to execute.
253+ command_pip_upgrade = 'pip install open-code-interpreter --upgrade'
254+ command_pip_requirements = 'pip install -r requirements.txt --upgrade'
255+
256+ # Execute the commands.
257+ command_output ,_ = code_interpreter .execute_command (command_pip_upgrade )
258+ display_markdown_message (f"Command Upgrade executed successfully." )
259+ if requirements_file_downloaded :
260+ command_output ,_ = code_interpreter .execute_command (command_pip_requirements )
261+ display_markdown_message (f"Command Requirements executed successfully." )
262+ else :
263+ logger .warn (f"Requirements file not downloaded." )
264+ display_markdown_message (f"Warning: Requirements file not downloaded." )
265+
266+ if command_output :
267+ logger .info (f"Command executed successfully." )
268+ display_code (command_output )
269+ logger .info (f"Output: { command_output [:100 ]} " )
0 commit comments