🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
Merge branch 'dev' into dev_pipeline
yzlin5522742002bc
diff --cc metagpt/actions/write_analysis_code.pyindex 51cfa6d49,787fb8d3e..66e2137fe--- a/metagpt/actions/write_analysis_code.py+++ b/metagpt/actions/write_analysis_code.py@@@ -23,10 -37,9 +37,11 @@@ class BaseWriteAnalysisCode(Action)str: The code string."""+class WriteCodeByGenerate(BaseWriteAnalysisCode):"""Write code fully by generation"""+ DEFAULT_SYSTEM_MSG = """You are Code Interpreter, a world-class programmer that can complete any goal by executing code. Strictly follow the plan and generate code step by step. Each step of the code will be executed on the user's machine, and the user will provide the code execution results to you.**Notice: Use !pip install in a standalone block to install missing packages.**""" # prompt reference: https://github.com/KillianLucas/open-interpreter/blob/v0.1.4/interpreter/system_message.txt+ REUSE_CODE_INSTRUCTION = """ATTENTION: DONT include codes from previous tasks in your current code block, include new codes only, DONT repeat codes!"""def __init__(self, name: str = "", context=None, llm=None) -> str:super().__init__(name, context, llm)@@@ -58,9 -84,13 +82,14 @@@return messagesasync def run(- self, context: [List[Message]], plan: Plan = None, task_guide: str = "", system_msg: str = None, **kwargs+ self,+ context: [List[Message]],+ plan: Plan = None,+ task_guide: str = "",+ system_msg: str = None,+ **kwargs,) -> str:+ context.append(Message(content=self.REUSE_CODE_INSTRUCTION, role="user"))prompt = self.process_msg(context, system_msg)code_content = await self.llm.aask_code(prompt, **kwargs)return code_content["code"]diff --cc metagpt/roles/ml_engineer.pyindex 7ad29a532,08c5649d4..1e4367372--- a/metagpt/roles/ml_engineer.py+++ b/metagpt/roles/ml_engineer.py@@@ -21,10 -21,11 +21,11 @@@ STRUCTURAL_CONTEXT = ""{current_task}"""+def truncate(result: str, keep_len: int = 1000) -> str:- desc = """I truncated the result to only keep the last 1000 characters\n"""+ desc = "Truncated to show only the last 1000 characters\n"if result.startswith(desc):- result = result[-len(desc):]+ result = result[-len(desc) :]if len(result) > keep_len:result = result[-keep_len:]@@@ -127,9 -143,11 +137,11 @@@ class MLEngineer(Role)# truncated the resultprint(truncate(result))# print(result)- self.working_memory.add(Message(content=result, role="user", cause_by=ExecutePyCode))+ self.working_memory.add(+ Message(content=result, role="user", cause_by=ExecutePyCode)+ )- if code.startswith("!pip"):+ if "!pip" in code:success = False# if not success:# await self._ask_review()@@@ -174,15 -202,13 +192,16 @@@def working_memory(self):return self._rc.memory+if __name__ == "__main__":- # requirement = "create a normal distribution and visualize it"- requirement = "run some analysis on iris dataset"-- async def main(requirement: str = requirement):- role = MLEngineer(goal=requirement)+ 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"++ async def main(requirement: str = requirement, auto_run: bool = False):+ role = MLEngineer(goal=requirement, auto_run=auto_run)await role.run(requirement)fire.Fire(main)