From 18a17bede099a1f188c0f1e55b0665bc65aec43c Mon Sep 17 00:00:00 2001 From: yzlin Date: Wed, 7 Feb 2024 13:00:31 +0800 Subject: [PATCH 1/3] create ci example folder, mv existing and create new --- examples/{ => ci}/crawl_webpage.py | 0 examples/ci/data_analysis.py | 14 ++++++++++++++ examples/{ => ci}/imitate_webpage.py | 2 +- examples/ci/rm_image_background.py | 15 +++++++++++++++ examples/{ => ci}/sd_tool_usage.py | 0 examples/ci/solve_math_problems.py | 17 +++++++++++++++++ 6 files changed, 47 insertions(+), 1 deletion(-) rename examples/{ => ci}/crawl_webpage.py (100%) create mode 100644 examples/ci/data_analysis.py rename examples/{ => ci}/imitate_webpage.py (92%) create mode 100644 examples/ci/rm_image_background.py rename examples/{ => ci}/sd_tool_usage.py (100%) create mode 100644 examples/ci/solve_math_problems.py diff --git a/examples/crawl_webpage.py b/examples/ci/crawl_webpage.py similarity index 100% rename from examples/crawl_webpage.py rename to examples/ci/crawl_webpage.py diff --git a/examples/ci/data_analysis.py b/examples/ci/data_analysis.py new file mode 100644 index 000000000..8dc4340d4 --- /dev/null +++ b/examples/ci/data_analysis.py @@ -0,0 +1,14 @@ +import asyncio + +from metagpt.roles.ci.code_interpreter import CodeInterpreter + + +async def main(requirement: str = ""): + code_interpreter = CodeInterpreter(use_tools=False) + await code_interpreter.run(requirement) + + +if __name__ == "__main__": + requirement = "Run data analysis on sklearn Iris dataset, include a plot" + + asyncio.run(main(requirement)) diff --git a/examples/imitate_webpage.py b/examples/ci/imitate_webpage.py similarity index 92% rename from examples/imitate_webpage.py rename to examples/ci/imitate_webpage.py index 5075e1e39..6a83d3a33 100644 --- a/examples/imitate_webpage.py +++ b/examples/ci/imitate_webpage.py @@ -15,7 +15,7 @@ Firstly, utilize Selenium and WebDriver for rendering. Secondly, convert image to a webpage including HTML, CSS and JS in one go. Finally, save webpage in a text file. Note: All required dependencies and environments have been fully installed and configured.""" - ci = CodeInterpreter(goal=prompt, use_tools=True) + ci = CodeInterpreter(use_tools=True) await ci.run(prompt) diff --git a/examples/ci/rm_image_background.py b/examples/ci/rm_image_background.py new file mode 100644 index 000000000..83dbbdc77 --- /dev/null +++ b/examples/ci/rm_image_background.py @@ -0,0 +1,15 @@ +import asyncio + +from metagpt.roles.ci.code_interpreter import CodeInterpreter + + +async def main(requirement: str = ""): + code_interpreter = CodeInterpreter(use_tools=False) + await code_interpreter.run(requirement) + + +if __name__ == "__main__": + image_path = "/your/path/to/the/image.jpeg" + save_path = "/your/intended/save/path/for/image_rm_bg.png" + requirement = f"This is a image, you need to use python toolkit rembg to remove the background of the image and save the result. image path:{image_path}; save path:{save_path}." + asyncio.run(main(requirement)) diff --git a/examples/sd_tool_usage.py b/examples/ci/sd_tool_usage.py similarity index 100% rename from examples/sd_tool_usage.py rename to examples/ci/sd_tool_usage.py diff --git a/examples/ci/solve_math_problems.py b/examples/ci/solve_math_problems.py new file mode 100644 index 000000000..5bf06b9d8 --- /dev/null +++ b/examples/ci/solve_math_problems.py @@ -0,0 +1,17 @@ +import asyncio + +from metagpt.roles.ci.code_interpreter import CodeInterpreter + + +async def main(requirement: str = ""): + code_interpreter = CodeInterpreter(use_tools=False, goal=requirement) + await code_interpreter.run(requirement) + + +if __name__ == "__main__": + problem = "At a school, all 60 students play on at least one of three teams: Basketball, Soccer, and Mathletics. 8 students play all three sports, half the students play basketball, and the ratio of the size of the math team to the size of the basketball team to the size of the soccer team is $4:3:2$. How many students at the school play on exactly two teams?" + requirement = ( + f"This is a math problem:{problem}. You can analyze and solve it step by step or use Python code to solve it." + ) + + asyncio.run(main(requirement)) From d29ab799bf7de735a76754e85d662cbbd8e5525e Mon Sep 17 00:00:00 2001 From: yzlin Date: Wed, 7 Feb 2024 15:55:20 +0800 Subject: [PATCH 2/3] change math problems --- examples/ci/solve_math_problems.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/examples/ci/solve_math_problems.py b/examples/ci/solve_math_problems.py index 5bf06b9d8..8c660975b 100644 --- a/examples/ci/solve_math_problems.py +++ b/examples/ci/solve_math_problems.py @@ -4,14 +4,10 @@ from metagpt.roles.ci.code_interpreter import CodeInterpreter async def main(requirement: str = ""): - code_interpreter = CodeInterpreter(use_tools=False, goal=requirement) + code_interpreter = CodeInterpreter(use_tools=False) await code_interpreter.run(requirement) if __name__ == "__main__": - problem = "At a school, all 60 students play on at least one of three teams: Basketball, Soccer, and Mathletics. 8 students play all three sports, half the students play basketball, and the ratio of the size of the math team to the size of the basketball team to the size of the soccer team is $4:3:2$. How many students at the school play on exactly two teams?" - requirement = ( - f"This is a math problem:{problem}. You can analyze and solve it step by step or use Python code to solve it." - ) - + requirement = "Solve this math problem: The greatest common divisor of positive integers m and n is 6. The least common multiple of m and n is 126. What is the least possible value of m + n?" asyncio.run(main(requirement)) From eb1e1b9ef22fe58720dfa71f01b812eecaf32b87 Mon Sep 17 00:00:00 2001 From: yzlin Date: Wed, 7 Feb 2024 21:54:40 +0800 Subject: [PATCH 3/3] mv examples --- examples/ci/{data_analysis.py => data_visualization.py} | 0 examples/{ => ci}/email_summary.py | 0 examples/ci/machine_learning.py | 0 examples/{ => ci}/ml_engineer_with_tools.py | 6 +++--- 4 files changed, 3 insertions(+), 3 deletions(-) rename examples/ci/{data_analysis.py => data_visualization.py} (100%) rename examples/{ => ci}/email_summary.py (100%) create mode 100644 examples/ci/machine_learning.py rename examples/{ => ci}/ml_engineer_with_tools.py (74%) diff --git a/examples/ci/data_analysis.py b/examples/ci/data_visualization.py similarity index 100% rename from examples/ci/data_analysis.py rename to examples/ci/data_visualization.py diff --git a/examples/email_summary.py b/examples/ci/email_summary.py similarity index 100% rename from examples/email_summary.py rename to examples/ci/email_summary.py diff --git a/examples/ci/machine_learning.py b/examples/ci/machine_learning.py new file mode 100644 index 000000000..e69de29bb diff --git a/examples/ml_engineer_with_tools.py b/examples/ci/ml_engineer_with_tools.py similarity index 74% rename from examples/ml_engineer_with_tools.py rename to examples/ci/ml_engineer_with_tools.py index 1c90f2946..1c73a1dd0 100644 --- a/examples/ml_engineer_with_tools.py +++ b/examples/ci/ml_engineer_with_tools.py @@ -9,8 +9,8 @@ async def main(requirement: str, auto_run: bool = True, use_tools: bool = True): if __name__ == "__main__": - data_path = "your_path_to_icr/icr-identify-age-related-conditions" # 替换 'your_path_to_icr' 为实际数据存放的路径 - train_path = f"{data_path}/your_train_data.csv" # 替换 'your_train_data.csv' 为你的训练数据文件名 - eval_path = f"{data_path}/your_eval_data.csv" # 替换 'your_eval_data.csv' 为你的评估数据文件名 + data_path = "your_path_to_icr/icr-identify-age-related-conditions" + train_path = f"{data_path}/your_train_data.csv" + eval_path = f"{data_path}/your_eval_data.csv" 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: {train_path}, eval data path:{eval_path}." asyncio.run(main(requirement))