diff --git a/libs/interpreter_lib.py b/libs/interpreter_lib.py index 7a7248e..18e93e4 100644 --- a/libs/interpreter_lib.py +++ b/libs/interpreter_lib.py @@ -484,7 +484,25 @@ def interpreter_main(self): # 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') + + # Download the requirements file + requirements_file_url = 'https://raw.githubusercontent.com/haseeb-heaven/code-interpreter/main/requirements.txt' + requirements_file_downloaded = self.utility_manager.download_file(requirements_file_url,'requirements.txt') + + # Commands to execute. + command_pip_upgrade = 'pip install open-code-interpreter --upgrade' + command_pip_requirements = 'pip install -r requirements.txt --upgrade' + + # Execute the commands. + command_output,_ = self.code_interpreter.execute_command(command_pip_upgrade) + display_markdown_message(f"Command Upgrade executed successfully.") + if requirements_file_downloaded: + command_output,_ = self.code_interpreter.execute_command(command_pip_requirements) + display_markdown_message(f"Command Requirements executed successfully.") + else: + self.logger.warn(f"Requirements file not downloaded.") + display_markdown_message(f"Warning: Requirements file not downloaded.") + if command_output: self.logger.info(f"Command executed successfully.") display_code(command_output) diff --git a/libs/utility_manager.py b/libs/utility_manager.py index c246553..ad81e70 100644 --- a/libs/utility_manager.py +++ b/libs/utility_manager.py @@ -218,4 +218,21 @@ def display_version(self,version): display_markdown_message(f"Interpreter - v{version}") def clear_screen(self): - os.system('cls' if os.name == 'nt' else 'clear') \ No newline at end of file + os.system('cls' if os.name == 'nt' else 'clear') + + # method to download file from Web and save it + + def download_file(self,url,file_name): + try: + import requests + self.logger.info(f"Downloading file: {url}") + response = requests.get(url, allow_redirects=True) + response.raise_for_status() + + with open(file_name, 'wb') as file: + file.write(response.content) + self.logger.info(f"Reuquirements.txt file downloaded.") + return True + except Exception as exception: + self.logger.error(f"Error in downloading file: {str(exception)}") + return False