File size: 1,186 Bytes
a01e687
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Configuration management."""

import os
from typing import Optional


class Config:
    """Application configuration."""

    def __init__(self):
        """Initialize configuration from environment variables."""
        self.openai_api_key = os.getenv("OPENAI_API_KEY", "")
        self.langchain_api_key = os.getenv("LANGCHAIN_API_KEY", "")
        self.langchain_tracing_v2 = os.getenv("LANGCHAIN_TRACING_V2", "false").lower() == "true"
        self.langchain_project = os.getenv("LANGCHAIN_PROJECT", "react-text-analyzer")
        self.model_name = os.getenv("MODEL_NAME", "gpt-4-turbo-preview")

    def is_valid(self) -> bool:
        """Check if required configuration is present.

        Returns:
            True if configuration is valid
        """
        return bool(self.openai_api_key)

    def get_openai_key(self) -> str:
        """Get OpenAI API key.

        Returns:
            API key
        """
        return self.openai_api_key

    def is_langsmith_enabled(self) -> bool:
        """Check if LangSmith tracing is enabled.

        Returns:
            True if enabled
        """
        return self.langchain_tracing_v2 and bool(self.langchain_api_key)