File size: 3,396 Bytes
f2a52eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""
HistoPath Configuration Management

Simple configuration class for centralizing common settings.
Maintains full backward compatibility with existing code.
"""

import os
from dataclasses import dataclass


@dataclass
class HistoPathConfig:
    """Central configuration for the HistoPath agent.

    All settings are optional and have sensible defaults.
    API keys are still read from environment variables to maintain
    compatibility with existing .env file structure.

    Usage:
        # Create config with defaults
        config = HistoPathConfig()

        # Override specific settings
        config = HistoPathConfig(llm="gpt-4", timeout_seconds=1200)

        # Modify after creation
        config.path = "./custom_data"
    """

    # Data and execution settings
    path: str = "./data"
    timeout_seconds: int = 600

    # LLM settings (API keys still from environment)
    llm: str = "claude-sonnet-4-20250514"
    temperature: float = 0.7

    # Tool settings
    use_tool_retriever: bool = True

    # Data licensing settings
    commercial_mode: bool = False  # If True, excludes non-commercial datasets

    # Custom model settings (for custom LLM serving)
    base_url: str | None = None
    api_key: str | None = None  # Only for custom models, not provider API keys

    # LLM source (auto-detected if None)
    source: str | None = None

    def __post_init__(self):
        """Load any environment variable overrides if they exist."""
        # Check for environment variable overrides (optional)
        # Support both old and new names for backwards compatibility
        if os.getenv("HISTOPATH_PATH") or os.getenv("HISTOPATH_DATA_PATH"):
            self.path = os.getenv("HISTOPATH_PATH") or os.getenv("HISTOPATH_DATA_PATH")
        if os.getenv("HISTOPATH_TIMEOUT_SECONDS"):
            self.timeout_seconds = int(os.getenv("HISTOPATH_TIMEOUT_SECONDS"))
        if os.getenv("HISTOPATH_LLM") or os.getenv("HISTOPATH_LLM_MODEL"):
            self.llm = os.getenv("HISTOPATH_LLM") or os.getenv("HISTOPATH_LLM_MODEL")
        if os.getenv("HISTOPATH_USE_TOOL_RETRIEVER"):
            self.use_tool_retriever = os.getenv("HISTOPATH_USE_TOOL_RETRIEVER").lower() == "true"
        if os.getenv("HISTOPATH_COMMERCIAL_MODE"):
            self.commercial_mode = os.getenv("HISTOPATH_COMMERCIAL_MODE").lower() == "true"
        if os.getenv("HISTOPATH_TEMPERATURE"):
            self.temperature = float(os.getenv("HISTOPATH_TEMPERATURE"))
        if os.getenv("HISTOPATH_CUSTOM_BASE_URL"):
            self.base_url = os.getenv("HISTOPATH_CUSTOM_BASE_URL")
        if os.getenv("HISTOPATH_CUSTOM_API_KEY"):
            self.api_key = os.getenv("HISTOPATH_CUSTOM_API_KEY")
        if os.getenv("HISTOPATH_SOURCE"):
            self.source = os.getenv("HISTOPATH_SOURCE")

    def to_dict(self) -> dict:
        """Convert config to dictionary for easy access."""
        return {
            "path": self.path,
            "timeout_seconds": self.timeout_seconds,
            "llm": self.llm,
            "temperature": self.temperature,
            "use_tool_retriever": self.use_tool_retriever,
            "commercial_mode": self.commercial_mode,
            "base_url": self.base_url,
            "api_key": self.api_key,
            "source": self.source,
        }


# Global default config instance (optional, for convenience)
default_config = HistoPathConfig()