-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetting.py
More file actions
73 lines (59 loc) · 2.13 KB
/
setting.py
File metadata and controls
73 lines (59 loc) · 2.13 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
import logging
from pydantic import Field, field_validator
from pydantic_settings import BaseSettings
from modules.models.groq_models import GroqModel
class Settings(BaseSettings):
"""
The Settings class manages the application's configuration.
This includes settings for the API key, LLM model, a flag for tracking execution time,
and the logging verbosity level. Configuration values are loaded from environment
variables or a `.env` file.
"""
api_key: str = Field(description="API key for authentication")
model: str = Field(
default=GroqModel.LLAMA3_70B_8192.value,
description="The LLM model to use (must be a valid model from GroqModel)"
)
track_execution_time: bool = Field(
default=True,
description="Flag to enable tracking of execution time"
)
verbose: int = Field(
default=1,
description="Logging verbosity level; 0 for WARN, 1 for INFO, 2 for DEBUG"
)
@field_validator('model')
def validate_model(cls, v: str) -> str:
"""
Validate that the specified model is available in GroqModel.
Args:
v (str): The model name to validate.
Returns:
str: The validated model name.
Raises:
ValueError: If the model name is not a valid model from GroqModel.
"""
if v not in [model.value for model in GroqModel]:
raise ValueError(f"Model '{v}' is not a valid model.")
return v
@property
def logging_level(self) -> int:
"""
Determine the logging level based on the verbosity setting.
Returns:
int: The logging level constant (e.g., logging.WARN, logging.INFO, logging.DEBUG).
"""
logging_levels = {
0: logging.WARN,
1: logging.INFO,
2: logging.DEBUG
}
return logging_levels.get(self.verbose, logging.INFO)
class Config:
"""
Settings configuration.
Loads variables from a .env file and applies case insensitivity for field names.
"""
env_file = ".env"
case_sensitive = False
CFG = Settings()