-
Notifications
You must be signed in to change notification settings - Fork 55
Add Task pipeline #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pan-x-c
merged 9 commits into
agentscope-ai:feature/data_processor
from
pan-x-c:feature/task_pipeline
Aug 18, 2025
Merged
Add Task pipeline #189
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
99968f1
add task pipeline
pan-x-c 26db7d9
add task pipeline test
pan-x-c 89b7595
fix tests
pan-x-c 06b099b
fix precommit
pan-x-c 27a4eda
fix tests
pan-x-c af2f3eb
fix tests
pan-x-c eaf0ae2
fix explorer
pan-x-c c6858df
fix comments
pan-x-c bb1b27d
fix comments
pan-x-c File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| from trinity.buffer.pipelines.experience_pipeline import ExperiencePipeline | ||
| from trinity.buffer.pipelines.task_pipeline import ( | ||
| TaskPipeline, | ||
| check_and_run_task_pipeline, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "ExperiencePipeline", | ||
| "TaskPipeline", | ||
| "check_and_run_task_pipeline", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| from typing import Any, Dict | ||
|
|
||
| from trinity.common.config import Config, OperatorConfig, TaskPipelineConfig | ||
| from trinity.utils.log import get_logger | ||
|
|
||
|
|
||
| def check_and_run_task_pipeline(config: Config) -> Dict: | ||
| if not (config.mode == "explore" or config.mode == "both"): | ||
| # task pipeline is only available when using Explorer | ||
| return {} | ||
| if config.data_processor.task_pipeline is None: | ||
| return {} | ||
|
|
||
| task_pipeline = TaskPipeline(config) | ||
| try: | ||
| return task_pipeline.process() | ||
| except Exception as e: | ||
| raise RuntimeError(f"Task pipeline failed: {e}") | ||
| finally: | ||
| task_pipeline.close() | ||
|
|
||
|
|
||
| class TaskPipeline: | ||
| """ | ||
| A class to process task datasets through DataJuicer. | ||
| """ | ||
|
|
||
| def __init__(self, config: Config): | ||
| self.logger = get_logger(__name__) | ||
| from trinity.service.data_juicer.client import DataJuicerClient | ||
|
|
||
| self.client = DataJuicerClient(config.service.data_juicer) # type: ignore [arg-type] | ||
| self.pipeline_config = config.data_processor.task_pipeline | ||
|
|
||
| def convert_pipeline_config(self, pipeline_config: TaskPipelineConfig) -> Dict[str, Any]: | ||
| """ | ||
| Convert the TaskPipelineConfig to a format suitable for DataJuicer. | ||
| """ | ||
|
|
||
| def _convert_operator(operator: OperatorConfig) -> Dict: | ||
| return {operator.name: {key: value for key, value in operator.args.items()}} | ||
|
|
||
| if pipeline_config.output.path is None: | ||
| raise ValueError("When using task pipeline, taskset.path must be set.") | ||
|
|
||
| converted_config = { | ||
| "pipeline_type": "task", | ||
| "operators": [_convert_operator(op) for op in pipeline_config.operators], | ||
| "np": pipeline_config.num_process, | ||
| "config_path": pipeline_config.config_path, | ||
| "inputs": [path for path in pipeline_config.inputs], | ||
| "target_fields": pipeline_config.target_fields, | ||
| "output_dir": pipeline_config.output.path, | ||
| } | ||
| return converted_config | ||
|
|
||
| def process(self) -> Dict[str, Any]: | ||
| """ | ||
| Process the task datasets using DataJuicer. | ||
|
|
||
| Returns: | ||
| Dict[str, Any]: Metrics for logging. | ||
| """ | ||
| # Convert the pipeline configuration | ||
| converted_config = self.convert_pipeline_config(self.pipeline_config) # type: ignore [arg-type] | ||
| self.client.initialize(converted_config) | ||
| self.logger.info("Starting task processing...") | ||
| metrics = self.client.process_task() | ||
| self.logger.info("Task processing completed.") | ||
| return metrics | ||
|
|
||
| def close(self): | ||
| self.client.close() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.