Compare commits
3 Commits
d553deed13
...
a7ce92524a
| Author | SHA1 | Date | |
|---|---|---|---|
| a7ce92524a | |||
| b52c98c6b3 | |||
| c8269f3152 |
@@ -1,7 +1,3 @@
|
|||||||
# Frontend Configuration
|
|
||||||
# frontend:
|
|
||||||
# url: "http://localhost:5004"
|
|
||||||
|
|
||||||
# Backend Configuration
|
# Backend Configuration
|
||||||
backend:
|
backend:
|
||||||
url: "http://localhost:5004"
|
url: "http://localhost:5004"
|
||||||
@@ -47,7 +43,7 @@ logging:
|
|||||||
|
|
||||||
# Cache Settings (Optional)
|
# Cache Settings (Optional)
|
||||||
cache:
|
cache:
|
||||||
enabled: true
|
enabled: True
|
||||||
timeout: 60 # Seconds
|
timeout: 60 # Seconds
|
||||||
|
|
||||||
test:
|
test:
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ def configure():
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
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 same level
|
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
|
||||||
@@ -62,19 +62,29 @@ def configure():
|
|||||||
# Extract and export backend API
|
# Extract and export backend API
|
||||||
# endpoint as global state variable
|
# endpoint as global state variable
|
||||||
####################################
|
####################################
|
||||||
if isinstance(updated_config.get('backend'), dict): # Look for 'backend' key
|
# if isinstance(updated_config.get('backend'), dict): # Look for 'backend' key
|
||||||
if isinstance(updated_config['backend'].get('url'), str): # Look for 'url' key
|
# if isinstance(updated_config['backend'].get('url'), str): # Look for 'url' key
|
||||||
url = updated_config['backend'].get('url')
|
# url = updated_config['backend'].get('url')
|
||||||
if isinstance(updated_config['backend'].get('api'), str): # Look for 'api' key
|
# if isinstance(updated_config['backend'].get('api'), str): # Look for 'api' key
|
||||||
api = updated_config['backend'].get('api')
|
# api = updated_config['backend'].get('api')
|
||||||
# backend_api_ep = url+api # Extract API endpoint if defined
|
# # backend_api_ep = url+api # Extract API endpoint if defined
|
||||||
logger.debug(f"Constructing endpoint address as url+api: {url+api}")
|
# logger.debug(f"Constructing endpoint address as url+api: {url+api}")
|
||||||
global_state.set_backend_api_ep(url+api) # Extract API endpoint if defined and set in global_state
|
# global_state.set_backend_api_ep(url+api) # Extract API endpoint if defined and set in global_state
|
||||||
logger.debug(f"Backend API endpoint is set to {global_state.get_backend_api_ep()}")
|
# logger.debug(f"Backend API endpoint is set to {global_state.get_backend_api_ep()}")
|
||||||
|
|
||||||
####################################
|
####################################
|
||||||
# Extract models (server url, api_key, model, et cetera)
|
# Extract models (server url, api_key, model, et cetera)
|
||||||
####################################
|
####################################
|
||||||
|
if isinstance(updated_config.get('backend'),dict): # Extract backend info from dictionary
|
||||||
|
global_state.set_backend(backend=updated_config.get('backend'))
|
||||||
|
logger.debug("backend = \n{}".format(json.dumps(global_state.get_backend(), indent=4)))
|
||||||
|
logger.debug(f"Backend API endpoint is set to: {global_state.get_backend_api_ep()}")
|
||||||
|
|
||||||
|
if isinstance(updated_config.get('models'),list): # Extract info on model, url, provider et cetera from list
|
||||||
|
global_state.set_models(models=updated_config.get('models'))
|
||||||
|
logger.debug("models = \n{}".format(json.dumps(global_state.get_models(), indent=4)))
|
||||||
|
|
||||||
|
# TODO: Remove this section when not needed anymore
|
||||||
if isinstance(updated_config.get('ollama'), dict): # Look for 'ollama' key
|
if isinstance(updated_config.get('ollama'), dict): # Look for 'ollama' key
|
||||||
if isinstance(updated_config['ollama'].get('model'), str): # Look for 'model' key
|
if isinstance(updated_config['ollama'].get('model'), str): # Look for 'model' key
|
||||||
model_to_use = updated_config['ollama'].get('model')
|
model_to_use = updated_config['ollama'].get('model')
|
||||||
@@ -121,7 +131,6 @@ def start_backend(config):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
conf = configure() # Read config from file and set up config dict
|
conf = configure() # Read config from file and set up config dict
|
||||||
logger.debug('conf dictionary set to {}'.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_frontend(config=conf) # Not needed as we are using Flask for backend now
|
||||||
start_backend(config=conf)
|
start_backend(config=conf)
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class GlobalState:
|
|||||||
cls._instance.logger.setLevel(getattr(logging, cls._instance.log_level)) # Initialize root logger level
|
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.logger.info(" __new__(cls): Logger in GlobalState created: %s", cls._instance.logger)
|
||||||
cls._instance.llm = "phi3:mini" # Default LLM for queries. TODO: Check with ollama server that it actually exists
|
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
|
# 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
|
# Try making things more aligned with the outline of the yaml file
|
||||||
cls._instance.backend = dict() # Holds info on which server the clients connect to
|
cls._instance.backend = dict() # Holds info on which server the clients connect to
|
||||||
cls._instance.models = [] # A list that holds info on which models are available for use (server url, model name, provider et cetera)
|
cls._instance.models = [] # A list that holds info on which models are available for use (server url, model name, provider et cetera)
|
||||||
@@ -70,14 +70,6 @@ class GlobalState:
|
|||||||
"""Getter for which LLM is used for queries"""
|
"""Getter for which LLM is used for queries"""
|
||||||
return self.llm
|
return self.llm
|
||||||
|
|
||||||
def set_backend_api_ep(self, be_api_ep=None):
|
|
||||||
"""Set backend API endpoint"""
|
|
||||||
self.backend_api_ep = be_api_ep
|
|
||||||
|
|
||||||
def get_backend_api_ep(self):
|
|
||||||
"""Getter for backend API endpoint"""
|
|
||||||
return self.backend_api_ep
|
|
||||||
|
|
||||||
def set_backend(self, backend=None):
|
def set_backend(self, backend=None):
|
||||||
"""Set backend that web clients connect to"""
|
"""Set backend that web clients connect to"""
|
||||||
self.backend = backend
|
self.backend = backend
|
||||||
@@ -86,11 +78,16 @@ class GlobalState:
|
|||||||
"""Getter for backend that web clients connect to"""
|
"""Getter for backend that web clients connect to"""
|
||||||
return self.backend
|
return self.backend
|
||||||
|
|
||||||
|
def get_backend_api_ep(self):
|
||||||
|
"""Getter for backend API endpoint"""
|
||||||
|
return self.backend["url"]+self.backend["api"]
|
||||||
|
|
||||||
def set_models(self, models=None):
|
def set_models(self, models=None):
|
||||||
"""Set the list of models."""
|
"""Set the list of models."""
|
||||||
self.models = models
|
if models is not None:
|
||||||
if not isinstance(models, list):
|
if not isinstance(models, list):
|
||||||
raise ValueError("Models must be a list")
|
raise ValueError("Models must be a list, even if there is just one model")
|
||||||
|
self.models = models
|
||||||
|
|
||||||
def get_models(self):
|
def get_models(self):
|
||||||
"""Return the list of models"""
|
"""Return the list of models"""
|
||||||
|
|||||||
Reference in New Issue
Block a user