update locally

This commit is contained in:
stellahsr 2023-12-13 15:38:19 +08:00
parent 7e164eecb3
commit abad52da85
2 changed files with 48 additions and 8 deletions

View file

@ -6,6 +6,31 @@ from metagpt.actions import Action
from metagpt.schema import Message, Task, Plan
from metagpt.utils.common import CodeParser
# CODE_STEPS_PROMPT_TEMPLATE = """
# # Context
# {context}
#
# -----
# Tasks are all code development tasks.
# You are a professional engineer, the main goal is to plan out concise solution steps for Current Task before coding.
# A planning process can reduce the difficulty and improve the quality of coding.
# You may be given some code plans for the tasks ahead, but you don't have to follow the existing plan when planning the current task.
# The output plan should following the subsequent principles:
# 1.The plan is a rough checklist of steps outlining the entire program's structure.Try to keep the number of steps fewer than 5.
# 2.The steps should be written concisely and at a high level, avoiding overly detailed implementation specifics.
# 3.The execution of the plan happens sequentially, but the plan can incorporate conditional (if) and looping(loop) keywords for more complex structures.
#
# Output the code steps in a JSON format, as shown in this example:
# ```json
# {
# "Step 1": "",
# "Step 2": "",
# "Step 3": "",
# ...
# }
# ```
# """
CODE_STEPS_PROMPT_TEMPLATE = """
# Context
{context}
@ -19,6 +44,7 @@ The output plan should following the subsequent principles:
1.The plan is a rough checklist of steps outlining the entire program's structure.Try to keep the number of steps fewer than 5.
2.The steps should be written concisely and at a high level, avoiding overly detailed implementation specifics.
3.The execution of the plan happens sequentially, but the plan can incorporate conditional (if) and looping(loop) keywords for more complex structures.
4.Follow the code logic to design and provide the code steps. You can analysis it step by step
Output the code steps in a JSON format, as shown in this example:
```json
@ -31,11 +57,22 @@ Output the code steps in a JSON format, as shown in this example:
```
"""
# STRUCTURAL_CONTEXT = """
# ## User Requirement
# {user_requirement}
# ## Current Plan
# {tasks}
# ## Current Task
# {current_task}
# """
STRUCTURAL_CONTEXT = """
## User Requirement
{user_requirement}
## Current Plan
## Plan
{tasks}
## Codes
{codes}
## Current Task
{current_task}
"""
@ -63,21 +100,24 @@ class WriteCodeSteps(Action):
def get_context(self, plan: Plan):
user_requirement = plan.goal
select_task_keys = ['task_id', 'instruction', 'is_finished', 'code']
# select_task_keys = ['task_id','code']
# select_task_keys = ['task_id', 'instruction', 'is_finished', 'code']
select_task_keys = ['task_id','instruction']
def process_task(task):
task_dict = task.dict()
ptask = {k: task_dict[k] for k in task_dict if k in select_task_keys }
return ptask
tasks = json.dumps(
[process_task(task) for task in plan.tasks], indent=4, ensure_ascii=False
)
code_lists = [task.code for task in plan.tasks if task.is_finished==True]
codes = "\n\n".join(code_lists)
current_task = json.dumps(process_task(plan.current_task)) if plan.current_task else {}
context = STRUCTURAL_CONTEXT.format(
user_requirement=user_requirement, tasks=tasks, current_task=current_task
user_requirement=user_requirement, tasks=tasks, codes=codes, current_task=current_task
)
print(context)
# print(context)

View file

@ -290,11 +290,11 @@ if __name__ == "__main__":
# 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'."
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}/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."
async def main(requirement: str = requirement, auto_run: bool = True):
role = MLEngineer(goal=requirement, auto_run=auto_run)
await role.run(requirement)