-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.py
More file actions
108 lines (86 loc) · 3.48 KB
/
settings.py
File metadata and controls
108 lines (86 loc) · 3.48 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import torch
from loguru import logger
from pydantic_settings import BaseSettings, SettingsConfigDict
from zenml.client import Client
from zenml.exceptions import EntityExistsError
class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8")
# OpenAI
OPENAI_API_KEY: str | None = None
OPENAI_MODEL_ID: str | None = None
# ollama model
OLLAMA_MODEL_ID: str | None = None
# ollama inference params
# OLLAMA_BASE_URL: str = "http://localhost:11434"
# huggingface model
HUGGINGFACE_INFERENCE_MODEL_ID: str | None = None
TEMPERATURE_INFERENCE: float = 0.15
MAX_NEW_TOKENS_INFERENCE: int = 1024
TOP_P_INFERENCE: float = 0.90
REPETITION_PENALTY: float = 1.05
HF_MODEL_DEVICE: str = (
"cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
)
# huggingface token
HUGGINGFACE_ACCESS_TOKEN: str | None = None
# Comet ML (during training)
COMET_API_KEY: str | None = None
COMET_PROJECT: str | None = None
# MongoDB database
DATABASE_HOST: str | None = None # mongodb://localhost:27017/
DATABASE_NAME: str | None = None
# Qdrant vector database
USE_QDRANT_CLOUD: bool = False
QDRANT_DATABASE_HOST: str | None = None # localhost
QDRANT_DATABASE_PORT: int | None = None # 6333
QDRANT_CLOUD_URL: str = "str"
QDRANT_APIKEY: str | None = None
# RAG
TEXT_EMBEDDING_MODEL_ID: str = "sentence-transformers/all-MiniLM-L6-v2"
RERANKING_CROSS_ENCODER_MODEL_ID: str = "cross-encoder/ms-marco-MiniLM-L4-v2"
RAG_MODEL_DEVICE: str = (
"cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
)
# uvicorn
UVICORN_HOST: str | None = None
UVICORN_PORT: int = 8000
UVICORN_RELOAD: bool = True
@property
def OPENAI_MAX_TOKEN_WINDOW(self) -> int:
official_max_token_window = {
"gpt-4o-mini": 128_000,
"gpt-4.1-nano": 1_047_576,
}.get(self.OPENAI_MODEL_ID, 128_000)
max_token_window = int(official_max_token_window * 0.90) # Use 90% of the official max token window to be safe
return max_token_window
@classmethod
def load_settings(cls) -> "Settings":
"""
Load settings from the ZenML secret store or fallback to .env file.
:return:Settings: The initialized settings object.
"""
try:
logger.info("Loading settings from the ZenML secret store.")
settings_secrets = Client().get_secret("settings")
loaded_settings = Settings(**settings_secrets.secret_values)
except (RuntimeError, KeyError):
logger.warning(
"Failed to load settings from the ZenML secret store. Defaulting to loading the settings from the '.env' file."
)
loaded_settings = Settings()
return loaded_settings
def export(self) -> None:
"""
Exports the settings to the ZenML secret store.
"""
env_vars = self.model_dump()
for key, value in env_vars.items():
env_vars[key] = str(value)
client = Client()
try:
client.create_secret(name="settings", values=env_vars)
except EntityExistsError:
logger.warning(
"Secret 'scope' already exists. Delete it manually by running 'zenml secret delete settings', before trying to recreate it."
)
settings = Settings.load_settings()