|
| 1 | +import os |
| 2 | +from dataclasses import dataclass |
| 3 | + |
| 4 | + |
| 5 | +@dataclass |
| 6 | +class Settings: |
| 7 | + ibm_cloud_api_key: str |
| 8 | + watsonx_region: str |
| 9 | + watsonx_project_id: str |
| 10 | + watsonx_embed_model: str |
| 11 | + watsonx_gen_model: str |
| 12 | + |
| 13 | + cos_endpoint: str |
| 14 | + cos_bucket: str |
| 15 | + cos_instance_crn: str |
| 16 | + cos_api_key: str | None |
| 17 | + cos_auth_endpoint: str |
| 18 | + cos_hmac_access_key_id: str |
| 19 | + cos_hmac_secret_access_key: str |
| 20 | + |
| 21 | + milvus_host: str |
| 22 | + milvus_port: int |
| 23 | + milvus_db: str | None |
| 24 | + milvus_tls: bool |
| 25 | + |
| 26 | + faiss_index_path: str |
| 27 | + faiss_meta_path: str |
| 28 | + |
| 29 | + chunk_size: int |
| 30 | + chunk_overlap: int |
| 31 | + top_k: int |
| 32 | + temperature: float |
| 33 | + embedding_dim: int |
| 34 | + |
| 35 | + @staticmethod |
| 36 | + def _get_bool(value: str | None, default: bool = False) -> bool: |
| 37 | + if value is None: |
| 38 | + return default |
| 39 | + return value.lower() in {"1", "true", "t", "yes", "y"} |
| 40 | + |
| 41 | + @classmethod |
| 42 | + def from_env(cls) -> "Settings": |
| 43 | + return cls( |
| 44 | + ibm_cloud_api_key=os.getenv("IBM_CLOUD_API_KEY", ""), |
| 45 | + watsonx_region=os.getenv("WATSONX_REGION", "us-south"), |
| 46 | + watsonx_project_id=os.getenv("WATSONX_PROJECT_ID", ""), |
| 47 | + watsonx_embed_model=os.getenv("WATSONX_EMBED_MODEL", "ibm/granite-embedding-30m-english"), |
| 48 | + watsonx_gen_model=os.getenv("WATSONX_GEN_MODEL", "ibm/granite-13b-instruct-v2"), |
| 49 | + cos_endpoint=os.getenv("COS_ENDPOINT", ""), |
| 50 | + cos_bucket=os.getenv("COS_BUCKET", ""), |
| 51 | + cos_instance_crn=os.getenv("COS_INSTANCE_CRN", ""), |
| 52 | + cos_api_key=os.getenv("COS_API_KEY") or os.getenv("IBM_CLOUD_API_KEY"), |
| 53 | + cos_auth_endpoint=os.getenv("COS_AUTH_ENDPOINT", "https://iam.cloud.ibm.com/identity/token"), |
| 54 | + cos_hmac_access_key_id=os.getenv("COS_HMAC_ACCESS_KEY_ID", ""), |
| 55 | + cos_hmac_secret_access_key=os.getenv("COS_HMAC_SECRET_ACCESS_KEY", ""), |
| 56 | + milvus_host=os.getenv("MILVUS_HOST", "localhost"), |
| 57 | + milvus_port=int(os.getenv("MILVUS_PORT", "19530")), |
| 58 | + milvus_db=os.getenv("MILVUS_DB"), |
| 59 | + milvus_tls=cls._get_bool(os.getenv("MILVUS_TLS"), False), |
| 60 | + faiss_index_path=os.getenv("FAISS_INDEX_PATH", "data/index.faiss"), |
| 61 | + faiss_meta_path=os.getenv("FAISS_META_PATH", "data/meta.json"), |
| 62 | + chunk_size=int(os.getenv("CHUNK_SIZE", "1200")), |
| 63 | + chunk_overlap=int(os.getenv("CHUNK_OVERLAP", "150")), |
| 64 | + top_k=int(os.getenv("TOP_K", "6")), |
| 65 | + temperature=float(os.getenv("TEMPERATURE", "0.2")), |
| 66 | + embedding_dim=int(os.getenv("EMBEDDING_DIM", "1024")), |
| 67 | + ) |
| 68 | + |
| 69 | + |
0 commit comments