Postprocessor Manager
📘 Postprocessor and PostprocessorManager Documentation¶
The Postprocessor and PostprocessorManager classes are responsible for refining and modifying responses generated by the orchestrator. Postprocessors are modular components that apply specific transformations or enhancements to the generated text. The PostprocessorManager orchestrates the execution of these postprocessors, ensuring they are applied.
🔑 Postprocessor Overview¶
The Postprocessor is an abstract class that defines the structure and behavior of individual postprocessors. Each postprocessor must implement the following methods to be compatible with the PostprocessorManager:
run: Executes the postprocessing logic on the response.apply_postprocessing_to_response: Applies the postprocessing changes to the response if necessary.remove_from_text: Removes any postprocessing artifacts from the text, ensuring clean input for subsequent LLM rounds.
Postprocessor Class Definition:¶
🔑 PostprocessorManager Overview¶
The PostprocessorManager is responsible for managing and executing postprocessors. It ensures that all configured postprocessors are run in parallel and their results are applied sequentially to the response. Additionally, it provides functionality to remove postprocessing artifacts from text when necessary.
🛠️ Key Functionalities of PostprocessorManager¶
1. Postprocessor Management¶
-
add_postprocessor(postprocessor: Postprocessor)
Adds a postprocessor to the manager's collection.
-
get_postprocessors(name: str) -> list[Postprocessor]
Retrieves the list of all registered postprocessors.
2. Postprocessor Execution¶
run_postprocessors(loop_response: LanguageModelStreamResponse)
Executes all registered postprocessors asynchronously. Results are applied sequentially to the response if modifications are detected.
3. Text Cleanup¶
remove_from_text(text: str) -> str
Iterates through all registered postprocessors and removes their artifacts from the text. This ensures that postprocessing-generated content does not interfere with subsequent LLM rounds.
🛠️ Summary of Responsibilities¶
- Postprocessor:
- Defines the structure and behavior of individual postprocessors.
-
Implements methods for running, applying, and removing postprocessing logic.
-
PostprocessorManager:
- Manages a collection of postprocessors.
- Executes postprocessors in parallel and applies their results sequentially.
- Provides functionality to clean up postprocessing artifacts from text.
This documentation provides a concise and focused explanation of the Postprocessor and PostprocessorManager classes, ensuring developers can implement and manage postprocessing logic effectively. Let me know if further refinements are needed!