diff --git a/smartassist/src/startservices.py b/smartassist/src/startservices.py index 0394968..1831c60 100644 --- a/smartassist/src/startservices.py +++ b/smartassist/src/startservices.py @@ -69,41 +69,31 @@ def configure(): 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 - 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 - - - # TODO: Remove this section when not needed anymore - if isinstance(updated_config.get('ollama'), dict): # Look for 'ollama' key - if isinstance(updated_config['ollama'].get('model'), str): # Look for 'model' key - model_to_use = updated_config['ollama'].get('model') - global_state.set_llm(model_to_use) - logger.debug("configure(): LLM is set to: %s",global_state.get_llm()) - - return updated_config - - -# def start_frontend(config): -# parsed_url = urllib.parse.urlparse(config['frontend']['url']) -# hostname = parsed_url.netloc.split(':')[0] # Split by ':' and take the first part, i.e., 'localhost', IP, or domain name -# port = parsed_url.port # This is the server port - -# # Use the socket module in Python to check whether a port is in use, -# # which would indicate that a server is already running on that port. -# with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: -# try: -# s.bind((hostname, port)) -# logger.debug("No server is running on %s -— starting one.", parsed_url.netloc) -# # Start frontend (web server) as a separate process -# subprocess.Popen(["python", "-m", "http.server", str(port)]) -# except socket.error as e: -# if e.errno == 48: -# logger.debug("A server is already running on %s -— will use this.", parsed_url.netloc) -# else: -# raise # Unexpected error, re-raise it so we can see the traceback -# except Exception as e: -# logger.error("Failed to start frontend: %s", str(e)) # Corresponds to print(f"Failed to start frontend: {e}") + endpoints = global_state.get_endpoints() + for endpoint in endpoints: # Set default LLM for each 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 + logger.debug(f"url {endpoint['url']} = {available_llms}") + if endpoint["model"] in available_llms: # Check if specific LLM requested + llm = endpoint["model"] + endpoint["default_llm"] = llm + + global_state.set_host_url(next(iter(endpoints),None)) # Set initial host to the first item in endpoints (or None) + global_state.set_llm(llm) # Set which server and llm to use + + + + # # TODO: Remove this section when not needed anymore + # if isinstance(updated_config.get('ollama'), dict): # Look for 'ollama' key + # if isinstance(updated_config['ollama'].get('model'), str): # Look for 'model' key + # model_to_use = updated_config['ollama'].get('model') + # global_state.set_llm(model_to_use) + # logger.debug("configure(): LLM is set to: %s",global_state.get_llm()) + + return updated_config def start_backend(config): @@ -120,6 +110,6 @@ def start_backend(config): if __name__ == '__main__': conf = configure() # Read config from file and set up config dict - logger.debug('conf dictionary set to \n{}'.format(json.dumps(conf, indent=4))) + # logger.debug('conf dictionary set to \n{}'.format(json.dumps(conf, indent=4))) # start_frontend(config=conf) # Not needed as we are using Flask for backend now start_backend(config=conf)