Enable multiple llms
This commit is contained in:
240
sia/config.py
240
sia/config.py
@@ -7,20 +7,11 @@ import os
|
||||
|
||||
@dataclass
|
||||
class Config:
|
||||
"""
|
||||
Configuration class that handles both command line and environment variables.
|
||||
|
||||
Command line arguments take precedence over environment variables.
|
||||
Environment variables serve as defaults that can be overridden via CLI.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Create configuration from command line arguments and environment variables.
|
||||
Required arguments must be provided either via CLI or environment variables.
|
||||
"""
|
||||
load_dotenv()
|
||||
parser = argparse.ArgumentParser(description='SIA - Self Improving Agent')
|
||||
|
||||
# Core configuration
|
||||
parser.add_argument(
|
||||
'--system-prompt',
|
||||
type=Path,
|
||||
@@ -39,6 +30,8 @@ class Config:
|
||||
default=os.getenv('SIA_ITERATIONS_DIR', 'iterations'),
|
||||
help='Path to the directory for storing iterations (default: iterations, env: SIA_ITERATIONS_DIR)'
|
||||
)
|
||||
|
||||
# Web server configuration
|
||||
parser.add_argument(
|
||||
'--server',
|
||||
action='store_true',
|
||||
@@ -63,108 +56,239 @@ class Config:
|
||||
default=self._parse_optional_path('SIA_STATIC_FILES', './static/'),
|
||||
help='Path to static web files (default: ./static/, env: SIA_STATIC_FILES)'
|
||||
)
|
||||
|
||||
# Local LLM configuration
|
||||
parser.add_argument(
|
||||
'--llm-engine',
|
||||
type=str,
|
||||
default=os.getenv('SIA_LLM_ENGINE', 'local'),
|
||||
help='LLM engine (default: local, env: SIA_LLM_ENGINE)'
|
||||
'--local-enable',
|
||||
action='store_true',
|
||||
default=self._parse_bool_env('SIA_LOCAL_ENABLED', False),
|
||||
help='Enable local LLM engine (env: SIA_LOCAL_ENABLED)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--api-token',
|
||||
'--local-model',
|
||||
type=str,
|
||||
default=os.getenv('SIA_API_TOKEN'),
|
||||
help='API access token (env: SIA_API_TOKEN)'
|
||||
default=os.getenv('SIA_LOCAL_MODEL', '/root/model/'),
|
||||
help='Path to local model directory (default: /root/model/, env: SIA_LOCAL_MODEL)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--model',
|
||||
type=str,
|
||||
default=os.getenv('SIA_MODEL', '/root/model/'),
|
||||
help='Path to the model directory (default: /root/model/, env: SIA_MODEL)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--temperature',
|
||||
'--local-temperature',
|
||||
type=float,
|
||||
default=float(os.getenv('SIA_TEMPERATURE', '0.7')),
|
||||
help='LLM temperature parameter (default: 0.7, env: SIA_TEMPERATURE)'
|
||||
default=float(os.getenv('SIA_LOCAL_TEMPERATURE', '0.7')),
|
||||
help='Local LLM temperature (default: 0.7, env: SIA_LOCAL_TEMPERATURE)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--token-limit',
|
||||
'--local-token-limit',
|
||||
type=int,
|
||||
default=os.getenv('SIA_TOKEN_LIMIT'),
|
||||
help='Token limit for the LLM (env: SIA_TOKEN_LIMIT)'
|
||||
default=int(os.getenv('SIA_LOCAL_TOKEN_LIMIT', '2048')),
|
||||
help='Local LLM token limit (env: SIA_LOCAL_TOKEN_LIMIT)'
|
||||
)
|
||||
|
||||
# OpenAI configuration
|
||||
parser.add_argument(
|
||||
'--openai-enable',
|
||||
action='store_true',
|
||||
default=self._parse_bool_env('SIA_OPENAI_ENABLED', False),
|
||||
help='Enable OpenAI LLM engine (env: SIA_OPENAI_ENABLED)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--openai-model',
|
||||
type=str,
|
||||
default=os.getenv('SIA_OPENAI_MODEL', 'gpt-3.5-turbo'),
|
||||
help='OpenAI model name (default: gpt-3.5-turbo, env: SIA_OPENAI_MODEL)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--openai-temperature',
|
||||
type=float,
|
||||
default=float(os.getenv('SIA_OPENAI_TEMPERATURE', '0.7')),
|
||||
help='OpenAI temperature (default: 0.7, env: SIA_OPENAI_TEMPERATURE)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--openai-token-limit',
|
||||
type=int,
|
||||
default=int(os.getenv('SIA_OPENAI_TOKEN_LIMIT', '4096')),
|
||||
help='OpenAI token limit (env: SIA_OPENAI_TOKEN_LIMIT)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--openai-api-key',
|
||||
type=str,
|
||||
default=os.getenv('SIA_OPENAI_API_KEY'),
|
||||
help='OpenAI API key (env: SIA_OPENAI_API_KEY)'
|
||||
)
|
||||
|
||||
# Hugging Face configuration
|
||||
parser.add_argument(
|
||||
'--hf-enable',
|
||||
action='store_true',
|
||||
default=self._parse_bool_env('SIA_HF_ENABLED', False),
|
||||
help='Enable Hugging Face LLM engine (env: SIA_HF_ENABLED)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--hf-model',
|
||||
type=str,
|
||||
default=os.getenv('SIA_HF_MODEL'),
|
||||
help='Hugging Face model name (env: SIA_HF_MODEL)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--hf-temperature',
|
||||
type=float,
|
||||
default=float(os.getenv('SIA_HF_TEMPERATURE', '0.7')),
|
||||
help='Hugging Face temperature (default: 0.7, env: SIA_HF_TEMPERATURE)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--hf-api-key',
|
||||
type=str,
|
||||
default=os.getenv('SIA_HF_API_KEY'),
|
||||
help='Hugging Face API key (env: SIA_HF_API_KEY)'
|
||||
)
|
||||
|
||||
# Mistral configuration
|
||||
parser.add_argument(
|
||||
'--mistral-enable',
|
||||
action='store_true',
|
||||
default=self._parse_bool_env('SIA_MISTRAL_ENABLED', False),
|
||||
help='Enable Mistral LLM engine (env: SIA_MISTRAL_ENABLED)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--mistral-model',
|
||||
type=str,
|
||||
default=os.getenv('SIA_MISTRAL_MODEL'),
|
||||
help='Mistral model name (env: SIA_MISTRAL_MODEL)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--mistral-temperature',
|
||||
type=float,
|
||||
default=float(os.getenv('SIA_MISTRAL_TEMPERATURE', '0.7')),
|
||||
help='Mistral temperature (default: 0.7, env: SIA_MISTRAL_TEMPERATURE)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--mistral-token-limit',
|
||||
type=int,
|
||||
default=int(os.getenv('SIA_MISTRAL_TOKEN_LIMIT', '4096')),
|
||||
help='Mistral token limit (env: SIA_MISTRAL_TOKEN_LIMIT)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--mistral-api-key',
|
||||
type=str,
|
||||
default=os.getenv('SIA_MISTRAL_API_KEY'),
|
||||
help='Mistral API key (env: SIA_MISTRAL_API_KEY)'
|
||||
)
|
||||
|
||||
self.args = parser.parse_args()
|
||||
|
||||
|
||||
def _parse_bool_env(self, env_var: str, default: bool) -> bool:
|
||||
"""Parse boolean environment variable."""
|
||||
val = os.getenv(env_var)
|
||||
if val is None:
|
||||
return default
|
||||
return val.lower() in ('true', '1', 'yes', 'on')
|
||||
|
||||
def _parse_optional_path(self, env_var: str, default: Optional[Path]) -> Optional[Path]:
|
||||
"""Parse optional Path environment variable."""
|
||||
val = os.getenv(env_var)
|
||||
if val is None:
|
||||
return default
|
||||
return Path(val)
|
||||
|
||||
# Core properties
|
||||
@property
|
||||
def system_prompt(self) -> Path:
|
||||
"""Path to the system prompt file."""
|
||||
return self.args.system_prompt
|
||||
|
||||
@property
|
||||
def action_schema(self) -> Path:
|
||||
"""Path to the action schema file."""
|
||||
return self.args.action_schema
|
||||
|
||||
@property
|
||||
def iterations_dir(self) -> Path:
|
||||
"""Path to the directory for storing iterations."""
|
||||
return self.args.iterations_dir
|
||||
|
||||
# Server properties
|
||||
@property
|
||||
def server(self) -> bool:
|
||||
"""Enable web server for debugging and human feedback."""
|
||||
return self.args.server
|
||||
|
||||
@property
|
||||
def host(self) -> str:
|
||||
"""Web server host."""
|
||||
return self.args.host
|
||||
|
||||
@property
|
||||
def port(self) -> int:
|
||||
"""Web server port."""
|
||||
return self.args.port
|
||||
|
||||
@property
|
||||
def static_files(self) -> Path:
|
||||
"""Path to static web files."""
|
||||
return self.args.static_files
|
||||
|
||||
# Local LLM properties
|
||||
@property
|
||||
def llm_engine(self) -> str:
|
||||
"""LLM engine."""
|
||||
return self.args.llm_engine
|
||||
|
||||
@property
|
||||
def api_token(self) -> Optional[str]:
|
||||
"""API access token."""
|
||||
return self.args.api_token
|
||||
def local_enabled(self) -> bool:
|
||||
return self.args.local_enable
|
||||
|
||||
@property
|
||||
def model(self) -> str:
|
||||
"""Path to the model directory."""
|
||||
return self.args.model
|
||||
def local_model(self) -> str:
|
||||
return self.args.local_model
|
||||
|
||||
@property
|
||||
def temperature(self) -> float:
|
||||
"""LLM temperature parameter."""
|
||||
return self.args.temperature
|
||||
|
||||
def local_temperature(self) -> float:
|
||||
return self.args.local_temperature
|
||||
|
||||
@property
|
||||
def token_limit(self) -> int:
|
||||
"""Token limit for the LLM."""
|
||||
return self.args.token_limit
|
||||
def local_token_limit(self) -> int:
|
||||
return self.args.local_token_limit
|
||||
|
||||
# OpenAI properties
|
||||
@property
|
||||
def openai_enabled(self) -> bool:
|
||||
return self.args.openai_enable
|
||||
|
||||
@property
|
||||
def openai_model(self) -> str:
|
||||
return self.args.openai_model
|
||||
|
||||
@property
|
||||
def openai_temperature(self) -> float:
|
||||
return self.args.openai_temperature
|
||||
|
||||
@property
|
||||
def openai_token_limit(self) -> int:
|
||||
return self.args.openai_token_limit
|
||||
|
||||
@property
|
||||
def openai_api_key(self) -> Optional[str]:
|
||||
return self.args.openai_api_key
|
||||
|
||||
# Hugging Face properties
|
||||
@property
|
||||
def hf_enabled(self) -> bool:
|
||||
return self.args.hf_enable
|
||||
|
||||
@property
|
||||
def hf_model(self) -> str:
|
||||
return self.args.hf_model
|
||||
|
||||
@property
|
||||
def hf_temperature(self) -> float:
|
||||
return self.args.hf_temperature
|
||||
|
||||
@property
|
||||
def hf_api_key(self) -> Optional[str]:
|
||||
return self.args.hf_api_key
|
||||
|
||||
# Mistral properties
|
||||
@property
|
||||
def mistral_enabled(self) -> bool:
|
||||
return self.args.mistral_enable
|
||||
|
||||
@property
|
||||
def mistral_model(self) -> str:
|
||||
return self.args.mistral_model
|
||||
|
||||
@property
|
||||
def mistral_temperature(self) -> float:
|
||||
return self.args.mistral_temperature
|
||||
|
||||
@property
|
||||
def mistral_token_limit(self) -> int:
|
||||
return self.args.mistral_token_limit
|
||||
|
||||
@property
|
||||
def mistral_api_key(self) -> Optional[str]:
|
||||
return self.args.mistral_api_key
|
||||
|
||||
Reference in New Issue
Block a user