-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsettings.py
More file actions
143 lines (110 loc) · 4.17 KB
/
Copy pathsettings.py
File metadata and controls
143 lines (110 loc) · 4.17 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
"""
LegalMind Configuration Settings
Google Cloud / Vertex AI Configuration
"""
import os
from typing import Optional
from pathlib import Path
from pydantic_settings import BaseSettings
from pydantic import field_validator, Field
from functools import lru_cache
class Settings(BaseSettings):
"""Application settings loaded from environment variables."""
# -------------------------------------------------------------------------
# Vertex AI Configuration
# -------------------------------------------------------------------------
gemini_model: str = "gemini-2.0-flash"
# -------------------------------------------------------------------------
# Google Cloud Project Configuration
# -------------------------------------------------------------------------
google_cloud_project: str = ""
google_application_credentials: Optional[str] = None
# -------------------------------------------------------------------------
# Firestore Configuration
# -------------------------------------------------------------------------
firestore_database: str = "(default)"
# -------------------------------------------------------------------------
# Cloud Storage Configuration
# -------------------------------------------------------------------------
gcs_bucket_name: str = "legalmind-contracts"
gcs_contracts_folder: str = "contracts"
gcs_documents_folder: str = "generated-documents"
# -------------------------------------------------------------------------
# Application Settings
# -------------------------------------------------------------------------
app_name: str = "LegalMind"
app_env: str = "development"
debug: bool = True
# Security Settings
api_secret_key: str = ""
allowed_origins: str = ""
# API Server
api_host: str = "0.0.0.0"
api_port: int = 8000
# Session Configuration
session_timeout_minutes: int = 60
max_tokens_per_request: int = 8192
# Rate Limiting
rate_limit_requests_per_minute: int = 30
# Caching
response_cache_ttl_seconds: int = 60
# -------------------------------------------------------------------------
# Feature Flags
# -------------------------------------------------------------------------
enable_search_grounding: bool = True
enable_thinking_logs: bool = True
enable_citations: bool = True
@field_validator("google_cloud_project", mode="after")
@classmethod
def validate_project(cls, v):
"""Validate Google Cloud project is configured."""
if not v:
raise ValueError(
"Missing required environment variable: GOOGLE_CLOUD_PROJECT. "
"Please set it in your .env.local file."
)
return v
model_config = {
"env_file": str(Path(__file__).parent.parent / ".env.local"),
"env_file_encoding": "utf-8",
"case_sensitive": False,
"extra": "allow",
"validate_assignment": True,
}
@lru_cache()
def get_settings() -> Settings:
"""Get cached settings instance.
Returns:
Settings: Application settings
"""
return Settings()
def get_google_cloud_project() -> str:
"""Get the Google Cloud project ID.
Returns:
str: The Google Cloud project ID
Raises:
ValueError: If the project ID is not configured
"""
settings = get_settings()
return settings.google_cloud_project
def get_gcs_bucket_name() -> str:
"""Get the Google Cloud Storage bucket name.
Returns:
str: The GCS bucket name
"""
return get_settings().gcs_bucket_name
def validate_settings() -> bool:
"""Validate that all required settings are configured.
Returns:
bool: True if all settings are valid
Raises:
ValueError: If any required settings are missing
"""
settings = get_settings()
# GOOGLE_CLOUD_PROJECT is always required
if not settings.google_cloud_project:
raise ValueError(
"Missing required environment variable: GOOGLE_CLOUD_PROJECT. "
"Please check your .env file."
)
return True