Skip to content

src.llm.adapters.watsonx.watsonx_config.WatsonXConfig

Configuration management for WatsonX credentials and settings.

This class handles loading and validation of required WatsonX credentials from environment variables.

Attributes:

Name Type Description
CREDS dict

Dictionary containing API key and URL for WatsonX.

PROJECT_ID str

WatsonX project identifier.

Example
# Validate credentials before use
WatsonXConfig.validate_credentials()

# Access credentials
credentials = WatsonXConfig.CREDS
project_id = WatsonXConfig.PROJECT_ID
Source code in src/llm/adapters/watsonx/watsonx_config.py
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
class WatsonXConfig:
    """Configuration management for WatsonX credentials and settings.

    This class handles loading and validation of required WatsonX credentials
    from environment variables.

    Attributes:
        CREDS (dict): Dictionary containing API key and URL for WatsonX.
        PROJECT_ID (str): WatsonX project identifier.

    Example:
        ```python
        # Validate credentials before use
        WatsonXConfig.validate_credentials()

        # Access credentials
        credentials = WatsonXConfig.CREDS
        project_id = WatsonXConfig.PROJECT_ID
        ```
    """
    CREDS = {'apikey': os.getenv("WXAI_API_KEY"), 'url': os.getenv("WXAI_URL")}
    PROJECT_ID = os.getenv("WXAI_PROJECT_ID")

    @classmethod
    def validate_credentials(cls):
        """Validate the presence of required WatsonX credentials.

        Checks for the presence of all required credentials and logs appropriate
        messages for missing values.

        Raises:
            ValueError: If any required credential is missing.
        """
        missing = [key for key, value in {
            'WXAI_API_KEY': cls.CREDS['apikey'],
            'WXAI_URL': cls.CREDS['url'],
            'WXAI_PROJECT_ID': cls.PROJECT_ID
        }.items() if not value]

        if missing:
            logger.error(f"Missing WatsonX credentials: {', '.join(missing)}")
            raise ValueError(f"Missing WatsonX credentials: {', '.join(missing)}")

        logger.info("All WatsonX credentials loaded successfully.")

validate_credentials() classmethod

Validate the presence of required WatsonX credentials.

Checks for the presence of all required credentials and logs appropriate messages for missing values.

Raises:

Type Description
ValueError

If any required credential is missing.

Source code in src/llm/adapters/watsonx/watsonx_config.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
@classmethod
def validate_credentials(cls):
    """Validate the presence of required WatsonX credentials.

    Checks for the presence of all required credentials and logs appropriate
    messages for missing values.

    Raises:
        ValueError: If any required credential is missing.
    """
    missing = [key for key, value in {
        'WXAI_API_KEY': cls.CREDS['apikey'],
        'WXAI_URL': cls.CREDS['url'],
        'WXAI_PROJECT_ID': cls.PROJECT_ID
    }.items() if not value]

    if missing:
        logger.error(f"Missing WatsonX credentials: {', '.join(missing)}")
        raise ValueError(f"Missing WatsonX credentials: {', '.join(missing)}")

    logger.info("All WatsonX credentials loaded successfully.")