Fixed local instance
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user