|
2 | 2 |
|
3 | 3 | from typing import Final |
4 | 4 |
|
| 5 | +# Use Final[type] as type hint for all constants to ensure that type checkers (Mypy etc.) |
| 6 | +# will be able to detect assignements to such constants. |
| 7 | + |
5 | 8 | # Minimal and maximal supported Llama Stack version |
6 | 9 | MINIMAL_SUPPORTED_LLAMA_STACK_VERSION: Final[str] = "0.2.17" |
7 | 10 | MAXIMAL_SUPPORTED_LLAMA_STACK_VERSION: Final[str] = "0.6.0" |
8 | 11 |
|
9 | | -UNABLE_TO_PROCESS_RESPONSE = "Unable to process this request" |
| 12 | +UNABLE_TO_PROCESS_RESPONSE: Final[str] = "Unable to process this request" |
10 | 13 |
|
11 | 14 | # Response stored in the conversation when the user interrupts a streaming request |
12 | | -INTERRUPTED_RESPONSE_MESSAGE = "You interrupted this request." |
| 15 | +INTERRUPTED_RESPONSE_MESSAGE: Final[str] = "You interrupted this request." |
13 | 16 |
|
14 | 17 | # Max seconds to wait for topic summary in background task after interrupt persist. |
15 | | -TOPIC_SUMMARY_INTERRUPT_TIMEOUT_SECONDS = 30.0 |
| 18 | +TOPIC_SUMMARY_INTERRUPT_TIMEOUT_SECONDS: Final[float] = 30.0 |
16 | 19 |
|
17 | 20 | # Supported attachment types |
18 | 21 | ATTACHMENT_TYPES = frozenset( |
|
34 | 37 |
|
35 | 38 | # Default system prompt used only when no other system prompt is specified in |
36 | 39 | # configuration file nor in the query request |
37 | | -DEFAULT_SYSTEM_PROMPT = "You are a helpful assistant" |
| 40 | +DEFAULT_SYSTEM_PROMPT: Final[str] = "You are a helpful assistant" |
38 | 41 |
|
39 | 42 | # Default topic summary system prompt used only when no other topic summary system |
40 | 43 | # prompt is specified in configuration file |
41 | | -DEFAULT_TOPIC_SUMMARY_SYSTEM_PROMPT = """ |
| 44 | +DEFAULT_TOPIC_SUMMARY_SYSTEM_PROMPT: Final[str] = """ |
42 | 45 | Instructions: |
43 | 46 | - You are a topic summarizer |
44 | 47 | - Your job is to extract precise topic summary from user input |
|
104 | 107 | """ |
105 | 108 |
|
106 | 109 | # Authentication constants |
107 | | -DEFAULT_VIRTUAL_PATH = "/ls-access" |
108 | | -DEFAULT_USER_NAME = "lightspeed-user" |
109 | | -DEFAULT_SKIP_USER_ID_CHECK = True |
110 | | -DEFAULT_USER_UID = "00000000-0000-0000-0000-000" |
| 110 | +DEFAULT_VIRTUAL_PATH: Final[str] = "/ls-access" |
| 111 | +DEFAULT_USER_NAME: Final[str] = "lightspeed-user" |
| 112 | +DEFAULT_SKIP_USER_ID_CHECK: Final[bool] = True |
| 113 | +DEFAULT_USER_UID: Final[str] = "00000000-0000-0000-0000-000" |
111 | 114 | # default value for token when no token is provided |
112 | | -NO_USER_TOKEN = "" |
113 | | -AUTH_MOD_K8S = "k8s" |
114 | | -AUTH_MOD_NOOP = "noop" |
115 | | -AUTH_MOD_NOOP_WITH_TOKEN = "noop-with-token" |
116 | | -AUTH_MOD_APIKEY_TOKEN = "api-key-token" |
117 | | -AUTH_MOD_JWK_TOKEN = "jwk-token" |
118 | | -AUTH_MOD_RH_IDENTITY = "rh-identity" |
| 115 | +NO_USER_TOKEN: Final[str] = "" |
| 116 | +AUTH_MOD_K8S: Final[str] = "k8s" |
| 117 | +AUTH_MOD_NOOP: Final[str] = "noop" |
| 118 | +AUTH_MOD_NOOP_WITH_TOKEN: Final[str] = "noop-with-token" |
| 119 | +AUTH_MOD_APIKEY_TOKEN: Final[str] = "api-key-token" |
| 120 | +AUTH_MOD_JWK_TOKEN: Final[str] = "jwk-token" |
| 121 | +AUTH_MOD_RH_IDENTITY: Final[str] = "rh-identity" |
119 | 122 | # Supported authentication modules |
120 | 123 | SUPPORTED_AUTHENTICATION_MODULES = frozenset( |
121 | 124 | { |
|
129 | 132 | ) |
130 | 133 | DEFAULT_AUTHENTICATION_MODULE = AUTH_MOD_NOOP |
131 | 134 | # Maximum allowed size for base64-encoded x-rh-identity header (bytes) |
132 | | -DEFAULT_RH_IDENTITY_MAX_HEADER_SIZE = 8192 |
| 135 | +DEFAULT_RH_IDENTITY_MAX_HEADER_SIZE: Final[int] = 8192 |
133 | 136 |
|
134 | 137 | # Maximum allowed file upload size (bytes) - 100MB default |
135 | 138 | # Protects against DoS attacks via large file uploads |
136 | | -DEFAULT_MAX_FILE_UPLOAD_SIZE = 100 * 1024 * 1024 # 100 MB |
137 | | -DEFAULT_JWT_UID_CLAIM = "user_id" |
138 | | -DEFAULT_JWT_USER_NAME_CLAIM = "username" |
| 139 | +DEFAULT_MAX_FILE_UPLOAD_SIZE: Final[int] = 100 * 1024 * 1024 # 100 MB |
| 140 | +DEFAULT_JWT_UID_CLAIM: Final[str] = "user_id" |
| 141 | +DEFAULT_JWT_USER_NAME_CLAIM: Final[str] = "username" |
139 | 142 |
|
140 | 143 | # MCP authorization header special values |
141 | | -MCP_AUTH_KUBERNETES = "kubernetes" |
142 | | -MCP_AUTH_CLIENT = "client" |
143 | | -MCP_AUTH_OAUTH = "oauth" |
| 144 | +MCP_AUTH_KUBERNETES: Final[str] = "kubernetes" |
| 145 | +MCP_AUTH_CLIENT: Final[str] = "client" |
| 146 | +MCP_AUTH_OAUTH: Final[str] = "oauth" |
144 | 147 |
|
145 | 148 | # Media type constants for streaming responses |
146 | | -MEDIA_TYPE_JSON = "application/json" |
147 | | -MEDIA_TYPE_TEXT = "text/plain" |
148 | | -MEDIA_TYPE_EVENT_STREAM = "text/event-stream" |
| 149 | +MEDIA_TYPE_JSON: Final[str] = "application/json" |
| 150 | +MEDIA_TYPE_TEXT: Final[str] = "text/plain" |
| 151 | +MEDIA_TYPE_EVENT_STREAM: Final[str] = "text/event-stream" |
149 | 152 |
|
150 | 153 | # Streaming event type constants |
151 | | -LLM_TOKEN_EVENT = "token" |
152 | | -LLM_TOOL_CALL_EVENT = "tool_call" |
153 | | -LLM_TOOL_RESULT_EVENT = "tool_result" |
154 | | -LLM_TURN_COMPLETE_EVENT = "turn_complete" |
| 154 | +LLM_TOKEN_EVENT: Final[str] = "token" |
| 155 | +LLM_TOOL_CALL_EVENT: Final[str] = "tool_call" |
| 156 | +LLM_TOOL_RESULT_EVENT: Final[str] = "tool_result" |
| 157 | +LLM_TURN_COMPLETE_EVENT: Final[str] = "turn_complete" |
155 | 158 |
|
156 | 159 | # PostgreSQL connection constants |
157 | 160 | # See: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-SSLMODE |
158 | | -POSTGRES_DEFAULT_SSL_MODE = "prefer" |
| 161 | +POSTGRES_DEFAULT_SSL_MODE: Final[str] = "prefer" |
159 | 162 | # See: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-GSSENCMODE |
160 | | -POSTGRES_DEFAULT_GSS_ENCMODE = "prefer" |
| 163 | +POSTGRES_DEFAULT_GSS_ENCMODE: Final[str] = "prefer" |
161 | 164 |
|
162 | 165 | # cache constants |
163 | | -CACHE_TYPE_MEMORY = "memory" |
164 | | -CACHE_TYPE_SQLITE = "sqlite" |
165 | | -CACHE_TYPE_POSTGRES = "postgres" |
166 | | -CACHE_TYPE_NOOP = "noop" |
| 166 | +CACHE_TYPE_MEMORY: Final[str] = "memory" |
| 167 | +CACHE_TYPE_SQLITE: Final[str] = "sqlite" |
| 168 | +CACHE_TYPE_POSTGRES: Final[str] = "postgres" |
| 169 | +CACHE_TYPE_NOOP: Final[str] = "noop" |
167 | 170 |
|
168 | 171 | # BYOK RAG |
169 | 172 | # Default RAG type for bring-your-own-knowledge RAG configurations, that type |
170 | 173 | # needs to be supported by Llama Stack |
171 | | -DEFAULT_RAG_TYPE = "inline::faiss" |
| 174 | +DEFAULT_RAG_TYPE: Final[str] = "inline::faiss" |
172 | 175 |
|
173 | 176 | # Default sentence transformer model for embedding generation, that type needs |
174 | 177 | # to be supported by Llama Stack and configured properly in providers and |
175 | 178 | # models sections |
176 | | -DEFAULT_EMBEDDING_MODEL = "sentence-transformers/all-mpnet-base-v2" |
| 179 | +DEFAULT_EMBEDDING_MODEL: Final[str] = "sentence-transformers/all-mpnet-base-v2" |
177 | 180 |
|
178 | 181 | # Default embedding vector dimension for the sentence transformer model |
179 | | -DEFAULT_EMBEDDING_DIMENSION = 768 |
| 182 | +DEFAULT_EMBEDDING_DIMENSION: Final[int] = 768 |
180 | 183 |
|
181 | 184 | # quota limiters constants |
182 | | -USER_QUOTA_LIMITER = "user_limiter" |
183 | | -CLUSTER_QUOTA_LIMITER = "cluster_limiter" |
| 185 | +USER_QUOTA_LIMITER: Final[str] = "user_limiter" |
| 186 | +CLUSTER_QUOTA_LIMITER: Final[str] = "cluster_limiter" |
184 | 187 |
|
185 | 188 | # RAG as a tool constants |
186 | | -DEFAULT_RAG_TOOL = "file_search" |
187 | | -TOOL_RAG_MAX_CHUNKS = 10 # retrieved from RAG as a tool |
| 189 | +DEFAULT_RAG_TOOL: Final[str] = "file_search" |
| 190 | +TOOL_RAG_MAX_CHUNKS: Final[int] = 10 # retrieved from RAG as a tool |
188 | 191 |
|
189 | 192 | # Inline RAG constants |
190 | | -BYOK_RAG_MAX_CHUNKS = 10 # retrieved from BYOK RAG |
191 | | -OKP_RAG_MAX_CHUNKS = 5 # retrieved from OKP RAG |
| 193 | +BYOK_RAG_MAX_CHUNKS: Final[int] = 10 # retrieved from BYOK RAG |
| 194 | +OKP_RAG_MAX_CHUNKS: Final[int] = 5 # retrieved from OKP RAG |
192 | 195 |
|
193 | 196 | # Solr OKP constants |
194 | | -SOLR_VECTOR_SEARCH_DEFAULT_K = 5 |
195 | | -SOLR_VECTOR_SEARCH_DEFAULT_SCORE_THRESHOLD = 0.3 |
196 | | -SOLR_VECTOR_SEARCH_DEFAULT_MODE = "hybrid" |
| 197 | +SOLR_VECTOR_SEARCH_DEFAULT_K: Final[int] = 5 |
| 198 | +SOLR_VECTOR_SEARCH_DEFAULT_SCORE_THRESHOLD: Final[float] = 0.3 |
| 199 | +SOLR_VECTOR_SEARCH_DEFAULT_MODE: Final[str] = "hybrid" |
197 | 200 |
|
198 | 201 | # Internal Solr filter always applied to restrict results to chunk documents |
199 | | -SOLR_CHUNK_FILTER_QUERY = "is_chunk:true" |
| 202 | +SOLR_CHUNK_FILTER_QUERY: Final[str] = "is_chunk:true" |
200 | 203 |
|
201 | 204 | # SOLR OKP RAG - default base URL when okp.rhokp_url is unset in configuration |
202 | | -RH_SERVER_OKP_DEFAULT_URL = "http://localhost:8081" |
| 205 | +RH_SERVER_OKP_DEFAULT_URL: Final[str] = "http://localhost:8081" |
203 | 206 |
|
204 | | -SOLR_PROVIDER_ID = "okp_solr" |
| 207 | +SOLR_PROVIDER_ID: Final[str] = "okp_solr" |
205 | 208 |
|
206 | 209 | # Solr default configuration values (can be overridden via environment variables) |
207 | | -SOLR_DEFAULT_VECTOR_STORE_ID = "portal-rag" |
208 | | -SOLR_DEFAULT_VECTOR_FIELD = "chunk_vector" |
209 | | -SOLR_DEFAULT_CONTENT_FIELD = "chunk" |
210 | | -SOLR_DEFAULT_EMBEDDING_MODEL = ( |
| 210 | +SOLR_DEFAULT_VECTOR_STORE_ID: Final[str] = "portal-rag" |
| 211 | +SOLR_DEFAULT_VECTOR_FIELD: Final[str] = "chunk_vector" |
| 212 | +SOLR_DEFAULT_CONTENT_FIELD: Final[str] = "chunk" |
| 213 | +SOLR_DEFAULT_EMBEDDING_MODEL: Final[str] = ( |
211 | 214 | "sentence-transformers/ibm-granite/granite-embedding-30m-english" |
212 | 215 | ) |
213 | | -SOLR_DEFAULT_EMBEDDING_DIMENSION = 384 |
| 216 | +SOLR_DEFAULT_EMBEDDING_DIMENSION: Final[int] = 384 |
214 | 217 |
|
215 | 218 | # Default score multiplier for BYOK RAG vector stores |
216 | 219 | DEFAULT_SCORE_MULTIPLIER = 1.0 |
217 | 220 |
|
218 | 221 | # Special RAG ID that activates the OKP provider when listed in rag.inline or rag.tool |
219 | | -OKP_RAG_ID = "okp" |
| 222 | +OKP_RAG_ID: Final[str] = "okp" |
220 | 223 |
|
221 | 224 | # Logging configuration constants |
222 | 225 | # Environment variable name for configurable log level |
223 | | -LIGHTSPEED_STACK_LOG_LEVEL_ENV_VAR = "LIGHTSPEED_STACK_LOG_LEVEL" |
| 226 | +LIGHTSPEED_STACK_LOG_LEVEL_ENV_VAR: Final[str] = "LIGHTSPEED_STACK_LOG_LEVEL" |
224 | 227 | # Default log level when environment variable is not set |
225 | | -DEFAULT_LOG_LEVEL = "INFO" |
| 228 | +DEFAULT_LOG_LEVEL: Final[str] = "INFO" |
226 | 229 | # Default log format for plain-text logging in non-TTY environments |
227 | | -DEFAULT_LOG_FORMAT = "%(asctime)s %(levelname)-8s %(name)s:%(lineno)d %(message)s" |
| 230 | +DEFAULT_LOG_FORMAT: Final[str] = ( |
| 231 | + "%(asctime)s %(levelname)-8s %(name)s:%(lineno)d %(message)s" |
| 232 | +) |
228 | 233 | # Environment variable to force StreamHandler instead of RichHandler |
229 | 234 | # Set to any non-empty value to disable RichHandler |
230 | | -LIGHTSPEED_STACK_DISABLE_RICH_HANDLER_ENV_VAR = "LIGHTSPEED_STACK_DISABLE_RICH_HANDLER" |
| 235 | +LIGHTSPEED_STACK_DISABLE_RICH_HANDLER_ENV_VAR: Final[str] = ( |
| 236 | + "LIGHTSPEED_STACK_DISABLE_RICH_HANDLER" |
| 237 | +) |
231 | 238 |
|
232 | | -DEFAULT_VIOLATION_MESSAGE = "I cannot process this request due to policy restrictions." |
| 239 | +DEFAULT_VIOLATION_MESSAGE: Final[str] = ( |
| 240 | + "I cannot process this request due to policy restrictions." |
| 241 | +) |
233 | 242 |
|
234 | 243 | # Input size limits for API request validation |
235 | 244 | # Maximum character length for the question field in /v1/infer requests (32 KiB) |
236 | | -RLSAPI_V1_QUESTION_MAX_LENGTH = 32_768 |
| 245 | +RLSAPI_V1_QUESTION_MAX_LENGTH: Final[int] = 32_768 |
237 | 246 | # Maximum character length for the serialized /v1/responses request body (64 KiB) |
238 | | -RESPONSES_REQUEST_MAX_SIZE = 65_536 |
| 247 | +RESPONSES_REQUEST_MAX_SIZE: Final[int] = 65_536 |
0 commit comments