From 3472562de7564a2952c6c6956ef2631c5dde0181 Mon Sep 17 00:00:00 2001 From: artitw Date: Tue, 29 Oct 2024 01:23:57 +0000 Subject: [PATCH] assistant updates --- setup.py | 2 +- text2text/assistant.py | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 5d28a39..787d1fe 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="text2text", - version="1.8.2", + version="1.8.3", author="artitw", author_email="artitw@gmail.com", description="Text2Text Language Modeling Toolkit", diff --git a/text2text/assistant.py b/text2text/assistant.py index 369484a..05b97d1 100644 --- a/text2text/assistant.py +++ b/text2text/assistant.py @@ -3,11 +3,24 @@ import time import subprocess import warnings +import platform from tqdm.auto import tqdm from llama_index.llms.ollama import Ollama from llama_index.core.llms import ChatMessage +def can_use_apt(): + # Check if the OS is Linux and if it is a Debian-based distribution + if platform.system() == "Linux": + try: + # Check if the apt command is available + result = os.system("apt --version") + return result == 0 # If the command runs successfully, return True + except Exception as e: + print(f"An error occurred: {e}") + return False + return False + def ollama_version(): try: result = subprocess.check_output(["ollama", "-v"], stderr=subprocess.STDOUT).decode("utf-8") @@ -62,10 +75,15 @@ def load_model(self): self.__del__() pbar.update(1) - return_code = os.system("apt install -q -y lshw") - if return_code != 0: - raise Exception("Cannot install lshw.") - pbar.update(1) + if can_use_apt(): + return_code = os.system("apt install -q -y lshw curl") + if return_code != 0: + raise Exception("Cannot install lshw and/or curl.") + pbar.update(1) + elif platform.system() == "Windows": + raise Exception("Windows not supported.") + else: + pbar.update(1) result = os.system( "curl -fsSL https://ollama.com/install.sh | sh"