fix: install missing package.

This commit is contained in:
刘棒棒 2023-11-28 11:24:52 +08:00
parent 5d3f51b010
commit b19e4908b2
2 changed files with 20 additions and 5 deletions

View file

@ -30,7 +30,7 @@ class WriteCodeByGenerate(BaseWriteAnalysisCode):
super().__init__(name, context, llm)
def process_msg(self, prompt: Union[str, List[Dict], Message, List[Message]], system_msg: str = None):
default_system_msg = """You are Open 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: The code for the next step depends on the code for the previous step.**"""
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: The code for the next step depends on the code for the previous step. Reuse existing code directly. Use !pip install to install missing packages.**"""
# 全部转成list
if not isinstance(prompt, list):
prompt = [prompt]

View file

@ -44,6 +44,7 @@ class MLEngineer(Role):
self.plan = Plan(goal=goal)
self.use_tools = False
self.use_task_guide = False
self.execute_code = ExecutePyCode()
async def _plan_and_act(self):
@ -90,9 +91,10 @@ class MLEngineer(Role):
self._rc.memory.add(Message(content=code, role="assistant", cause_by=cause_by))
result, success = await ExecutePyCode().run(code)
print(result)
self._rc.memory.add(Message(content=result, role="user", cause_by=ExecutePyCode))
result, success = await self.execute_code.run(code)
# truncated the result
print(self.truncate(result))
self._rc.memory.add(Message(content=self.truncate(result), role="user", cause_by=ExecutePyCode))
# if not success:
# await self._ask_review()
@ -104,7 +106,8 @@ class MLEngineer(Role):
async def _ask_review(self):
context = self.get_useful_memories()
review, confirmed = await AskReview().run(context=context[-5:], plan=self.plan)
self._rc.memory.add(Message(content=review, role="user", cause_by=AskReview))
if review.lower() not in ("confirm", "y", "yes"):
self._rc.memory.add(Message(content=review, role="user", cause_by=AskReview))
return confirmed
async def _update_plan(self, max_tasks: int = 3):
@ -124,6 +127,18 @@ class MLEngineer(Role):
memories = super().get_memories()
return memories
def truncate(self, result: str, keep_len: int = 1000) -> str:
desc = """I truncated the result to only keep the last 1000 characters\n"""
if result.startswith(desc):
result = result[-len(desc):]
if len(result) > keep_len:
result = result[-keep_len:]
if not result.startswith(desc):
return desc + result
return desc
if __name__ == "__main__":
# requirement = "create a normal distribution and visualize it"