|
| 1 | +from pathlib import Path |
1 | 2 | from typing import Any, Dict, List, Optional, Tuple |
2 | 3 |
|
3 | 4 | from pydantic import BaseModel, Field |
4 | 5 |
|
| 6 | +from rdagent.components.coder.data_science.conf import get_ds_env |
5 | 7 | from rdagent.components.coder.data_science.ensemble.exp import EnsembleTask |
6 | 8 | from rdagent.components.coder.data_science.feature.exp import FeatureTask |
7 | 9 | from rdagent.components.coder.data_science.model.exp import ModelTask |
8 | 10 | from rdagent.components.coder.data_science.pipeline.exp import PipelineTask |
9 | 11 | from rdagent.components.coder.data_science.raw_data_loader.exp import DataLoaderTask |
10 | 12 | from rdagent.components.coder.data_science.workflow.exp import WorkflowTask |
| 13 | +from rdagent.core.experiment import FBWorkspace |
11 | 14 | from rdagent.utils.agent.tpl import T |
12 | 15 |
|
13 | 16 | _COMPONENT_META: Dict[str, Dict[str, Any]] = { |
@@ -86,3 +89,20 @@ class CodingSketch(BaseModel): |
86 | 89 | "The content **must** be formatted using Markdown, with logical sections, key decision points, or implementation steps clearly organized by level-3 headings (i.e., `###`). " |
87 | 90 | "This field should provide sufficient detail for a developer to understand the implementation flow, algorithms, data handling, and key logic points without ambiguity." |
88 | 91 | ) |
| 92 | + |
| 93 | + |
| 94 | +def get_packages(self, pkgs: list[str] | None = None) -> str: |
| 95 | + # TODO: add it into base class. Environment should(i.e. `DSDockerConf`) should be part of the scenario class. |
| 96 | + """Return runtime environment information.""" |
| 97 | + # Reuse package list cached during Draft stage when available. |
| 98 | + if pkgs is None and hasattr(self, "required_packages"): |
| 99 | + pkgs = getattr(self, "required_packages") # type: ignore[arg-type] |
| 100 | + |
| 101 | + env = get_ds_env() |
| 102 | + implementation = FBWorkspace() |
| 103 | + fname = "package_info.py" |
| 104 | + implementation.inject_files(**{fname: (Path(__file__).absolute().resolve().parent / "package_info.py").read_text()}) |
| 105 | + |
| 106 | + pkg_args = " ".join(pkgs) if pkgs else "" |
| 107 | + stdout = implementation.execute(env=env, entry=f"python {fname} {pkg_args}") |
| 108 | + return stdout |
0 commit comments