5 Commits

4 changed files with 52 additions and 53 deletions
+5 -18
View File
@@ -3,36 +3,23 @@ backend:
url: "http://localhost:5004"
api: "/api/chat"
preferred_ep: "Ollama-WARA"
endpoints:
- model: "AUTODETECT"
title: "Ollama-local"
title: "Ollama-local" # Must be a unique identifier
url: "http://localhost:11434"
provider: "ollama"
# - model: "AUTODETECT"
- model: "AUTODETECT"
title: "Ollama-WARA"
- model: "llava:13b"
title: "Ollama-WARA" # Must be a unique identifier
url: "https://ollama-test.wara-ops.org"
requestOptions:
headers:
Authorization: "${OLLAMA_API_KEY}" # on MacOS: echo "Authorization: Basic $(echo -n 'user:password' | gbase64 -w 0)"
provider: "ollama"
# Ollama Server Configuration this section is to be removed when endpoints are being parsed correctly
ollama:
title: "Ollama-local"
# url: "http://localhost:11434"
url: "https://ollama-test.wara-ops.org"
api_key: "${OLLAMA_API_KEY}" # Refer to environment variable
# model: "phi3:mini" # Select a model supported by the Ollama server
# model: "llama3:70b" # Select a model supported by the Ollama server
model: "llama3.1:70b" # Select a model supported by the Ollama server
# model: "llama3.1:8b" # Select a model supported by the Ollama server
# model: "llama3:latest" # Select a model supported by the Ollama server
# model: "mannix/llama3-8b-ablitered-v3:latest" # Select a model supported by the Ollama server
# model: "mistral-nemo:latest" # Select a model supported by the Ollama server
# model: "gemma2:27b"
# model: "AUTODETECT"
# Logging comment out the whole section for default level which is INFO
logging:
+9 -1
View File
@@ -7,4 +7,12 @@ class LogLevel(Enum):
INFO = 'INFO'
WARNING = 'WARNING'
ERROR = 'ERROR'
CRITICAL = 'CRITICAL'
CRITICAL = 'CRITICAL'
LOG_LEVEL_MAPPING = {
LogLevel.DEBUG: 10,
LogLevel.INFO: 20,
LogLevel.WARNING: 30,
LogLevel.ERROR: 40,
LogLevel.CRITICAL: 50
}
+11 -3
View File
@@ -10,6 +10,7 @@ import logging
import requests
import utils
from utils import GlobalState
from enums import LogLevel
global_state = GlobalState() # Configure root logger. The level will be adjusted later based on config file
logger = global_state.get_logger(__name__) # Logger for this module, inherit properties of the root logger
@@ -56,8 +57,9 @@ def configure():
if isinstance(updated_config.get('logging'), dict): # Look for 'logging' key in config file
logging_config = updated_config['logging']
if isinstance(logging_config.get('level'), str): # Set to value of the yaml file if specified
global_state.set_log_level(logging_config['level'])
logger.debug("configure(): This logger now has effective log level %s", logger.getEffectiveLevel())
# global_state.set_log_level(logging_config['level'])
global_state.set_log_level(LogLevel(logging_config['level']))
logger.info("configure(): This logger now has effective log level %s", logger.getEffectiveLevel())
####################################
# Extract models (server url, api_key, model, et cetera)
@@ -66,6 +68,8 @@ def configure():
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()}")
preferred_ep = updated_config.get('preferred_ep', None) # Get the preferred endpoint if specified, otherwise None
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
@@ -80,7 +84,11 @@ def configure():
llm = endpoint["model"]
endpoint["default_llm"] = llm
default_endpoint = next(iter(endpoints),None) # Set default_endpoint to first endpoint from list of endpoints
if preferred_ep: # If preferred_ep is specified, set it as the default endpoint
list_of_eps = global_state.get_endpoints_with_key_value("title", preferred_ep) # Should only be one element in the list...
default_endpoint = next(iter(list_of_eps),None) # Same as default_endpoint = list_of_eps[0] if list_of_eps else None
else:
default_endpoint = next(iter(endpoints),None) # Set default_endpoint to first endpoint from list of all endpoints
default_llm = default_endpoint["default_llm"] # Get default LLM for default_endpoint
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)
+27 -31
View File
@@ -5,7 +5,7 @@ import logging
import json
import requests
from typing import Optional
from enums import LogLevel
from enums import LogLevel, LOG_LEVEL_MAPPING
class GlobalState:
"""
@@ -43,58 +43,42 @@ class GlobalState:
return cls._instance
# def configure_logging(self, level: Optional[LogLevel] = None) -> None:
# """
# Configure the logging system for this project.
# Args:
# level (LogLevel): The log level to use. If None, uses the default log level set in `self.log_level`.
# Notes:
# This method sets up logging for the project and logs a message at the debug level indicating the effective log level.
# """
def configure_logging(self, level: Optional[str] = None) -> None:
def configure_logging(self, level: Optional[LogLevel] = None) -> None:
"""
Configure the logging system for this project.
Args:
level (str): The log level to use. Can be one of the standard Python log levels (e.g., 'DEBUG', 'INFO', 'WARNING', etc.). If None, uses the default log level set in `self.log_level`.
level (LogLevel): The log level to use. If None, uses the default log level set in `self.log_level`.
Notes:
This method sets up logging for the project and logs a message at the debug level indicating the effective log level.
"""
if level is None:
if level == None:
level = self.log_level
# numeric_level = getattr(logging, level.upper()) # Convert string to numeric level
numeric_level = getattr(logging, level.upper()) # Convert string to numeric level
if isinstance(level, LogLevel):
logging.info(f"Trying to set up logging with level {level}")
numeric_level = LOG_LEVEL_MAPPING[level]
if numeric_level is None:
raise ValueError("Invalid log level")
self.logger.setLevel(numeric_level)
self.logger.debug(f"utils.py -- configure_logging(): effective log level is {level} which is {self.logger.getEffectiveLevel()}")
# def set_log_level(self, level: LogLevel) -> None:
# """
# Set the log level for this project.
# Args:
# level (LogLevel): The new log level to use. Can be one of the evels defined in enum.py (e.g., DEBUG, INFO, WARNING, CRITICAL etc.).
# Notes:
# This method updates the `self.log_level` attribute and calls `configure_logging()` to apply the change.
# """
def set_log_level(self, level: str = 'INFO') -> None:
def set_log_level(self, level: LogLevel) -> None:
"""
Set the log level for this project.
Args:
level (str): The new log level to use. Can be one of the standard Python log levels (e.g., 'DEBUG', 'INFO', 'WARNING', etc.).
level (LogLevel): The new log level to use. Can be one of the evels defined in enum.py (e.g., DEBUG, INFO, WARNING, CRITICAL etc.).
Notes:
This method updates the `self.log_level` attribute and calls `configure_logging()` to apply the change.
"""
"""
self.log_level = level
self.configure_logging()
def get_log_level(self) -> str:
def get_log_level(self) -> LogLevel:
"""
Get the current log level.
@@ -232,6 +216,18 @@ class GlobalState:
"""
return [ep for ep in self.endpoints if key in ep]
def get_endpoints_with_key_value(self, key: str, value: any) -> list[dict]:
"""
Returns a list of endpoint dictionaries that contain the specified key-value pair.
Args:
key (str): The key to search for in the endpoint dictionaries.
value (Any): The value to search for in the endpoint dictionaries.
Returns:
list[dict]: A list of endpoint dictionaries containing the specified key.
"""
return [ep for ep in self.endpoints if key in ep and value == ep[key]]
def fetch_models(self) -> None:
"""