docs: document how to add a new text-generation task in CONTRIBUTING.md - #2404
docs: document how to add a new text-generation task in CONTRIBUTING.md#2404maowiz wants to merge 1 commit into
Conversation
Documents the current TextGenerationTask architecture in nemo_retriever/models/llm/tasks/: subclassing, optional parse and preflight hooks, construction-time validation, registration, and testing. Addresses the intent of NVIDIA#16 under the current codebase and complements NVIDIA#2395. Signed-off-by: Muhammad Maowiz Saleem <maowizsaleem009@gmail.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Greptile SummaryThis docs-only PR adds an "Adding a New Text-Generation Task" section to
|
| Filename | Overview |
|---|---|
| CONTRIBUTING.md | Adds an 'Adding a New Text-Generation Task' section accurately describing the task architecture, with one minor inaccuracy: the docs claim required_inputs is enforced by the lifecycle when it is actually only a convention enforced within each build_request implementation. |
Sequence Diagram
sequenceDiagram
participant Caller
participant invoke as TextGenerationTask.invoke
participant preflight as _preflight_error (optional hook)
participant build as build_request (required)
participant client as TextCompletionClient
participant parse as parse (optional hook)
Caller->>invoke: "invoke(client, **inputs)"
invoke->>preflight: "_preflight_error(**inputs)"
preflight-->>invoke: None or error_code
alt error_code returned
invoke-->>Caller: "raise GenerationTaskError(phase=request)"
end
invoke->>build: "build_request(**inputs)"
alt build_request raises
invoke-->>Caller: "raise GenerationTaskError(phase=request)"
end
build-->>invoke: GenerationRequest
invoke->>client: client.complete(messages, ...)
alt transport error
invoke-->>Caller: "raise GenerationTaskError(phase=transport)"
end
alt unsupported response
invoke-->>Caller: "raise GenerationTaskError(phase=response)"
end
client-->>invoke: (raw_text, latency_s)
invoke->>parse: parse(raw_text)
alt parse raises
invoke-->>Caller: "raise GenerationTaskError(phase=parse)"
end
parse-->>invoke: text
alt empty text
invoke-->>Caller: "raise GenerationTaskError(phase=response, code=empty_output_error)"
end
invoke-->>Caller: GeneratedTextResult(text, latency_s, model)
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
CONTRIBUTING.md:316-320
**`required_inputs` is not validated by the lifecycle**
The inline comment says the attribute is "validated by the lifecycle", and the Design rules section further states "everything `build_request` consumes must be listed in `required_inputs`" as something the lifecycle enforces. Neither claim is accurate. Examining `TextGenerationTask.invoke` in `base.py`, the method never reads `self.required_inputs` — no check against the caller-provided `inputs` is performed. What the lifecycle *does* do is wrap any exception thrown by `build_request` into a `request`-phase `GenerationTaskError`, so a missing key will still surface as an error, but that happens because the subclass implementation raises (e.g. a `KeyError`), not because the framework inspects `required_inputs`. A developer who reads this doc may believe listing a name there is sufficient for validation and skip writing explicit checks in `build_request` or `_preflight_error` — which would produce only a generic `request_error` message instead of a useful one.
Reviews (1): Last reviewed commit: "docs: add CONTRIBUTING guide for creatin..." | Re-trigger Greptile
| # Logical inputs callers must provide (validated by the lifecycle). | ||
| required_inputs = ("document", "focus") | ||
|
|
||
| # Override sampling defaults only when your task needs different ones. | ||
| _default_sampling = {"temperature": 0.2, "top_p": None, "max_tokens": 1024} |
There was a problem hiding this comment.
required_inputs is not validated by the lifecycle
The inline comment says the attribute is "validated by the lifecycle", and the Design rules section further states "everything build_request consumes must be listed in required_inputs" as something the lifecycle enforces. Neither claim is accurate. Examining TextGenerationTask.invoke in base.py, the method never reads self.required_inputs — no check against the caller-provided inputs is performed. What the lifecycle does do is wrap any exception thrown by build_request into a request-phase GenerationTaskError, so a missing key will still surface as an error, but that happens because the subclass implementation raises (e.g. a KeyError), not because the framework inspects required_inputs. A developer who reads this doc may believe listing a name there is sufficient for validation and skip writing explicit checks in build_request or _preflight_error — which would produce only a generic request_error message instead of a useful one.
Prompt To Fix With AI
This is a comment left during a code review.
Path: CONTRIBUTING.md
Line: 316-320
Comment:
**`required_inputs` is not validated by the lifecycle**
The inline comment says the attribute is "validated by the lifecycle", and the Design rules section further states "everything `build_request` consumes must be listed in `required_inputs`" as something the lifecycle enforces. Neither claim is accurate. Examining `TextGenerationTask.invoke` in `base.py`, the method never reads `self.required_inputs` — no check against the caller-provided `inputs` is performed. What the lifecycle *does* do is wrap any exception thrown by `build_request` into a `request`-phase `GenerationTaskError`, so a missing key will still surface as an error, but that happens because the subclass implementation raises (e.g. a `KeyError`), not because the framework inspects `required_inputs`. A developer who reads this doc may believe listing a name there is sufficient for validation and skip writing explicit checks in `build_request` or `_preflight_error` — which would produce only a generic `request_error` message instead of a useful one.
How can I resolve this? If you propose a fix, please make it concise.
Description
The "Adding a New Stage or Module" section of CONTRIBUTING.md is still a TODO, and #16 (document how to add a new task) predates the current architecture. This PR adds an "Adding a New Text-Generation Task" section documenting the task system that exists on
maintoday, innemo_retriever/src/nemo_retriever/models/llm/tasks/:TextGenerationTask, withbuild_requestas the single required methodparse/_preflight_errorhooks and the strictinvokelifecycle withGenerationTaskErrorphases (request/transport/response/parse)GenericPromptTasktasks/__init__.pynemo_retriever/tests/test_generation_tasks.pyEverything documented was verified against the modules on
main. The Table of Contents is updated to match.Addresses the intent of #16 under the current architecture, and complements the CONTRIBUTING.md refresh tracked in #2395.
Checklist
🤖 Generated with Claude Code