Skip to content

Commit 54d72f8

Browse files
📝 Add docstrings to camand/feat_choose_summarize
Docstrings generation was requested by @camilleAND. * #282 (comment) The following files were modified: * `src/backend/chat/tools/document_summarize.py`
1 parent dfb7fb8 commit 54d72f8

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/backend/chat/tools/document_summarize.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,26 @@ async def document_summarize( # pylint: disable=too-many-locals, too-many-state
5858
doc_index: int | None = None,
5959
) -> ToolReturn:
6060
"""
61-
Generate a complete, ready-to-use summary of the documents in context
62-
(do not request the documents to the user).
63-
Return this summary directly to the user WITHOUT any modification,
64-
or additional summarization.
65-
The summary is already optimized and MUST be presented as-is in the final response
66-
or translated preserving the information.
67-
68-
Instructions are optional but should reflect the user's request.
69-
70-
Examples:
71-
"Summarize this doc in 2 paragraphs" -> instructions = "summary in 2 paragraphs", doc_index=None
72-
"Summarize this doc in English" -> instructions = "In English", doc_index=None
73-
"Summarize this doc" -> instructions = "" (default), doc_index=None
74-
"Summarize the last document" -> instructions = "", doc_index=-1
75-
"Summarize the first document" -> instructions = "", doc_index=0
76-
77-
Args:
78-
instructions (str | None): The instructions the user gave to use for the summarization
79-
doc_index (int | None): The index of the document to summarize (e.g. 0 for first, -1 for last).
80-
If None, summarizes all text documents found.
61+
Produce a final, user-ready summary for one or more text documents from the conversation.
62+
63+
Builds per-chunk summaries for the selected documents, synthesizes them into a single coherent
64+
markdown-formatted summary that is intended to be returned to the user verbatim.
65+
66+
Parameters:
67+
instructions (str | None): Optional user instructions to guide the summary (e.g., length,
68+
language, style). When omitted, a default hint is used.
69+
doc_index (int | None): If provided, summarize only the document at this index (0-based;
70+
negative indices allowed, e.g. -1 for the last document). If `None`, all text documents
71+
found in the conversation are summarized.
72+
73+
Returns:
74+
str: The final synthesized summary formatted in Markdown.
75+
76+
Raises:
77+
ModelCannotRetry: If no text documents are found in the conversation or on unexpected errors
78+
that should stop processing and be reported to the user.
79+
ModelRetry: For retryable errors such as an out-of-range `doc_index`, errors during chunk
80+
processing, merge-generation failures, or when the summarization produces an empty result.
8181
"""
8282
try:
8383
instructions_hint = (
@@ -202,4 +202,4 @@ async def summarize_chunk_with_semaphore(idx, chunk, total_chunks):
202202
raise ModelCannotRetry(
203203
f"An unexpected error occurred during document summarization: {type(exc).__name__}. "
204204
"You must explain this to the user and not try to answer based on your knowledge."
205-
) from exc
205+
) from exc

0 commit comments

Comments
 (0)