Better checker for Ollama instance missing
This commit is contained in:
parent
19a8aade60
commit
79a7840f24
@ -2,7 +2,7 @@
|
|||||||
"""
|
"""
|
||||||
Handles requests to remote and integrated instances of Ollama
|
Handles requests to remote and integrated instances of Ollama
|
||||||
"""
|
"""
|
||||||
import json, os, requests, subprocess, threading
|
import json, os, requests, subprocess, threading, shutil
|
||||||
from .internal import data_dir, cache_dir
|
from .internal import data_dir, cache_dir
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from time import sleep
|
from time import sleep
|
||||||
@ -92,25 +92,31 @@ class instance():
|
|||||||
self.idle_timer.start()
|
self.idle_timer.start()
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
if not os.path.isdir(os.path.join(cache_dir, 'tmp/ollama')):
|
if shutil.which('ollama'):
|
||||||
os.mkdir(os.path.join(cache_dir, 'tmp/ollama'))
|
if not os.path.isdir(os.path.join(cache_dir, 'tmp/ollama')):
|
||||||
self.instance = None
|
os.mkdir(os.path.join(cache_dir, 'tmp/ollama'))
|
||||||
params = self.overrides.copy()
|
self.instance = None
|
||||||
params["OLLAMA_DEBUG"] = "1"
|
params = self.overrides.copy()
|
||||||
params["OLLAMA_HOST"] = f"127.0.0.1:{self.local_port}" # You can't change this directly sorry :3
|
params["OLLAMA_DEBUG"] = "1"
|
||||||
params["HOME"] = data_dir
|
params["OLLAMA_HOST"] = f"127.0.0.1:{self.local_port}" # You can't change this directly sorry :3
|
||||||
params["TMPDIR"] = os.path.join(cache_dir, 'tmp/ollama')
|
params["HOME"] = data_dir
|
||||||
instance = subprocess.Popen(["ollama", "serve"], env={**os.environ, **params}, stderr=subprocess.PIPE, stdout=subprocess.PIPE, text=True)
|
params["TMPDIR"] = os.path.join(cache_dir, 'tmp/ollama')
|
||||||
threading.Thread(target=log_output, args=(instance.stdout,)).start()
|
instance = subprocess.Popen(["ollama", "serve"], env={**os.environ, **params}, stderr=subprocess.PIPE, stdout=subprocess.PIPE, text=True)
|
||||||
threading.Thread(target=log_output, args=(instance.stderr,)).start()
|
threading.Thread(target=log_output, args=(instance.stdout,)).start()
|
||||||
logger.info("Starting Alpaca's Ollama instance...")
|
threading.Thread(target=log_output, args=(instance.stderr,)).start()
|
||||||
logger.debug(params)
|
logger.info("Starting Alpaca's Ollama instance...")
|
||||||
logger.info("Started Alpaca's Ollama instance")
|
logger.debug(params)
|
||||||
v_str = subprocess.check_output("ollama -v", shell=True).decode('utf-8')
|
logger.info("Started Alpaca's Ollama instance")
|
||||||
logger.info('Ollama version: {}'.format(v_str.split('client version is ')[1].strip()))
|
v_str = subprocess.check_output("ollama -v", shell=True).decode('utf-8')
|
||||||
self.instance = instance
|
logger.info('Ollama version: {}'.format(v_str.split('client version is ')[1].strip()))
|
||||||
if not self.idle_timer:
|
self.instance = instance
|
||||||
self.start_timer()
|
if not self.idle_timer:
|
||||||
|
self.start_timer()
|
||||||
|
else:
|
||||||
|
self.remote = True
|
||||||
|
if not self.remote_url:
|
||||||
|
self.remote_url = 'http://0.0.0.0:11434'
|
||||||
|
window.connection_error()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
if self.idle_timer:
|
if self.idle_timer:
|
||||||
|
@ -777,12 +777,6 @@ Generate a title following these rules:
|
|||||||
if show_launch_dialog:
|
if show_launch_dialog:
|
||||||
GLib.idle_add(self.launch_dialog.present, self)
|
GLib.idle_add(self.launch_dialog.present, self)
|
||||||
|
|
||||||
#Check if Ollama instance doesn't exists
|
|
||||||
if not shutil.which('ollama'):
|
|
||||||
remote = True
|
|
||||||
if not remote_url:
|
|
||||||
remote_url = 'http://0.0.0.0:11434'
|
|
||||||
|
|
||||||
#Instance
|
#Instance
|
||||||
self.launch_level_bar.set_value(0)
|
self.launch_level_bar.set_value(0)
|
||||||
self.launch_status.set_description(_('Loading instance'))
|
self.launch_status.set_description(_('Loading instance'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user