-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsettings.py
More file actions
82 lines (65 loc) · 2.72 KB
/
settings.py
File metadata and controls
82 lines (65 loc) · 2.72 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
import boto3
import os
import yaml
from pathlib import Path
from pydantic_settings import BaseSettings
from src.modules.logger import get_logger
LOGGER = get_logger(__name__)
CWF = Path(__file__)
ROOT = CWF.parent.parent.parent.absolute().__str__()
PARAMS = yaml.safe_load(
Path(os.path.join(ROOT, "config", "params.yaml")).read_text(encoding="utf-8")
)
AWS_SESSION = boto3.Session()
AWS_SSM_CLIENT = AWS_SESSION.client("ssm")
def get_ssm_parameter(name: str | None, default: str | None = None) -> str | None:
"""
Retrieves a specific value from AWS Systems Manager's Parameter Store.
:param name: The name of the parameter to retrieve.
:param default: The default value to return if the parameter is not found.
:return: The value of the requested parameter.
"""
if name is None:
name = "none-params-in-ssm"
try:
response = AWS_SSM_CLIENT.get_parameter(Name=name, WithDecryption=True)
value = response["Parameter"]["Value"]
except AWS_SSM_CLIENT.exceptions.ParameterNotFound:
LOGGER.warning(
f"Parameter {name} not found in SSM, returning default: {default}"
)
return default
return value
class ChatbotSettings(BaseSettings):
"""Settings for the chatbot application."""
# api keys
google_api_key: str = get_ssm_parameter(
name=os.getenv("CHB_AWS_SSM_GOOGLE_API_KEY"),
default=os.getenv("CHB_AWS_GOOGLE_API_KEY"),
)
# RAG settings
embed_batch_size: int = int(os.getenv("CHB_EMBED_BATCH_SIZE", "100"))
embed_dim: int = int(os.getenv("CHB_EMBEDDING_DIM", "768"))
embed_model_id: str = os.getenv("CHB_EMBED_MODEL_ID", "gemini-embedding-001")
embed_retries: int = int(os.getenv("CHB_EMBED_RETRIES", "30"))
embed_retry_min_seconds: float = float(
os.getenv("CHB_EMBED_RETRY_MIN_SECONDS", "1.5")
)
embed_task_docs: str = "RETRIEVAL_DOCUMENT"
max_tokens: int = int(os.getenv("CHB_MODEL_MAXTOKENS", "2048"))
model_id: str = os.getenv("CHB_MODEL_ID", "gemini-2.5-flash-lite")
provider: str = os.getenv("CHB_PROVIDER", "google")
temperature_rag: float = float(os.getenv("CHB_MODEL_TEMPERATURE", "0.3"))
# vector index and docs params
chunk_overlap: int = PARAMS["vector_index"]["chunk_overlap"]
chunk_size: int = PARAMS["vector_index"]["chunk_size"]
index_id: str = os.getenv("CHB_INDEX_ID", "devportal-index")
bucket_static_content: str = os.getenv(
"CHB_AWS_S3_BUCKET_NAME_STATIC_CONTENT", "devportal-d-website-static-content"
)
# urls
redis_url: str = os.getenv("CHB_REDIS_URL")
website_url: str = os.getenv("CHB_WEBSITE_URL")
# other
language_code: str = os.getenv("CHB_LANGUAGE_CODE_STATIC_FILES", "it")
SETTINGS = ChatbotSettings()