Lagt till hantering av host_url där LLM:er körs.
This commit is contained in:
@@ -40,10 +40,8 @@ def fetch_models_from_endpoints(endpoints, global_state):
|
||||
if isinstance(models, dict) and 'error' in models:
|
||||
logger.error('Error fetching models from backend: %s', models['error'])
|
||||
else:
|
||||
endpoint["models"] = models.get("models", []) # get the list of models directly
|
||||
logger.debug("models = \n{}".format(json.dumps(models, indent=4)))
|
||||
if endpoint["model"] is not "AUTODETECT": # Check if specified model is available
|
||||
logger.debug("Asking for specific model")
|
||||
endpoint["models"] = models.get("models", []) # Get the list of models directly
|
||||
# logger.debug("models = \n{}".format(json.dumps(models, indent=4)))
|
||||
|
||||
|
||||
class GlobalState:
|
||||
@@ -67,6 +65,7 @@ class GlobalState:
|
||||
cls._instance.logger.addHandler(handler)
|
||||
cls._instance.logger.setLevel(getattr(logging, cls._instance.log_level)) # Initialize root logger level
|
||||
cls._instance.logger.info(" __new__(cls): Logger in GlobalState created: %s", cls._instance.logger)
|
||||
cls._instance.host_url = None # Currently used LLM host
|
||||
cls._instance.llm = "phi3:mini" # Default LLM for queries. TODO: Check with ollama server that it actually exists
|
||||
# cls._instance.backend_api_ep = "http://localhost:5005/api/chat" # Default backend API endpoint
|
||||
# Try making things more aligned with the outline of the yaml file
|
||||
@@ -105,6 +104,14 @@ class GlobalState:
|
||||
logger = logging.getLogger(module_name)
|
||||
return logger
|
||||
|
||||
def set_host_url(self, url="http://localhost:11434"):
|
||||
"""Set the host url to which LLM requests are sent"""
|
||||
self.host = url
|
||||
|
||||
def get_host_url(self):
|
||||
"""Get the url for the currently used host for LLMs"""
|
||||
return self.host_url
|
||||
|
||||
def set_llm(self, model_name="phi3:mini"):
|
||||
"""Set LLM for queries"""
|
||||
self.llm = model_name
|
||||
@@ -114,11 +121,11 @@ class GlobalState:
|
||||
return self.llm
|
||||
|
||||
def set_backend(self, backend=None):
|
||||
"""Set backend that web clients connect to"""
|
||||
"""Set backend server that web clients connect to"""
|
||||
self.backend = backend
|
||||
|
||||
def get_backend(self):
|
||||
"""Getter for backend that web clients connect to"""
|
||||
"""Getter for backend server that web clients connect to"""
|
||||
return self.backend
|
||||
|
||||
def get_backend_api_ep(self):
|
||||
@@ -134,4 +141,11 @@ class GlobalState:
|
||||
|
||||
def get_endpoints(self):
|
||||
"""Return the list of endpoints"""
|
||||
return self.endpoints
|
||||
return self.endpoints
|
||||
|
||||
def get_list_of_available_llms(self, endpoint=None):
|
||||
"""Return a sorted list of LLMs available at endpoint"""
|
||||
llm_list = None
|
||||
if isinstance(endpoint["models"], list):
|
||||
llm_list = sorted([list_item['name'] for list_item in endpoint["models"]], key=str.lower)
|
||||
return llm_list
|
||||
Reference in New Issue
Block a user