|
32 | 32 | import shlex |
33 | 33 | import shutil |
34 | 34 | from rich.console import Console |
35 | | -from rich.text import Text |
36 | 35 |
|
37 | 36 | litellm.set_verbose = False |
38 | 37 | litellm.suppress_debug_info = True |
@@ -1242,7 +1241,7 @@ def interpreter_main(self, version): |
1242 | 1241 | elif any(command in task.lower() for command in ['/mode ']): |
1243 | 1242 | mode = task.split(' ')[1] |
1244 | 1243 | if mode: |
1245 | | - if not mode.lower() in ['code','script','command','vision','chat']: |
| 1244 | + if mode.lower() not in ['code','script','command','vision','chat']: |
1246 | 1245 | mode = 'code' |
1247 | 1246 | display_markdown_message(f"The input mode is not supported. Mode changed to {mode}," |
1248 | 1247 | "\nUse '/list' command to get the list of supported modes.") |
@@ -1290,22 +1289,46 @@ def interpreter_main(self, version): |
1290 | 1289 | continue |
1291 | 1290 |
|
1292 | 1291 | # INSTALL - Command section. |
1293 | | - elif any(command in task.lower() for command in ['/install']): |
1294 | | - # get the package name after the command |
1295 | | - package_name = task.split(' ')[1] |
| 1292 | + elif task.lower().startswith('/install'): |
| 1293 | + parts = task.split(' ') |
| 1294 | + if len(parts) >= 3: |
| 1295 | + # Case: /install <language> <package> |
| 1296 | + language = parts[1].lower() |
| 1297 | + package_name = parts[2] |
| 1298 | + |
| 1299 | + # Validate language |
| 1300 | + if language in ['python', 'py']: |
| 1301 | + language = 'python' |
| 1302 | + elif language in ['javascript', 'js', 'node']: |
| 1303 | + language = 'javascript' |
| 1304 | + else: |
| 1305 | + # If unknown language, treat as package name to be safe |
| 1306 | + package_name = parts[1] |
| 1307 | + language = self.INTERPRETER_LANGUAGE |
| 1308 | + elif len(parts) == 2: |
| 1309 | + package_name = parts[1] |
| 1310 | + language = self.INTERPRETER_LANGUAGE |
| 1311 | + else: |
| 1312 | + display_markdown_message("Usage: **/install [language] <package_name>**") |
| 1313 | + continue |
1296 | 1314 |
|
1297 | 1315 | # check if package name is not system module. |
1298 | 1316 | system_modules = self.package_manager.get_system_modules() |
1299 | 1317 |
|
1300 | | - # Skip installing system modules. |
1301 | 1318 | if package_name in system_modules: |
1302 | 1319 | self.logger.info(f"Package {package_name} is a system module.") |
1303 | 1320 | display_markdown_message(f"Package {package_name} is a system module.") |
1304 | | - raise Exception(f"Package {package_name} is a system module.") |
| 1321 | + continue |
1305 | 1322 |
|
1306 | 1323 | if package_name: |
1307 | | - self.logger.info(f"Installing package {package_name} on interpreter {self.INTERPRETER_LANGUAGE}") |
1308 | | - self.package_manager.install_package(package_name, self.INTERPRETER_LANGUAGE) |
| 1324 | + self.logger.info(f"Installing package {package_name} for {language}") |
| 1325 | + display_markdown_message(f"Installing package **{package_name}** for **{language}**...") |
| 1326 | + try: |
| 1327 | + self.package_manager.install_package(package_name, language) |
| 1328 | + display_markdown_message(f"Successfully installed **{package_name}**") |
| 1329 | + except Exception as ex: |
| 1330 | + self.logger.error(f"Manual installation failed: {ex}") |
| 1331 | + display_markdown_message(f"Failed to install **{package_name}**: {ex}") |
1309 | 1332 | continue |
1310 | 1333 |
|
1311 | 1334 | # Get the prompt based on the mode. |
@@ -1492,21 +1515,32 @@ def interpreter_main(self, version): |
1492 | 1515 | raise Exception(f"Package {package_name} is a system module.") |
1493 | 1516 |
|
1494 | 1517 | if package_name: |
1495 | | - self.logger.info(f"Installing package {package_name} on interpreter {self.INTERPRETER_LANGUAGE}") |
1496 | | - self.package_manager.install_package(package_name, self.INTERPRETER_LANGUAGE) |
1497 | | - |
1498 | | - # Wait and Execute the code again. |
1499 | | - time.sleep(3) |
1500 | | - code_output, code_error = self._execute_generated_output(code_snippet, os_name, force_execute=True) |
1501 | | - if code_output: |
1502 | | - self.logger.info(f"{self.INTERPRETER_LANGUAGE} code executed successfully.") |
1503 | | - display_code(code_output) |
1504 | | - self.logger.info(f"Output: {code_output[:100]}") |
1505 | | - elif code_error: |
1506 | | - self.logger.info(f"{self.INTERPRETER_LANGUAGE} code executed with error.") |
1507 | | - display_markdown_message(f"Error: {code_error}") |
1508 | | - else: |
1509 | | - display_markdown_message("Execution completed successfully. No stdout was produced.") |
| 1518 | + for attempt in range(1, 4): |
| 1519 | + try: |
| 1520 | + self.logger.info(f"Installing package {package_name} on interpreter {self.INTERPRETER_LANGUAGE} (Attempt {attempt}/3)") |
| 1521 | + self.package_manager.install_package(package_name, self.INTERPRETER_LANGUAGE) |
| 1522 | + |
| 1523 | + # Wait and Execute the code again. |
| 1524 | + time.sleep(3) |
| 1525 | + code_output, code_error = self._execute_generated_output(code_snippet, os_name, force_execute=True) |
| 1526 | + if code_output: |
| 1527 | + self.logger.info(f"{self.INTERPRETER_LANGUAGE} code executed successfully.") |
| 1528 | + display_code(code_output) |
| 1529 | + self.logger.info(f"Output: {code_output[:100]}") |
| 1530 | + elif code_error: |
| 1531 | + self.logger.info(f"{self.INTERPRETER_LANGUAGE} code executed with error.") |
| 1532 | + display_markdown_message(f"Error: {code_error}") |
| 1533 | + else: |
| 1534 | + display_markdown_message("Execution completed successfully. No stdout was produced.") |
| 1535 | + break # Exit retry loop on success |
| 1536 | + except Exception as ex: |
| 1537 | + if attempt < 3: |
| 1538 | + self.logger.warning(f"Attempt {attempt} to install package {package_name} failed: {ex}") |
| 1539 | + display_markdown_message(f"Attempt {attempt}/3 to install package **{package_name}** failed. Retrying in 2 seconds...") |
| 1540 | + time.sleep(2) |
| 1541 | + else: |
| 1542 | + self.logger.error(f"Failed to install package {package_name} after 3 attempts: {ex}") |
| 1543 | + display_markdown_message(f"Failed to install package **{package_name}** after 3 attempts. Error: {ex}. Proceeding with repair logic...") |
1510 | 1544 |
|
1511 | 1545 | if code_error and not code_error.startswith("Safety blocked:"): |
1512 | 1546 | code_snippet, repaired_output, repaired_error = self._attempt_repair_after_failure( |
|
0 commit comments