File size: 2,485 Bytes
54c2a57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ecf3087
 
948f3da
ecf3087
54c2a57
 
 
 
 
 
 
 
 
3ab87df
 
54c2a57
 
 
 
 
 
 
 
 
 
 
 
5ed3596
 
 
54c2a57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from pydantic_settings import BaseSettings, SettingsConfigDict
from urllib.parse import quote_plus


class Settings(BaseSettings):
    """
    Manages application settings and loads environment variables from a .env file.
    It constructs the complete MongoDB connection string from individual components.
    """

    # Database name
    DB_NAME: str

    # AI Model name
    SENTIMENT_MODEL: str

    # YouTube API Key
    YT_API_KEY: str

    # MongoDB connection details
    MONGODB_URI: str
    MONGODB_USR: str
    MONGODB_PWD: str

    # Data Fetching Strategy Settings
    FETCH_NUM_ENTITIES: int = 20
    FETCH_VIDEOS_PER_ENTITY: int = 5
    FETCH_COMMENTS_PER_VIDEO: int = 100
    FETCH_TOTAL_COMMENTS_PER_ENTITY: int = 500
    FETCH_TRENDS_GEO: str = "US"
    FETCH_TRENDS_WITHIN_DAYS: int = 7

    # Consumer Performance Settings
    CONSUMER_BATCH_SIZE: int = 32
    CONSUMER_BATCH_TIMEOUT_SECONDS: int = 5

    # Cache folder
    HF_HOME: str = "/data"
    TRANSFORMERS_CACHE: str = "./.cache"

    # FastAPI
    API_PREFIX: str = "/api"
    API_VERSION: str = "/v1"
    API_PREFIX_TRENDS: str
    DEBUG: bool = False

    # QStash Settings
    QSTASH_URL: str = "https://qstash.upstash.io"
    QSTASH_TOKEN: str
    # QSTASH_CURRENT_SIGNING_KEY: str
    # QSTASH_NEXT_SIGNING_KEY: str

    # Base URL for the application, used for constructing callback URLs
    BASE_URL: str = "http://localhost:8000"

    # Display Settings
    HOME_PAGE_ENTITIES_LIMIT: int = 10
    REPRESENTATIVE_COMMENTS_LIMIT: int = 3

    # On-Demand Use Case
    ON_DEMAND_COMMENTS_PER_VIDEO: int = 100
    ON_DEMAND_TOTAL_COMMENTS: int = 500

    # Inference Batch Size
    INFERENCE_BATCH_SIZE: int = 32

    # Pydantic model configuration to load from .env file
    model_config = SettingsConfigDict(
        env_file=".env", env_file_encoding="utf-8", extra="ignore"
    )

    @property
    def MONGODB_CONNECTION_STRING(self) -> str:
        """
        Constructs and returns the full MongoDB connection string,
        properly escaping the username and password.
        """
        # Escape username and password to handle special characters
        escaped_usr = quote_plus(self.MONGODB_USR)
        escaped_pwd = quote_plus(self.MONGODB_PWD)

        # Replace placeholders in the URI
        return self.MONGODB_URI.replace("<username>", escaped_usr).replace(
            "<password>", escaped_pwd
        )


# Create a single instance of the Settings class
settings = Settings()