Skip to content

Commit 91469b5

Browse files
committed
refactor: centralize endpoint path strings into constants
Move hardcoded endpoint_path string literals from individual endpoint handlers into shared Final[str] constants in constants.py. This makes metric labeling paths consistent and easier to maintain across infer, query, streaming_query, and responses endpoints. Signed-off-by: Major Hayden <major@redhat.com>
1 parent 35216ab commit 91469b5

5 files changed

Lines changed: 16 additions & 6 deletions

File tree

src/app/endpoints/query.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from authorization.middleware import authorize
2323
from client import AsyncLlamaStackClientHolder
2424
from configuration import configuration
25+
from constants import ENDPOINT_PATH_QUERY
2526
from log import get_logger
2627
from models.common.responses.responses_api_params import ResponsesApiParams
2728
from models.config import Action
@@ -170,7 +171,7 @@ async def query_endpoint_handler(
170171

171172
# Moderation input is the raw user content (query + attachments) without injected RAG
172173
# context, to avoid false positives from retrieved document content.
173-
endpoint_path = "/v1/query"
174+
endpoint_path = ENDPOINT_PATH_QUERY
174175
moderation_input = prepare_input(query_request)
175176
moderation_result = await run_shield_moderation(
176177
client, moderation_input, endpoint_path, query_request.shield_ids

src/app/endpoints/responses.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from authorization.middleware import authorize
3737
from client import AsyncLlamaStackClientHolder
3838
from configuration import configuration
39-
from constants import SUBSTITUTED_INSTRUCTIONS_PLACEHOLDER
39+
from constants import ENDPOINT_PATH_RESPONSES, SUBSTITUTED_INSTRUCTIONS_PLACEHOLDER
4040
from log import get_logger
4141
from models.common.responses.responses_api_params import ResponsesApiParams
4242
from models.common.responses.responses_context import ResponsesContext
@@ -329,7 +329,7 @@ async def responses_endpoint_handler(
329329
)
330330
attachments_text = extract_attachments_text(original_request.input)
331331

332-
endpoint_path = "/v1/responses"
332+
endpoint_path = ENDPOINT_PATH_RESPONSES
333333
moderation_result = await run_shield_moderation(
334334
client,
335335
input_text + "\n\n" + attachments_text,

src/app/endpoints/rlsapi_v1.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from authorization.middleware import authorize
2323
from client import AsyncLlamaStackClientHolder
2424
from configuration import configuration
25+
from constants import ENDPOINT_PATH_INFER
2526
from log import get_logger
2627
from metrics import recording
2728
from models.config import Action
@@ -241,7 +242,7 @@ async def retrieve_simple_response(
241242
instructions: str,
242243
tools: Optional[list[Any]] = None,
243244
model_id: Optional[str] = None,
244-
endpoint_path: str = "/v1/infer",
245+
endpoint_path: str = ENDPOINT_PATH_INFER,
245246
) -> str:
246247
"""Retrieve a simple response from the LLM for a stateless query.
247248
@@ -678,7 +679,7 @@ async def infer_endpoint( # pylint: disable=R0914
678679
if quota_id is not None:
679680
check_tokens_available(configuration.quota_limiters, quota_id)
680681

681-
endpoint_path = "/v1/infer"
682+
endpoint_path = ENDPOINT_PATH_INFER
682683

683684
request_id = get_suid()
684685

src/app/endpoints/streaming_query.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from client import AsyncLlamaStackClientHolder
4848
from configuration import configuration
4949
from constants import (
50+
ENDPOINT_PATH_STREAMING_QUERY,
5051
INTERRUPTED_RESPONSE_MESSAGE,
5152
LLM_TOKEN_EVENT,
5253
LLM_TOOL_CALL_EVENT,
@@ -227,7 +228,7 @@ async def streaming_query_endpoint_handler( # pylint: disable=too-many-locals
227228
# Moderation input is the raw user content (query + attachments) without injected RAG
228229
# context, to avoid false positives from retrieved document content.
229230
moderation_input = prepare_input(query_request)
230-
endpoint_path = "/v1/streaming_query"
231+
endpoint_path = ENDPOINT_PATH_STREAMING_QUERY
231232
moderation_result = await run_shield_moderation(
232233
client, moderation_input, endpoint_path, query_request.shield_ids
233234
)

src/constants.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,13 @@
244244
# system prompt for the client's instructions. Avoids leaking the actual
245245
# server prompt back to the client.
246246
SUBSTITUTED_INSTRUCTIONS_PLACEHOLDER: Final[str] = "<server prompt applied>"
247+
248+
# API endpoint path constants used for metric labeling across endpoint handlers.
249+
ENDPOINT_PATH_INFER: Final[str] = "/v1/infer"
250+
ENDPOINT_PATH_QUERY: Final[str] = "/v1/query"
251+
ENDPOINT_PATH_STREAMING_QUERY: Final[str] = "/v1/streaming_query"
252+
ENDPOINT_PATH_RESPONSES: Final[str] = "/v1/responses"
253+
247254
# Input size limits for API request validation
248255
# Maximum character length for the question field in /v1/infer requests (32 KiB)
249256
RLSAPI_V1_QUESTION_MAX_LENGTH: Final[int] = 32_768

0 commit comments

Comments
 (0)