Configuration

The configuration system consists of two main classes:

  • Config: Defines the configuration model.

  • ConfigLoader: Manages loading and accessing configuration.

Config

class openchatbi.config_loader.Config(*, organization: str = 'The Company', dialect: str = 'presto', default_llm: MagicMock | BaseChatModel, embedding_model: MagicMock | BaseModel | None = None, text2sql_llm: MagicMock | BaseChatModel | None = None, analysis_llm: MagicMock | BaseChatModel | None = None, llm_provider: str | None = None, llm_providers: dict[str, LLMProviderConfig] = {}, bi_config: dict[str, Any] = {}, data_warehouse_config: dict[str, Any] = {}, catalog_store: Any = None, vector_db_path: str = None, mcp_servers: list[dict[str, Any]] = [], report_directory: str = './data', python_executor: str = 'local', visualization_mode: str | None = 'rule', enable_sql_result_limit: bool = True, sql_result_limit: int = 10000, enable_confidence_gate: bool = False, sql_confidence_threshold: float = 0.7, confidence_gate_mode: str = 'post_exec', confidence_evaluator_mode: str = 'simple', enable_empty_result_error: bool = False, enable_golden_sql: bool = False, golden_sql_namespace: str = 'global', sql_max_retries: int = 3, retry_on_timeout: bool = False, retry_strategy_overrides: dict[str, Any] = {}, context_config: dict[str, Any] = {}, memory_config: dict[str, Any] = {}, observability: ObservabilityConfig = ObservabilityConfig(tracing=TracingConfig(enabled=False, provider=None, langfuse_host=None, sample_rate=1.0), metrics=MetricsConfig(enabled=False, prometheus_port=None), audit=AuditConfig(enabled=False, sink='log', path=None, mask_sql_literals=True)), timeseries_forecasting_service_url: str = 'http://localhost:8765', timeseries_forecasting_min_input_length: int | None = None)[source]

Configuration model for the OpenChatBI application.

organization

Organization name. Defaults to “The Company”.

Type:

str

dialect

SQL dialect to use. Defaults to “presto”.

Type:

str

default_llm

Default language model for general tasks.

Type:

BaseChatModel

embedding_model

Language model for embedding generation.

Type:

BaseModel

text2sql_llm

Language model specifically for text-to-SQL tasks.

Type:

Optional[BaseChatModel]

bi_config

BI configuration loaded from YAML file. Defaults to empty dict.

Type:

Dict[str, Any]

data_warehouse_config

Data warehouse configuration. Defaults to empty dict.

Type:

Dict[str, Any]

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

analysis_llm: MagicMock | BaseChatModel | None
llm_provider: str | None
llm_providers: dict[str, LLMProviderConfig]
vector_db_path: str
visualization_mode: str | None
enable_sql_result_limit: bool
sql_result_limit: int
enable_confidence_gate: bool
sql_confidence_threshold: float
confidence_gate_mode: str
confidence_evaluator_mode: str
enable_empty_result_error: bool
enable_golden_sql: bool
golden_sql_namespace: str
sql_max_retries: int
retry_on_timeout: bool
retry_strategy_overrides: dict[str, Any]
context_config: dict[str, Any]
memory_config: dict[str, Any]
observability: ObservabilityConfig
timeseries_forecasting_service_url: str
timeseries_forecasting_min_input_length: int | None
classmethod from_dict(config: dict[str, Any]) Config[source]

Creates a Config instance from a dictionary.

Parameters:

config (Dict[str, Any]) – Dictionary containing configuration values.

Returns:

A new Config instance with the provided values.

Return type:

Config

ConfigLoader

class openchatbi.config_loader.ConfigLoader[source]

Bases: object

Singleton class to load and manage configuration settings for OpenChatBI.

This class provides methods to load, get, and set configuration parameters for the application, including LLM models, SQL dialect, and other settings.

llm_configs = ['default_llm', 'embedding_model', 'text2sql_llm', 'analysis_llm']
get() Config[source]

Get the current configuration.

Returns:

The current configuration instance.

Return type:

Config

Raises:

ValueError – If the configuration has not been loaded.

load(config_file: str = None) None[source]

Load configuration from a YAML file.

Parameters:

config_file (str, optional) – Path to configuration file. Uses CONFIG_FILE environment variable or ‘openchatbi/config.yaml’ if not provided.

Raises:
  • ImportError – If pyyaml is not installed.

  • FileNotFoundError – If the configuration file cannot be found.

load_bi_config(bi_config_file: str) dict[str, Any][source]

Load BI configuration from a YAML file.

Parameters:

bi_config_file (str) – Path to the BI configuration file. Defaults to ‘example/bi.yaml’.

Returns:

The loaded BI configuration as a dictionary.

Return type:

Dict[str, Any]

Raises:
  • ImportError – If pyyaml is not installed.

  • FileNotFoundError – If the BI configuration file cannot be found.

set(config: dict[str, Any]) None[source]

Set the configuration from a dictionary.

Parameters:

config (Dict[str, Any]) – Dictionary containing configuration values.