Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Fixes restart every second message #8

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ooba/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def install(force_reinstall=False, verbose=False, cpu=False, gpu_choice=None, fu
total_lines = 1738
pbar = tqdm(total=total_lines, ncols=100)

for cmd in [base_cmd, update_cmd]:
for cmd in update_cmd:
process = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, bufsize=1)

# Read the output line by line
Expand Down
28 changes: 11 additions & 17 deletions ooba/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
REPO_DIR = os.path.join(get_app_dir(), 'text-generation-ui')

class llm:
def __init__(self, path, cpu=False, verbose=False, first_time=True):
def __init__(self, path, cpu=False, verbose=False):

if first_time:
print("\nGetting started...")
print("Initializing server, please wait...")

try:
self.path = path
Expand All @@ -42,8 +41,8 @@ def __init__(self, path, cpu=False, verbose=False, first_time=True):
install_oobabooga(gpu_choice=self.gpu_choice)

# Start oobabooga server
model_dir = "/".join(path.split("/")[:-1])
model_name = path.split("/")[-1]
model_dir = os.path.dirname(path)
model_name = os.path.basename(path)

# Find an open port
while True:
Expand Down Expand Up @@ -103,7 +102,7 @@ def __init__(self, path, cpu=False, verbose=False, first_time=True):
else:
if self.verbose:
print(f"Server is not ready... ({attempt+1}/{num_attempts})")
time.sleep(1.5)
time.sleep(5)
else:
raise Exception("Server took too long to start")

Expand Down Expand Up @@ -132,20 +131,15 @@ def __init__(self, path, cpu=False, verbose=False, first_time=True):
install_oobabooga(force_reinstall=True, cpu=True)
self.__init__(path, cpu=True, verbose=self.verbose)

if first_time:
# Hack to fix it not working multiple times in a row. Must change this soon
self.first_time = True


def chat(self, messages, max_tokens=None, temperature=0):

# Hack to fix it not working multiple times in a row. Must change this soon
if self.first_time:
self.first_time = False
else:
# If port is closed, Terminate and restart server
if self.port not in get_open_ports(self.port, self.port +1):
if self.verbose:
print(f"Port {self.port} is not open. Restarting server")
self.process.terminate()
self.__init__(self.path, cpu=self.cpu, verbose=self.verbose, first_time=False)
self.__init__(self.path, cpu=self.cpu, verbose=self.verbose)

if any([message["role"] == "system" for message in messages[1:]]):
raise ValueError("Only the first message can have {'role': 'system'}.")

Expand Down