Fixed local instance

This commit is contained in:
jeffser
2024-05-28 11:24:50 -06:00
parent 19cc97a1c4
commit 257197d4d8
3 changed files with 19 additions and 16 deletions

View File

@@ -1,27 +1,23 @@
# local_instance.py
import subprocess, os
import subprocess, os, threading
from time import sleep
instance = None
port = 11435
data_dir = os.getenv("XDG_DATA_HOME")
def start(data_dir):
def start():
instance = subprocess.Popen(["/app/bin/ollama", "serve"], env={**os.environ, 'OLLAMA_HOST': f"127.0.0.1:{port}", "HOME": data_dir}, stderr=subprocess.PIPE, text=True)
print("Starting Alpaca's Ollama instance...")
sleep(1)
while True:
err = instance.stderr.readline()
if err == '' and instance.poll() is not None:
break
if 'msg="inference compute"' in err: #Ollama outputs a line with this when it finishes loading, yeah
break
print("Started Alpaca's Ollama instance")
def stop():
if instance: instance.kill()
print("Stopped Alpaca's Ollama instance")
def reset(data_dir):
def reset():
stop()
sleep(1)
start(data_dir)
start()