Skip to content

Commit 302557a

Browse files
committed
LCORE-1891: Use Final types in constants
1 parent d67f84d commit 302557a

1 file changed

Lines changed: 70 additions & 64 deletions

File tree

src/constants.py

Lines changed: 70 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
MINIMAL_SUPPORTED_LLAMA_STACK_VERSION: Final[str] = "0.2.17"
77
MAXIMAL_SUPPORTED_LLAMA_STACK_VERSION: Final[str] = "0.6.0"
88

9-
UNABLE_TO_PROCESS_RESPONSE = "Unable to process this request"
9+
UNABLE_TO_PROCESS_RESPONSE: Final[str] = "Unable to process this request"
1010

1111
# Response stored in the conversation when the user interrupts a streaming request
12-
INTERRUPTED_RESPONSE_MESSAGE = "You interrupted this request."
12+
INTERRUPTED_RESPONSE_MESSAGE: Final[str] = "You interrupted this request."
1313

1414
# Max seconds to wait for topic summary in background task after interrupt persist.
15-
TOPIC_SUMMARY_INTERRUPT_TIMEOUT_SECONDS = 30.0
15+
TOPIC_SUMMARY_INTERRUPT_TIMEOUT_SECONDS: Final[float] = 30.0
1616

1717
# Supported attachment types
1818
ATTACHMENT_TYPES = frozenset(
@@ -34,11 +34,11 @@
3434

3535
# Default system prompt used only when no other system prompt is specified in
3636
# configuration file nor in the query request
37-
DEFAULT_SYSTEM_PROMPT = "You are a helpful assistant"
37+
DEFAULT_SYSTEM_PROMPT: Final[str] = "You are a helpful assistant"
3838

3939
# Default topic summary system prompt used only when no other topic summary system
4040
# prompt is specified in configuration file
41-
DEFAULT_TOPIC_SUMMARY_SYSTEM_PROMPT = """
41+
DEFAULT_TOPIC_SUMMARY_SYSTEM_PROMPT: Final[str] = """
4242
Instructions:
4343
- You are a topic summarizer
4444
- Your job is to extract precise topic summary from user input
@@ -104,18 +104,18 @@
104104
"""
105105

106106
# 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"
107+
DEFAULT_VIRTUAL_PATH: Final[str] = "/ls-access"
108+
DEFAULT_USER_NAME: Final[str] = "lightspeed-user"
109+
DEFAULT_SKIP_USER_ID_CHECK: Final[bool] = True
110+
DEFAULT_USER_UID: Final[str] = "00000000-0000-0000-0000-000"
111111
# 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"
112+
NO_USER_TOKEN: Final[str] = ""
113+
AUTH_MOD_K8S: Final[str] = "k8s"
114+
AUTH_MOD_NOOP: Final[str] = "noop"
115+
AUTH_MOD_NOOP_WITH_TOKEN: Final[str] = "noop-with-token"
116+
AUTH_MOD_APIKEY_TOKEN: Final[str] = "api-key-token"
117+
AUTH_MOD_JWK_TOKEN: Final[str] = "jwk-token"
118+
AUTH_MOD_RH_IDENTITY: Final[str] = "rh-identity"
119119
# Supported authentication modules
120120
SUPPORTED_AUTHENTICATION_MODULES = frozenset(
121121
{
@@ -129,110 +129,116 @@
129129
)
130130
DEFAULT_AUTHENTICATION_MODULE = AUTH_MOD_NOOP
131131
# Maximum allowed size for base64-encoded x-rh-identity header (bytes)
132-
DEFAULT_RH_IDENTITY_MAX_HEADER_SIZE = 8192
132+
DEFAULT_RH_IDENTITY_MAX_HEADER_SIZE: Final[int] = 8192
133133

134134
# Maximum allowed file upload size (bytes) - 100MB default
135135
# 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"
136+
DEFAULT_MAX_FILE_UPLOAD_SIZE: Final[int] = 100 * 1024 * 1024 # 100 MB
137+
DEFAULT_JWT_UID_CLAIM: Final[str] = "user_id"
138+
DEFAULT_JWT_USER_NAME_CLAIM: Final[str] = "username"
139139

140140
# MCP authorization header special values
141-
MCP_AUTH_KUBERNETES = "kubernetes"
142-
MCP_AUTH_CLIENT = "client"
143-
MCP_AUTH_OAUTH = "oauth"
141+
MCP_AUTH_KUBERNETES: Final[str] = "kubernetes"
142+
MCP_AUTH_CLIENT: Final[str] = "client"
143+
MCP_AUTH_OAUTH: Final[str] = "oauth"
144144

145145
# 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"
146+
MEDIA_TYPE_JSON: Final[str] = "application/json"
147+
MEDIA_TYPE_TEXT: Final[str] = "text/plain"
148+
MEDIA_TYPE_EVENT_STREAM: Final[str] = "text/event-stream"
149149

150150
# 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"
151+
LLM_TOKEN_EVENT: Final[str] = "token"
152+
LLM_TOOL_CALL_EVENT: Final[str] = "tool_call"
153+
LLM_TOOL_RESULT_EVENT: Final[str] = "tool_result"
154+
LLM_TURN_COMPLETE_EVENT: Final[str] = "turn_complete"
155155

156156
# PostgreSQL connection constants
157157
# See: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-SSLMODE
158-
POSTGRES_DEFAULT_SSL_MODE = "prefer"
158+
POSTGRES_DEFAULT_SSL_MODE: Final[str] = "prefer"
159159
# See: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-GSSENCMODE
160-
POSTGRES_DEFAULT_GSS_ENCMODE = "prefer"
160+
POSTGRES_DEFAULT_GSS_ENCMODE: Final[str] = "prefer"
161161

162162
# cache constants
163-
CACHE_TYPE_MEMORY = "memory"
164-
CACHE_TYPE_SQLITE = "sqlite"
165-
CACHE_TYPE_POSTGRES = "postgres"
166-
CACHE_TYPE_NOOP = "noop"
163+
CACHE_TYPE_MEMORY: Final[str] = "memory"
164+
CACHE_TYPE_SQLITE: Final[str] = "sqlite"
165+
CACHE_TYPE_POSTGRES: Final[str] = "postgres"
166+
CACHE_TYPE_NOOP: Final[str] = "noop"
167167

168168
# BYOK RAG
169169
# Default RAG type for bring-your-own-knowledge RAG configurations, that type
170170
# needs to be supported by Llama Stack
171-
DEFAULT_RAG_TYPE = "inline::faiss"
171+
DEFAULT_RAG_TYPE: Final[str] = "inline::faiss"
172172

173173
# Default sentence transformer model for embedding generation, that type needs
174174
# to be supported by Llama Stack and configured properly in providers and
175175
# models sections
176-
DEFAULT_EMBEDDING_MODEL = "sentence-transformers/all-mpnet-base-v2"
176+
DEFAULT_EMBEDDING_MODEL: Final[str] = "sentence-transformers/all-mpnet-base-v2"
177177

178178
# Default embedding vector dimension for the sentence transformer model
179-
DEFAULT_EMBEDDING_DIMENSION = 768
179+
DEFAULT_EMBEDDING_DIMENSION: Final[int] = 768
180180

181181
# quota limiters constants
182-
USER_QUOTA_LIMITER = "user_limiter"
183-
CLUSTER_QUOTA_LIMITER = "cluster_limiter"
182+
USER_QUOTA_LIMITER: Final[str] = "user_limiter"
183+
CLUSTER_QUOTA_LIMITER: Final[str] = "cluster_limiter"
184184

185185
# RAG as a tool constants
186-
DEFAULT_RAG_TOOL = "file_search"
187-
TOOL_RAG_MAX_CHUNKS = 10 # retrieved from RAG as a tool
186+
DEFAULT_RAG_TOOL: Final[str] = "file_search"
187+
TOOL_RAG_MAX_CHUNKS: Final[int] = 10 # retrieved from RAG as a tool
188188

189189
# Inline RAG constants
190-
BYOK_RAG_MAX_CHUNKS = 10 # retrieved from BYOK RAG
191-
OKP_RAG_MAX_CHUNKS = 5 # retrieved from OKP RAG
190+
BYOK_RAG_MAX_CHUNKS: Final[int] = 10 # retrieved from BYOK RAG
191+
OKP_RAG_MAX_CHUNKS: Final[int] = 5 # retrieved from OKP RAG
192192

193193
# 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"
194+
SOLR_VECTOR_SEARCH_DEFAULT_K: Final[int] = 5
195+
SOLR_VECTOR_SEARCH_DEFAULT_SCORE_THRESHOLD: Final[float] = 0.3
196+
SOLR_VECTOR_SEARCH_DEFAULT_MODE: Final[str] = "hybrid"
197197

198198
# Internal Solr filter always applied to restrict results to chunk documents
199-
SOLR_CHUNK_FILTER_QUERY = "is_chunk:true"
199+
SOLR_CHUNK_FILTER_QUERY: Final[str] = "is_chunk:true"
200200

201201
# SOLR OKP RAG - default base URL when okp.rhokp_url is unset in configuration
202-
RH_SERVER_OKP_DEFAULT_URL = "http://localhost:8081"
202+
RH_SERVER_OKP_DEFAULT_URL: Final[str] = "http://localhost:8081"
203203

204-
SOLR_PROVIDER_ID = "okp_solr"
204+
SOLR_PROVIDER_ID: Final[str] = "okp_solr"
205205

206206
# 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 = (
207+
SOLR_DEFAULT_VECTOR_STORE_ID: Final[str] = "portal-rag"
208+
SOLR_DEFAULT_VECTOR_FIELD: Final[str] = "chunk_vector"
209+
SOLR_DEFAULT_CONTENT_FIELD: Final[str] = "chunk"
210+
SOLR_DEFAULT_EMBEDDING_MODEL: Final[str] = (
211211
"sentence-transformers/ibm-granite/granite-embedding-30m-english"
212212
)
213-
SOLR_DEFAULT_EMBEDDING_DIMENSION = 384
213+
SOLR_DEFAULT_EMBEDDING_DIMENSION: Final[int] = 384
214214

215215
# Default score multiplier for BYOK RAG vector stores
216216
DEFAULT_SCORE_MULTIPLIER = 1.0
217217

218218
# Special RAG ID that activates the OKP provider when listed in rag.inline or rag.tool
219-
OKP_RAG_ID = "okp"
219+
OKP_RAG_ID: Final[str] = "okp"
220220

221221
# Logging configuration constants
222222
# Environment variable name for configurable log level
223-
LIGHTSPEED_STACK_LOG_LEVEL_ENV_VAR = "LIGHTSPEED_STACK_LOG_LEVEL"
223+
LIGHTSPEED_STACK_LOG_LEVEL_ENV_VAR: Final[str] = "LIGHTSPEED_STACK_LOG_LEVEL"
224224
# Default log level when environment variable is not set
225-
DEFAULT_LOG_LEVEL = "INFO"
225+
DEFAULT_LOG_LEVEL: Final[str] = "INFO"
226226
# 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"
227+
DEFAULT_LOG_FORMAT: Final[str] = (
228+
"%(asctime)s %(levelname)-8s %(name)s:%(lineno)d %(message)s"
229+
)
228230
# Environment variable to force StreamHandler instead of RichHandler
229231
# Set to any non-empty value to disable RichHandler
230-
LIGHTSPEED_STACK_DISABLE_RICH_HANDLER_ENV_VAR = "LIGHTSPEED_STACK_DISABLE_RICH_HANDLER"
232+
LIGHTSPEED_STACK_DISABLE_RICH_HANDLER_ENV_VAR: Final[str] = (
233+
"LIGHTSPEED_STACK_DISABLE_RICH_HANDLER"
234+
)
231235

232-
DEFAULT_VIOLATION_MESSAGE = "I cannot process this request due to policy restrictions."
236+
DEFAULT_VIOLATION_MESSAGE: Final[str] = (
237+
"I cannot process this request due to policy restrictions."
238+
)
233239

234240
# Input size limits for API request validation
235241
# Maximum character length for the question field in /v1/infer requests (32 KiB)
236-
RLSAPI_V1_QUESTION_MAX_LENGTH = 32_768
242+
RLSAPI_V1_QUESTION_MAX_LENGTH: Final[int] = 32_768
237243
# Maximum character length for the serialized /v1/responses request body (64 KiB)
238-
RESPONSES_REQUEST_MAX_SIZE = 65_536
244+
RESPONSES_REQUEST_MAX_SIZE: Final[int] = 65_536

0 commit comments

Comments
 (0)