Spaces:
Sleeping
Sleeping
Commit
·
3269c5f
1
Parent(s):
3eeed2d
Upload config.py with huggingface_hub
Browse files
config.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from loguru import logger
|
| 2 |
+
from pydantic import Field, field_validator
|
| 3 |
+
from pydantic_settings import BaseSettings, SettingsConfigDict
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class Settings(BaseSettings):
|
| 7 |
+
"""
|
| 8 |
+
A Pydantic-based settings class for managing application configurations.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
# --- Pydantic Settings ---
|
| 12 |
+
model_config: SettingsConfigDict = SettingsConfigDict(
|
| 13 |
+
env_file=".env", env_file_encoding="utf-8"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
# --- Comet ML & Opik Configuration ---
|
| 17 |
+
COMET_API_KEY: str | None = Field(
|
| 18 |
+
default="yPmLa7W6QyBODw1Pnfg9jqr7E", description="API key for Comet ML and Opik services."
|
| 19 |
+
)
|
| 20 |
+
COMET_PROJECT: str = Field(
|
| 21 |
+
default="second_brain_course",
|
| 22 |
+
description="Project name for Comet ML and Opik tracking.",
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
# --- Hugging Face Configuration ---
|
| 26 |
+
HUGGINGFACE_ACCESS_TOKEN: str | None = Field(
|
| 27 |
+
default=None, description="Access token for Hugging Face API authentication."
|
| 28 |
+
)
|
| 29 |
+
USE_HUGGINGFACE_DEDICATED_ENDPOINT: bool = Field(
|
| 30 |
+
default=False,
|
| 31 |
+
description="Whether to use the dedicated endpoint for summarizing responses. If True, we will use the dedicated endpoint instead of OpenAI.",
|
| 32 |
+
)
|
| 33 |
+
HUGGINGFACE_DEDICATED_ENDPOINT: str | None = Field(
|
| 34 |
+
default=None,
|
| 35 |
+
description="Dedicated endpoint URL for real-time inference. "
|
| 36 |
+
"If provided, we will use the dedicated endpoint instead of OpenAI. "
|
| 37 |
+
"For example, https://um18v2aeit3f6g1b.eu-west-1.aws.endpoints.huggingface.cloud/v1/, "
|
| 38 |
+
"with /v1 after the endpoint URL.",
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
# --- MongoDB Atlas Configuration ---
|
| 42 |
+
MONGODB_DATABASE_NAME: str = Field(
|
| 43 |
+
default="second_brain_course",
|
| 44 |
+
description="Name of the MongoDB database.",
|
| 45 |
+
)
|
| 46 |
+
MONGODB_COLLECTION_NAME: str = Field(
|
| 47 |
+
default="rag_insights_test",
|
| 48 |
+
description="Name of the MongoDB collection for RAG documents.",
|
| 49 |
+
)
|
| 50 |
+
MONGODB_URI: str = Field(
|
| 51 |
+
default="mongodb+srv://keshavchhaparia:bUSBXeVCGWDyQhDG@saaslabs.awtivxf.mongodb.net/?retryWrites=true&w=majority&appName=saaslabs",
|
| 52 |
+
description="Connection URI for the MongoDB Atlas instance.",
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
# --- OpenAI API Configuration ---
|
| 56 |
+
OPENAI_API_KEY: str = Field(
|
| 57 |
+
description="API key for OpenAI service authentication.",
|
| 58 |
+
)
|
| 59 |
+
OPENAI_MODEL_ID: str = Field(
|
| 60 |
+
default="gpt-4o", description="Identifier for the OpenAI model to be used."
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
@field_validator("OPENAI_API_KEY")
|
| 64 |
+
@classmethod
|
| 65 |
+
def check_not_empty(cls, value: str, info) -> str:
|
| 66 |
+
if not value or value.strip() == "":
|
| 67 |
+
logger.error(f"{info.field_name} cannot be empty.")
|
| 68 |
+
raise ValueError(f"{info.field_name} cannot be empty.")
|
| 69 |
+
return value
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
try:
|
| 73 |
+
settings = Settings()
|
| 74 |
+
except Exception as e:
|
| 75 |
+
logger.error(f"Failed to load configuration: {e}")
|
| 76 |
+
raise SystemExit(e)
|