Anpassat anrop för att hämta lista av endpoints till den nya klassmetoden. Sätter url och llm enligt första modellen i första endpoint i yaml-konfigurationen.
This commit is contained in:
@@ -5,11 +5,11 @@ import yaml
|
|||||||
import json
|
import json
|
||||||
import socket
|
import socket
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from backend import run_flask, tag
|
from backend import run_flask
|
||||||
import logging
|
import logging
|
||||||
import requests
|
import requests
|
||||||
import utils
|
import utils
|
||||||
from utils import GlobalState, fetch_models_from_endpoints
|
from utils import GlobalState
|
||||||
|
|
||||||
global_state = GlobalState() # Configure root logger. The level will be adjusted later based on config file
|
global_state = GlobalState() # Configure root logger. The level will be adjusted later based on config file
|
||||||
logger = global_state.getLogger(__name__) # Logger for this module, inherit properties of the root logger
|
logger = global_state.getLogger(__name__) # Logger for this module, inherit properties of the root logger
|
||||||
@@ -44,7 +44,7 @@ def configure():
|
|||||||
|
|
||||||
def update_dict_with_env_vars(d): # Check all keys in d
|
def update_dict_with_env_vars(d): # Check all keys in d
|
||||||
for key in d: # Iterate over all keys in the dictionary. The keys seen are all at the top-level of d
|
for key in d: # Iterate over all keys in the dictionary. The keys seen are all at the top-level of d
|
||||||
logger.info(f"key investigated now: {key}")
|
# logger.info(f"key investigated now: {key}")
|
||||||
d[key] = update_value(d[key])
|
d[key] = update_value(d[key])
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@@ -70,19 +70,23 @@ def configure():
|
|||||||
if isinstance(updated_config.get('endpoints'), list): # Extract info on endpoint, model, url, provider et cetera from list
|
if isinstance(updated_config.get('endpoints'), list): # Extract info on endpoint, model, url, provider et cetera from list
|
||||||
global_state.set_endpoints(endpoints=updated_config.get('endpoints')) # Extract and set list of endpoints
|
global_state.set_endpoints(endpoints=updated_config.get('endpoints')) # Extract and set list of endpoints
|
||||||
# logger.debug("endpoints = \n{}".format(json.dumps(global_state.get_endpoints(), indent=4)))
|
# logger.debug("endpoints = \n{}".format(json.dumps(global_state.get_endpoints(), indent=4)))
|
||||||
fetch_models_from_endpoints(global_state.get_endpoints(), global_state) # Call the new function
|
global_state.fetch_models()
|
||||||
endpoints = global_state.get_endpoints()
|
endpoints = global_state.get_endpoints()
|
||||||
for endpoint in endpoints: # Set default LLM for each endpoint
|
for endpoint in endpoints: # Set default LLM for each endpoint
|
||||||
available_llms = global_state.get_list_of_available_llms(endpoint=endpoint)
|
available_llms = global_state.get_list_of_available_llms(endpoint=endpoint)
|
||||||
llm = next(iter(available_llms),None) # First available LLM or None. Default for AUTODETECT and requests for non-existing LLMs
|
llm = next(iter(available_llms),None) # First available LLM or None. Default for AUTODETECT and requests for non-existing LLMs
|
||||||
logger.debug(f"url {endpoint['url']} = {available_llms}")
|
logger.debug(f"url {endpoint['url']} = {available_llms}")
|
||||||
if endpoint["model"] in available_llms: # Check if specific LLM requested
|
if endpoint["model"] in available_llms: # Check if specific LLM requested, AUTODETECT evaluates to False
|
||||||
llm = endpoint["model"]
|
llm = endpoint["model"]
|
||||||
endpoint["default_llm"] = llm
|
endpoint["default_llm"] = llm
|
||||||
|
|
||||||
|
default_endpoint = next(iter(endpoints),None) # Set default_endpoint to first endpoint from list of endpoints
|
||||||
global_state.set_host_url(next(iter(endpoints),None)) # Set initial host to the first item in endpoints (or None)
|
default_llm = default_endpoint["default_llm"] # Get default LLM for default_endpoint
|
||||||
global_state.set_llm(llm) # Set which server and llm to use
|
default_ulr = default_endpoint["url"] # Get ulr of default_endpoint
|
||||||
|
global_state.set_host_url(default_ulr) # Set initial host to the first item in endpoints (or None)
|
||||||
|
global_state.set_llm(default_llm) # Set which llm to use
|
||||||
|
logger.debug(f"Desired default endpoint: {default_ulr},\tDesired default LLM: {default_llm}")
|
||||||
|
logger.debug(f"Returned default endpoint: {global_state.get_host_url()},\tReturned default LLM: {global_state.get_llm()}")
|
||||||
|
|
||||||
return updated_config
|
return updated_config
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user