mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-09 15:52:38 +02:00
Merge branch 'dev_tool_selection' of https://gitlab.deepwisdomai.com/agents/data_agents_opt into dev_tool_selection
This commit is contained in:
commit
ad592b9501
2 changed files with 26 additions and 15 deletions
|
|
@ -160,12 +160,6 @@ class ExecutePyCode(ExecuteCode, Action):
|
|||
|
||||
return code, language
|
||||
|
||||
def save_notebook(self, path: str):
|
||||
path = Path(path)
|
||||
print(path)
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
nbformat.write(self.nb, path)
|
||||
|
||||
async def run(self, code: Union[str, Dict, Message], language: str = "python") -> Tuple[str, bool]:
|
||||
code, language = self._process_code(code, language)
|
||||
|
||||
|
|
|
|||
|
|
@ -245,7 +245,7 @@ class MLEngineer(Role):
|
|||
async def _reflect(self):
|
||||
context = self.get_memories()
|
||||
context = "\n".join([str(msg) for msg in context])
|
||||
|
||||
|
||||
reflection = await Reflect().run(context=context)
|
||||
self.working_memory.add(Message(content=reflection, role="assistant"))
|
||||
self.working_memory.add(Message(content=Reflect.REWRITE_PLAN_INSTRUCTION, role="user"))
|
||||
|
|
@ -274,12 +274,30 @@ class MLEngineer(Role):
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# requirement = "Run data analysis on sklearn Iris dataset, include a plot"
|
||||
# requirement = "Run data analysis on sklearn Diabetes dataset, include a plot"
|
||||
# requirement = "Run data analysis on sklearn Wine recognition dataset, include a plot, and train a model to predict wine class (20% as validation), and show validation accuracy"
|
||||
# requirement = "Run data analysis on sklearn Wisconsin Breast Cancer dataset, include a plot, train a model to predict targets (20% as validation), and show validation accuracy"
|
||||
# requirement = "Run EDA and visualization on this dataset, train a model to predict survival, report metrics on validation set (20%), dataset: workspace/titanic/train.csv"
|
||||
|
||||
# requirement = "Perform data analysis on the provided data. Train a model to predict the target variable Survived. Include data preprocessing, feature engineering, and modeling in your pipeline. The metric is accuracy."
|
||||
|
||||
# data_path = f"{DATA_PATH}/titanic"
|
||||
# requirement = f"This is a titanic passenger survival dataset, your goal is to predict passenger survival outcome. The target column is Survived. Perform data analysis, data preprocessing, feature engineering, and modeling to predict the target. Report accuracy on the eval data. Train data path: '{data_path}/split_train.csv', eval data path: '{data_path}/split_eval.csv'."
|
||||
# requirement = f"Run data analysis on sklearn Wine recognition dataset, include a plot, and train a model to predict wine class (20% as validation), and show validation accuracy"
|
||||
# data_path = f"{DATA_PATH}/icr-identify-age-related-conditions"
|
||||
# requirement = f"This is a medical dataset with over fifty anonymized health characteristics linked to three age-related conditions. Your goal is to predict whether a subject has or has not been diagnosed with one of these conditions.The target column is Class. Perform data analysis, data preprocessing, feature engineering, and modeling to predict the target. Report f1 score on the eval data. Train data path: {data_path}/split_train.csv, eval data path: {data_path}/split_eval.csv."
|
||||
|
||||
# data_path = f"{DATA_PATH}/santander-customer-transaction-prediction"
|
||||
# requirement = f"This is a customers financial dataset. Your goal is to predict which customers will make a specific transaction in the future. The target column is target. Perform data analysis, data preprocessing, feature engineering, and modeling to predict the target. Report F1 Score on the eval data. Train data path: '{data_path}/split_train.csv', eval data path: '{data_path}/split_eval.csv' ."
|
||||
|
||||
data_path = f"{DATA_PATH}/house-prices-advanced-regression-techniques"
|
||||
requirement = f"This is a house price dataset, your goal is to predict the sale price of a property based on its features. The target column is SalePrice. Perform data analysis, data preprocessing, feature engineering, and modeling to predict the target. Report RMSE between the logarithm of the predicted value and the logarithm of the observed sales price on the eval data. Train data path: '{data_path}/split_train.csv', eval data path: '{data_path}/split_eval.csv'."
|
||||
|
||||
save_dir = ""
|
||||
# save_dir = DATA_PATH / "save" / "2023-12-14_16-58-03"
|
||||
|
||||
|
||||
# save_dir = DATA_PATH / "output" / "2023-12-14_20-40-34"
|
||||
|
||||
def load_history(save_dir: str = save_dir):
|
||||
"""
|
||||
|
|
@ -293,7 +311,7 @@ if __name__ == "__main__":
|
|||
"""
|
||||
|
||||
plan_path = Path(save_dir) / "plan.json"
|
||||
nb_path = Path(save_dir) / "history_nb.ipynb"
|
||||
nb_path = Path(save_dir) / "history_nb" / "code.ipynb"
|
||||
plan = json.load(open(plan_path, "r", encoding="utf-8"))
|
||||
nb = nbformat.read(open(nb_path, "r", encoding="utf-8"), as_version=nbformat.NO_CONVERT)
|
||||
return plan, nb
|
||||
|
|
@ -310,10 +328,9 @@ if __name__ == "__main__":
|
|||
Returns:
|
||||
Path: The path to the saved history directory.
|
||||
"""
|
||||
# save_path = Path(save_dir) if save_dir else DATA_PATH / "save" / datetime.now().strftime(
|
||||
# '%Y-%m-%d_%H-%M-%S')
|
||||
save_path = DATA_PATH / "save" / datetime.now().strftime(
|
||||
'%Y-%m-%d_%H-%M-%S')
|
||||
record_time = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
|
||||
save_path = DATA_PATH / "output" / f"{record_time}"
|
||||
|
||||
# overwrite exist trajectory
|
||||
save_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
|
@ -322,7 +339,7 @@ if __name__ == "__main__":
|
|||
with open(save_path / "plan.json", "w", encoding="utf-8") as plan_file:
|
||||
json.dump(plan, plan_file, indent=4, ensure_ascii=False)
|
||||
|
||||
role.execute_code.save_notebook(path=save_path / "history_nb.ipynb")
|
||||
save_code_file(name=Path(record_time) / "history_nb", code_context=role.execute_code.nb, file_format="ipynb")
|
||||
return save_path
|
||||
|
||||
|
||||
|
|
@ -344,7 +361,7 @@ if __name__ == "__main__":
|
|||
role = MLEngineer(goal=requirement, auto_run=auto_run)
|
||||
role.plan = Plan(**plan)
|
||||
role.execute_code = ExecutePyCode(nb)
|
||||
|
||||
|
||||
else:
|
||||
logger.info("Run from scratch")
|
||||
role = MLEngineer(goal=requirement, auto_run=auto_run)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue