LLM Configuration
LLM configuration loading module.
This module provides functionality to load and validate LLM configuration from YAML files, including environment variable expansion.
- class spacylize.llm_config.LLMConfig(*, model, api_key=None, api_base=None, max_tokens=1024)[source]
Bases:
BaseModelConfiguration model for LLM settings.
Defines the structure and validation rules for LLM configuration including model selection, authentication, and generation parameters.
- Parameters:
model (str)
api_key (str | None)
api_base (str | None)
max_tokens (int)
- model
The model identifier for LiteLLM.
- Type:
str
- api_key
Optional API key for authentication.
- Type:
str | None
- api_base
Optional custom API base URL.
- Type:
str | None
- max_tokens
Maximum number of tokens to generate.
- Type:
int
- model: str
- api_key: str | None
- api_base: str | None
- max_tokens: int
- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- spacylize.llm_config.expand_env_vars(value)[source]
Recursively expand environment variable references in configuration values.
Replaces ${VAR_NAME} patterns with their environment variable values. Supports nested dictionaries and lists.
- Parameters:
value (Any) – Configuration value to process (str, dict, list, or other).
- Returns:
The value with environment variables expanded.
- Return type:
Any
- spacylize.llm_config.load_llm_config(path)[source]
Load and validate LLM configuration from a YAML file.
- Parameters:
path (Path) – Path to the YAML configuration file.
- Returns:
Validated LLM configuration object.
- Return type:
- Raises:
RuntimeError – If the configuration is invalid or fails validation.