🔍 Code Extractor

class SmartStatConfig

Maturity: 47

Configuration class for SmartStat service that manages directory paths and API keys for various LLM providers integrated into Vice AI.

File:
/tf/active/vicechatdev/vice_ai/new_app.py
Lines:
258 - 278
Complexity:
simple

Purpose

SmartStatConfig is a configuration container class that initializes and manages file system directories for SmartStat service operations (uploads, scripts, reports, output) and consolidates API credentials for multiple LLM providers (OpenAI, Gemini, Azure OpenAI, Anthropic). It ensures all required directories exist on instantiation and pulls API keys from a global LLM_CONFIG dictionary.

Source Code

class SmartStatConfig:
    """Configuration for SmartStat service integrated into Vice AI"""
    def __init__(self):
        from pathlib import Path
        BASE_DIR = Path(__file__).parent
        self.UPLOAD_FOLDER = BASE_DIR / 'smartstat_uploads'
        self.GENERATED_SCRIPTS_FOLDER = BASE_DIR / 'smartstat_scripts'
        self.REPORTS_FOLDER = BASE_DIR / 'smartstat_reports'
        self.OUTPUT_DIR = BASE_DIR / 'smartstat_output'
        
        # Ensure directories exist
        for directory in [self.UPLOAD_FOLDER, self.GENERATED_SCRIPTS_FOLDER, 
                         self.REPORTS_FOLDER, self.OUTPUT_DIR]:
            directory.mkdir(parents=True, exist_ok=True)
        
        # Use Vice AI's LLM config
        self.OPENAI_API_KEY = LLM_CONFIG['openai_api_key']
        self.GEMINI_API_KEY = LLM_CONFIG['gemini_api_key']
        self.AZURE_OPENAI_ENDPOINT = LLM_CONFIG['azure_openai_endpoint']
        self.AZURE_OPENAI_API_KEY = LLM_CONFIG['azure_openai_api_key']
        self.ANTHROPIC_API_KEY = LLM_CONFIG['anthropic_api_key']

Parameters

Name Type Default Kind
bases - -

Parameter Details

No parameters: The __init__ method takes no parameters. All configuration is derived from the file system location and the global LLM_CONFIG dictionary.

Return Value

Instantiation returns a SmartStatConfig object with initialized directory paths (as pathlib.Path objects) and API key strings. The class has no methods that return values; it serves purely as a configuration container.

Class Interface

Methods

__init__(self) -> None

Purpose: Initializes the SmartStatConfig instance by setting up directory paths and loading API keys from global LLM_CONFIG

Returns: None - initializes instance attributes

Attributes

Name Type Description Scope
UPLOAD_FOLDER pathlib.Path Directory path for storing uploaded files for SmartStat processing instance
GENERATED_SCRIPTS_FOLDER pathlib.Path Directory path for storing generated analysis scripts instance
REPORTS_FOLDER pathlib.Path Directory path for storing generated statistical reports instance
OUTPUT_DIR pathlib.Path Directory path for storing general output files from SmartStat operations instance
OPENAI_API_KEY str API key for OpenAI services, retrieved from LLM_CONFIG['openai_api_key'] instance
GEMINI_API_KEY str API key for Google Gemini services, retrieved from LLM_CONFIG['gemini_api_key'] instance
AZURE_OPENAI_ENDPOINT str Endpoint URL for Azure OpenAI services, retrieved from LLM_CONFIG['azure_openai_endpoint'] instance
AZURE_OPENAI_API_KEY str API key for Azure OpenAI services, retrieved from LLM_CONFIG['azure_openai_api_key'] instance
ANTHROPIC_API_KEY str API key for Anthropic Claude services, retrieved from LLM_CONFIG['anthropic_api_key'] instance

Dependencies

  • pathlib

Required Imports

from pathlib import Path

Usage Example

# Ensure LLM_CONFIG is defined globally
LLM_CONFIG = {
    'openai_api_key': 'sk-...',
    'gemini_api_key': 'AIza...',
    'azure_openai_endpoint': 'https://...',
    'azure_openai_api_key': 'abc123...',
    'anthropic_api_key': 'sk-ant-...'
}

# Instantiate the config
config = SmartStatConfig()

# Access directory paths
upload_path = config.UPLOAD_FOLDER
scripts_path = config.GENERATED_SCRIPTS_FOLDER

# Access API keys
openai_key = config.OPENAI_API_KEY
gemini_key = config.GEMINI_API_KEY

# Use paths for file operations
file_path = config.UPLOAD_FOLDER / 'data.csv'
with open(file_path, 'w') as f:
    f.write('sample data')

Best Practices

  • Ensure LLM_CONFIG dictionary is properly defined in the global scope before instantiating SmartStatConfig
  • Instantiate SmartStatConfig once at application startup and reuse the instance throughout the application lifecycle
  • Do not modify the directory paths after instantiation as other services may depend on these locations
  • Ensure the application has appropriate file system permissions to create directories in the module's parent directory
  • Keep API keys secure and never commit LLM_CONFIG values to version control
  • The class creates directories automatically on instantiation, so no manual directory setup is needed
  • All directory paths are pathlib.Path objects, use them with the / operator for path joining
  • The class has no cleanup or teardown methods; directories persist after the object is destroyed

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class Config_v1 71.4% similar

    Configuration class that centralizes all application settings including Flask configuration, directory paths, API keys, LLM model settings, and statistical analysis parameters.

    From: /tf/active/vicechatdev/full_smartstat/config.py
  • class SmartStatService 67.3% similar

    Service for running SmartStat analysis sessions in Vice AI

    From: /tf/active/vicechatdev/vice_ai/smartstat_service.py
  • class Config 65.4% similar

    Configuration class that manages application-wide settings, directory structures, API keys, and operational parameters for a statistical analysis application.

    From: /tf/active/vicechatdev/vice_ai/smartstat_config.py
  • class SmartStatSession 55.2% similar

    A session management class that encapsulates a SmartStat statistical analysis session, tracking data, analysis history, plots, and reports for a specific data section.

    From: /tf/active/vicechatdev/vice_ai/smartstat_service.py
  • class Config_v3 54.1% similar

    Configuration manager class that loads, manages, and persists configuration settings for a contract validity analyzer application, supporting YAML files and environment variable overrides.

    From: /tf/active/vicechatdev/contract_validity_analyzer/config/config.py
← Back to Browse