Compare commits
5 Commits
c7630bf6b3
...
17c20a4ce8
| Author | SHA1 | Date | |
|---|---|---|---|
| 17c20a4ce8 | |||
| 210a75e8bf | |||
| 01d4a5f314 | |||
| 4621cf6cbf | |||
| 56f9038e6c |
@@ -3,36 +3,23 @@ backend:
|
|||||||
url: "http://localhost:5004"
|
url: "http://localhost:5004"
|
||||||
api: "/api/chat"
|
api: "/api/chat"
|
||||||
|
|
||||||
|
preferred_ep: "Ollama-WARA"
|
||||||
|
|
||||||
endpoints:
|
endpoints:
|
||||||
- model: "AUTODETECT"
|
- model: "AUTODETECT"
|
||||||
title: "Ollama-local"
|
title: "Ollama-local" # Must be a unique identifier
|
||||||
url: "http://localhost:11434"
|
url: "http://localhost:11434"
|
||||||
provider: "ollama"
|
provider: "ollama"
|
||||||
# - model: "AUTODETECT"
|
# - model: "AUTODETECT"
|
||||||
- model: "AUTODETECT"
|
- model: "llava:13b"
|
||||||
title: "Ollama-WARA"
|
title: "Ollama-WARA" # Must be a unique identifier
|
||||||
url: "https://ollama-test.wara-ops.org"
|
url: "https://ollama-test.wara-ops.org"
|
||||||
requestOptions:
|
requestOptions:
|
||||||
headers:
|
headers:
|
||||||
Authorization: "${OLLAMA_API_KEY}" # on MacOS: echo "Authorization: Basic $(echo -n 'user:password' | gbase64 -w 0)"
|
Authorization: "${OLLAMA_API_KEY}" # on MacOS: echo "Authorization: Basic $(echo -n 'user:password' | gbase64 -w 0)"
|
||||||
provider: "ollama"
|
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 – comment out the whole section for default level which is INFO
|
||||||
logging:
|
logging:
|
||||||
|
|||||||
@@ -7,4 +7,12 @@ class LogLevel(Enum):
|
|||||||
INFO = 'INFO'
|
INFO = 'INFO'
|
||||||
WARNING = 'WARNING'
|
WARNING = 'WARNING'
|
||||||
ERROR = 'ERROR'
|
ERROR = 'ERROR'
|
||||||
CRITICAL = 'CRITICAL'
|
CRITICAL = 'CRITICAL'
|
||||||
|
|
||||||
|
LOG_LEVEL_MAPPING = {
|
||||||
|
LogLevel.DEBUG: 10,
|
||||||
|
LogLevel.INFO: 20,
|
||||||
|
LogLevel.WARNING: 30,
|
||||||
|
LogLevel.ERROR: 40,
|
||||||
|
LogLevel.CRITICAL: 50
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import logging
|
|||||||
import requests
|
import requests
|
||||||
import utils
|
import utils
|
||||||
from utils import GlobalState
|
from utils import GlobalState
|
||||||
|
from enums import LogLevel
|
||||||
|
|
||||||
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.get_logger(__name__) # Logger for this module, inherit properties of the root logger
|
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
|
if isinstance(updated_config.get('logging'), dict): # Look for 'logging' key in config file
|
||||||
logging_config = updated_config['logging']
|
logging_config = updated_config['logging']
|
||||||
if isinstance(logging_config.get('level'), str): # Set to value of the yaml file if specified
|
if isinstance(logging_config.get('level'), str): # Set to value of the yaml file if specified
|
||||||
global_state.set_log_level(logging_config['level'])
|
# 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(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)
|
# Extract models (server url, api_key, model, et cetera)
|
||||||
@@ -66,6 +68,8 @@ def configure():
|
|||||||
global_state.set_backend(backend=updated_config.get('backend'))
|
global_state.set_backend(backend=updated_config.get('backend'))
|
||||||
logger.debug("backend = \n{}".format(json.dumps(global_state.get_backend(), indent=4)))
|
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()}")
|
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
|
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
|
||||||
@@ -80,7 +84,11 @@ def configure():
|
|||||||
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
|
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_llm = default_endpoint["default_llm"] # Get default LLM for default_endpoint
|
||||||
default_ulr = default_endpoint["url"] # Get ulr of 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)
|
global_state.set_host_url(default_ulr) # Set initial host to the first item in endpoints (or None)
|
||||||
|
|||||||
+27
-31
@@ -5,7 +5,7 @@ import logging
|
|||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from enums import LogLevel
|
from enums import LogLevel, LOG_LEVEL_MAPPING
|
||||||
|
|
||||||
class GlobalState:
|
class GlobalState:
|
||||||
"""
|
"""
|
||||||
@@ -43,58 +43,42 @@ class GlobalState:
|
|||||||
|
|
||||||
return cls._instance
|
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.
|
Configure the logging system for this project.
|
||||||
|
|
||||||
Args:
|
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:
|
Notes:
|
||||||
This method sets up logging for the project and logs a message at the debug level indicating the effective log level.
|
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
|
level = self.log_level
|
||||||
# numeric_level = getattr(logging, level.upper()) # Convert string to numeric level
|
if isinstance(level, LogLevel):
|
||||||
numeric_level = getattr(logging, level.upper()) # Convert string to numeric level
|
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.setLevel(numeric_level)
|
||||||
self.logger.debug(f"utils.py -- configure_logging(): effective log level is {level} which is {self.logger.getEffectiveLevel()}")
|
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:
|
def set_log_level(self, level: LogLevel) -> None:
|
||||||
# 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:
|
|
||||||
"""
|
"""
|
||||||
Set the log level for this project.
|
Set the log level for this project.
|
||||||
|
|
||||||
Args:
|
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:
|
Notes:
|
||||||
This method updates the `self.log_level` attribute and calls `configure_logging()` to apply the change.
|
This method updates the `self.log_level` attribute and calls `configure_logging()` to apply the change.
|
||||||
"""
|
"""
|
||||||
self.log_level = level
|
self.log_level = level
|
||||||
self.configure_logging()
|
self.configure_logging()
|
||||||
|
|
||||||
def get_log_level(self) -> str:
|
def get_log_level(self) -> LogLevel:
|
||||||
"""
|
"""
|
||||||
Get the current log level.
|
Get the current log level.
|
||||||
|
|
||||||
@@ -232,6 +216,18 @@ class GlobalState:
|
|||||||
"""
|
"""
|
||||||
return [ep for ep in self.endpoints if key in ep]
|
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:
|
def fetch_models(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user