refactor: streamline Settings class by removing unused properties and simplifying path resolution
This commit is contained in:
parent
0abbae93a4
commit
4fce9c9a98
162
src/config.py
162
src/config.py
|
|
@ -1,35 +1,29 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
from typing import Optional
|
||||||
from dotenv import load_dotenv
|
|
||||||
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||||
|
|
||||||
load_dotenv()
|
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
raw_path_: str
|
data_path_: Optional[str] = None
|
||||||
data_path_: str
|
raw_path_: Optional[str] = None
|
||||||
processed_path_: str
|
processed_path_: Optional[str] = None
|
||||||
models_path_: str
|
models_path_: Optional[str] = None
|
||||||
external_path_: str
|
external_path_: Optional[str] = None
|
||||||
kubeconfig_path: str
|
interim_path_: Optional[str] = None
|
||||||
interim_path_: str
|
kubeconfig_path_: Optional[str] = None
|
||||||
database_url: str
|
postgres_url: str
|
||||||
openai_api_key: str
|
elasticsearch_url: str
|
||||||
elasticsearch_index: str
|
elasticsearch_local_url: str
|
||||||
elasticsearch_docs_index: str
|
ollama_url: str
|
||||||
elasticsearch_code_index: str
|
ollama_local_url: str
|
||||||
llm_base_url: str
|
ollama_model_name: str
|
||||||
ollama_url: str
|
ollama_emb_model_name: str
|
||||||
ollama_local_url: str
|
langfuse_host: str
|
||||||
langfuse_host: str
|
langfuse_public_key: str
|
||||||
elasticsearch_url: str
|
langfuse_secret_key: str
|
||||||
elasticsearch_local_url: str
|
hf_token: str
|
||||||
ollama_model_name: str
|
hf_emb_model_name: str
|
||||||
ollama_emb_model_name: str
|
|
||||||
model_name: str
|
|
||||||
hf_emb_model_name: str
|
|
||||||
langfuse_public_key: str
|
|
||||||
langfuse_secret_key: str
|
|
||||||
hf_token: str
|
|
||||||
|
|
||||||
model_config = SettingsConfigDict(
|
model_config = SettingsConfigDict(
|
||||||
env_file=".env",
|
env_file=".env",
|
||||||
|
|
@ -39,114 +33,40 @@ class Settings(BaseSettings):
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def proj_root(self) -> Path:
|
def project_root(self) -> Path:
|
||||||
return Path(__file__).resolve().parents[1]
|
return Path(__file__).resolve().parents[1]
|
||||||
|
|
||||||
@property
|
def _resolve_path(self, path: Optional[str]) -> Optional[Path]:
|
||||||
def data_path(self) -> Path:
|
if path is None:
|
||||||
proj_root = self.proj_root
|
return None
|
||||||
return proj_root / self.data_path_
|
return self.project_root / path
|
||||||
|
|
||||||
@property
|
|
||||||
def models_path(self) -> Path:
|
|
||||||
proj_root = self.proj_root
|
|
||||||
return proj_root / self.models_path_
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def processed_path(self) -> Path:
|
def data_path(self) -> Optional[Path]:
|
||||||
proj_root = self.proj_root
|
return self._resolve_path(self.data_path_)
|
||||||
return proj_root / self.processed_path_
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def raw_path(self) -> Path:
|
def raw_path(self) -> Optional[Path]:
|
||||||
proj_root = self.proj_root
|
return self._resolve_path(self.raw_path_)
|
||||||
return proj_root / self.raw_path_
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def interim_path(self) -> Path:
|
def processed_path(self) -> Optional[Path]:
|
||||||
proj_root = self.proj_root
|
return self._resolve_path(self.processed_path_)
|
||||||
return proj_root / self.interim_path_
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def external_path(self) -> Path:
|
def models_path(self) -> Optional[Path]:
|
||||||
proj_root = self.proj_root
|
return self._resolve_path(self.models_path_)
|
||||||
return proj_root / self.external_path_
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def database_url(self) -> str:
|
def external_path(self) -> Optional[Path]:
|
||||||
return self.database_url
|
return self._resolve_path(self.external_path_)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def openai_api_key(self) -> str:
|
def interim_path(self) -> Optional[Path]:
|
||||||
return self.openai_api_key
|
return self._resolve_path(self.interim_path_)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def elasticsearch_index(self) -> str:
|
def kubeconfig_path(self) -> Optional[Path]:
|
||||||
return self.elasticsearch_index
|
return self._resolve_path(self.kubeconfig_path_)
|
||||||
|
|
||||||
@property
|
|
||||||
def elasticsearch_docs_index(self) -> str:
|
|
||||||
return self.elasticsearch_docs_index
|
|
||||||
|
|
||||||
@property
|
|
||||||
def elasticsearch_code_index(self) -> str:
|
|
||||||
return self.elasticsearch_code_index
|
|
||||||
|
|
||||||
@property
|
|
||||||
def llm_base_url(self) -> str:
|
|
||||||
return self.llm_base_url
|
|
||||||
|
|
||||||
@property
|
|
||||||
def ollama_url(self) -> str:
|
|
||||||
return self.ollama_url
|
|
||||||
|
|
||||||
@property
|
|
||||||
def ollama_local_url(self) -> str:
|
|
||||||
return self.ollama_local_url
|
|
||||||
|
|
||||||
@property
|
|
||||||
def langfuse_host(self) -> str:
|
|
||||||
return self.langfuse_host
|
|
||||||
|
|
||||||
@property
|
|
||||||
def elasticsearch_url(self) -> str:
|
|
||||||
return self.elasticsearch_url
|
|
||||||
|
|
||||||
@property
|
|
||||||
def elasticsearch_local_url(self) -> str:
|
|
||||||
return self.elasticsearch_local_url
|
|
||||||
|
|
||||||
@property
|
|
||||||
def ollama_model_name(self) -> str:
|
|
||||||
return self.ollama_model_name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def ollama_emb_model_name(self) -> str:
|
|
||||||
return self.ollama_emb_model_name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def model_name(self) -> str:
|
|
||||||
return self.model_name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def hf_emb_model_name(self) -> str:
|
|
||||||
return self.hf_emb_model_name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def langfuse_public_key(self) -> str:
|
|
||||||
return self.langfuse_public_key
|
|
||||||
|
|
||||||
@property
|
|
||||||
def langfuse_secret_key(self) -> str:
|
|
||||||
return self.langfuse_secret_key
|
|
||||||
|
|
||||||
@property
|
|
||||||
def hf_token(self) -> str:
|
|
||||||
return self.hf_token
|
|
||||||
|
|
||||||
@property
|
|
||||||
def kubeconfig_path(self) -> Path:
|
|
||||||
proj_root = self.proj_root
|
|
||||||
return proj_root / self.kubeconfig_path
|
|
||||||
|
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
Loading…
Reference in New Issue