Spaces:
Sleeping
Sleeping
| # flake8: noqa: E501 | |
| # pylint: disable=C0301 | |
| """ | |
| Configuration module for ClipboardHealthAI application. | |
| """ | |
| import os | |
| import pathlib | |
| import time | |
| from functools import lru_cache | |
| from typing import Optional, Type | |
| from dotenv import load_dotenv | |
| from langchain_core.runnables import Runnable | |
| from langchain_openai import ChatOpenAI | |
| from motor.motor_asyncio import AsyncIOMotorClient, AsyncIOMotorDatabase | |
| from pydantic import BaseModel | |
| load_dotenv() | |
| time.tzset() | |
| class BaseConfig: | |
| """ | |
| Base configuration class containing common settings for all environments. | |
| """ | |
| BASE_DIR: pathlib.Path = pathlib.Path(__file__).parent.parent.parent | |
| SECRET_KEY: str = os.getenv("SECRET", "") | |
| DB_CLIENT: AsyncIOMotorDatabase = AsyncIOMotorClient(os.getenv("MONGO_DB_URL")).euscrapper | |
| LINKEDIN_COOKIE_LI_AT = os.getenv("LINKEDIN_COOKIE_LI_AT") | |
| LINKEDIN_COOKIE_JSESSIONID = os.getenv("LINKEDIN_COOKIE_JSESSIONID") | |
| def get_headers(api_key: str) -> dict: | |
| """ | |
| Generate HTTP headers for API requests. | |
| """ | |
| return { | |
| "Authorization": f"Bearer {api_key}", | |
| "Content-Type": "application/json", | |
| "Accept": "application/json", | |
| } | |
| def get_llm( | |
| model: str = "gpt-5-mini", | |
| temperature: float = 1.0, | |
| schema: Optional[Type[BaseModel]] = None, | |
| is_json: bool = False, | |
| ) -> Runnable: | |
| """ | |
| Get a configured LLM instance. | |
| """ | |
| kwargs = {"model": model, "temperature": temperature} | |
| if model.startswith("gpt-5"): | |
| kwargs["reasoning_effort"] = "minimal" | |
| if schema: | |
| return ChatOpenAI(**kwargs).with_structured_output(schema) | |
| if is_json: | |
| return ChatOpenAI(**kwargs).with_structured_output(method="json_mode") | |
| return ChatOpenAI(**kwargs) | |
| class DevelopmentConfig(BaseConfig): | |
| """ | |
| Development environment configuration settings. | |
| """ | |
| Issuer = "http://localhost:8000" | |
| Audience = "http://localhost:3000" | |
| class ProductionConfig(BaseConfig): | |
| """ | |
| Production environment configuration settings. | |
| """ | |
| Issuer = "https://schedulerapi.cbhexp.com" | |
| Audience = "https://scheduler.cbhexp.com" | |
| def get_settings() -> DevelopmentConfig | ProductionConfig: | |
| """ | |
| Get the appropriate configuration based on the current environment. | |
| """ | |
| config_cls_dict = { | |
| "development": DevelopmentConfig, | |
| "production": ProductionConfig, | |
| } | |
| config_name = os.getenv("FASTAPI_CONFIG", default="development") | |
| config_cls = config_cls_dict[config_name] | |
| return config_cls() # type: ignore | |
| settings = get_settings() | |