Skip to content

Commit ab729a0

Browse files
authored
Merge pull request #1444 from tisnik/lcore-1608-improve-docstrings-in-lcore-repository
LCORE-1608: improve docstrings in LCORE repository
2 parents 2edd0f7 + 6b3be0b commit ab729a0

File tree

109 files changed

+763
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+763
-7
lines changed

dev-tools/mcp-mock-server/test_mock_mcp_server.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
Pytest tests for the MCP Mock Server.
1+
"""Pytest tests for the MCP Mock Server.
32
43
This test suite verifies the mock server functionality without requiring
54
the full Lightspeed Stack infrastructure.

src/app/database.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,17 @@ def _create_sqlite_engine(config: SQLiteDatabaseConfiguration, **kwargs: Any) ->
7272
"""Create SQLite database engine.
7373
7474
Parameters:
75+
----------
7576
config (SQLiteDatabaseConfiguration): Configuration containing
7677
`db_path` for the SQLite file.
7778
**kwargs: Additional keyword arguments forwarded to SQLAlchemy's create_engine.
7879
7980
Returns:
81+
-------
8082
Engine: A SQLAlchemy Engine bound to the specified SQLite database file.
8183
8284
Raises:
85+
------
8386
FileNotFoundError: If the parent directory of `config.db_path` does not exist.
8487
RuntimeError: If engine creation fails.
8588
"""
@@ -107,14 +110,17 @@ def _create_postgres_engine(
107110
SSL.
108111
109112
Parameters:
113+
----------
110114
config (PostgreSQLDatabaseConfiguration): Connection and database
111115
settings (user, password, host, port, db, ssl/gss options, optional
112116
namespace and ca_cert_path).
113117
114118
Returns:
119+
-------
115120
Engine: A SQLAlchemy Engine connected to the configured PostgreSQL database.
116121
117122
Raises:
123+
------
118124
RuntimeError: If engine creation fails or if creating the specified schema fails.
119125
"""
120126
postgres_url = (

src/app/endpoints/feedback.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,12 @@ def store_feedback(user_id: str, feedback: dict) -> None:
149149
configured local storage directory.
150150
151151
Parameters:
152+
----------
152153
user_id (str): Unique identifier of the user submitting feedback.
153154
feedback (dict): Feedback data to be stored, merged with user ID and timestamp.
154155
155156
Raises:
157+
------
156158
HTTPException: If writing the feedback file fails (HTTP 500).
157159
"""
158160
logger.debug("Storing feedback for user %s", user_id)

src/app/endpoints/query.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,13 @@ async def retrieve_response(
276276
This function processes the prepared request and returns the LLM response.
277277
278278
Parameters:
279+
----------
279280
client: The AsyncLlamaStackClient to use for the request.
280281
responses_params: The Responses API parameters.
281282
moderation_result: The moderation result.
282283
283284
Returns:
285+
-------
284286
TurnSummary: Summary of the LLM response content
285287
"""
286288
response: Optional[OpenAIResponseObject] = None

src/app/endpoints/rags.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,12 @@ def _resolve_rag_id_to_vector_db_id(rag_id: str, byok_rags: list[ByokRag]) -> st
112112
(assuming it is already a llama-stack vector store ID).
113113
114114
Parameters:
115+
----------
115116
rag_id: The user-provided RAG identifier.
116117
byok_rags: List of BYOK RAG config entries.
117118
118119
Returns:
120+
-------
119121
The llama-stack vector_db_id, or the original ID if no mapping found.
120122
"""
121123
for brag in byok_rags:

src/app/endpoints/stream_interrupt.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,17 @@ async def stream_interrupt_endpoint_handler(
4949
"""Interrupt an in-progress streaming query by request identifier.
5050
5151
Parameters:
52+
----------
5253
interrupt_request: Request payload containing the stream request ID.
5354
auth: Auth context tuple resolved from the authentication dependency.
5455
registry: Stream interrupt registry dependency used to cancel streams.
5556
5657
Returns:
58+
-------
5759
StreamingInterruptResponse: Confirmation payload when interruption succeeds.
5860
5961
Raises:
62+
------
6063
HTTPException: If no active stream for the given request ID can be interrupted.
6164
"""
6265
user_id, _, _, _ = auth

src/app/endpoints/streaming_query.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ async def _persist_interrupted_turn(
438438
and updated when ready.
439439
440440
Parameters:
441+
----------
441442
context: The response generator context.
442443
responses_params: The Responses API parameters.
443444
turn_summary: TurnSummary with llm_response already set to the
@@ -507,11 +508,13 @@ def _register_interrupt_callback(
507508
both persist the same turn.
508509
509510
Parameters:
511+
----------
510512
context: The response generator context.
511513
responses_params: The Responses API parameters.
512514
turn_summary: TurnSummary populated during streaming.
513515
514516
Returns:
517+
-------
515518
A mutable list ``[False]`` used as a persist-done guard; the
516519
caller should check ``guard[0]`` before persisting and set
517520
it to ``True`` afterwards.
@@ -877,6 +880,7 @@ def stream_http_error_event(
877880
Args:
878881
error: An AbstractErrorResponse instance representing the error.
879882
media_type: The media type for the response format. Defaults to MEDIA_TYPE_JSON if None.
883+
880884
Returns:
881885
str: A Server-Sent Events (SSE) formatted error message containing
882886
the serialized error details.
@@ -903,9 +907,11 @@ def format_stream_data(d: dict) -> str:
903907
Create a response generator function for Responses API streaming.
904908
905909
Parameters:
910+
----------
906911
d (dict): The data to be formatted as an SSE event.
907912
908913
Returns:
914+
-------
909915
str: The formatted SSE data string.
910916
"""
911917
data = json.dumps(d)
@@ -920,11 +926,13 @@ def stream_start_event(conversation_id: str, request_id: str) -> str:
920926
use the request ID to issue an interrupt if needed.
921927
922928
Parameters:
929+
----------
923930
conversation_id (str): Unique identifier for the conversation.
924931
request_id (str): Unique SUID for this streaming request,
925932
returned to the client for interrupt support.
926933
927934
Returns:
935+
-------
928936
str: SSE-formatted string representing the start event.
929937
"""
930938
return format_stream_data(
@@ -946,9 +954,11 @@ def stream_interrupted_event(request_id: str) -> str:
946954
from an unexpected connection drop.
947955
948956
Parameters:
957+
----------
949958
request_id (str): Unique identifier for the interrupted request.
950959
951960
Returns:
961+
-------
952962
str: SSE-formatted string representing the interrupted event.
953963
"""
954964
return format_stream_data(
@@ -974,12 +984,14 @@ def stream_end_event(
974984
including referenced document metadata and token usage information.
975985
976986
Parameters:
987+
----------
977988
token_usage (TokenCounter): Token usage information.
978989
available_quotas (dict[str, int]): Available quotas for the user.
979990
referenced_documents (list[ReferencedDocument]): List of referenced documents.
980991
media_type (str): The media type for the response format.
981992
982993
Returns:
994+
-------
983995
str: A Server-Sent Events (SSE) formatted string
984996
representing the end of the data stream.
985997
"""

src/app/endpoints/tools.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ def _input_schema_to_parameters(
4343
the flat parameter list format used by the tools endpoint response.
4444
4545
Parameters:
46+
----------
4647
schema: JSON Schema dict with ``properties`` and ``required`` keys,
4748
or ``None`` if the tool has no parameters.
4849
4950
Returns:
51+
-------
5052
A list of parameter dicts, each containing ``name``, ``description``,
5153
``parameter_type``, ``required``, and ``default`` keys.
5254
"""

src/app/routers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def include_routers(app: FastAPI) -> None:
4141
authorized, metrics) are mounted without a version prefix.
4242
4343
Parameters:
44+
----------
4445
app (FastAPI): The FastAPI application to which routers will be attached.
4546
"""
4647
app.include_router(root.router)

src/authentication/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@ def get_auth_dependency(
2424
"""Select the configured authentication dependency interface.
2525
2626
Parameters:
27+
----------
2728
virtual_path (str): Virtual path passed to the authentication
2829
dependency when it is constructed.
2930
3031
Returns:
32+
-------
3133
AuthInterface: An instance implementing AuthInterface for the
3234
configured authentication module.
3335
3436
Raises:
37+
------
3538
ValueError: If the configured authentication module is not supported.
3639
"""
3740
try:

0 commit comments

Comments
 (0)