mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-27 14:25:20 +02:00
code adapted to v0.6
This commit is contained in:
parent
4ec6151691
commit
cd990fd5c9
15 changed files with 80 additions and 77 deletions
|
|
@ -30,7 +30,7 @@ class AskReview(Action):
|
|||
)
|
||||
|
||||
logger.info("most recent context:")
|
||||
latest_action = context[-1].cause_by.__name__ if context[-1].cause_by else ""
|
||||
latest_action = context[-1].cause_by if context[-1].cause_by else ""
|
||||
review_instruction = (
|
||||
ReviewConst.TASK_REVIEW_INSTRUCTION
|
||||
if trigger == ReviewConst.TASK_REVIEW_TRIGGER
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Any, List, Optional
|
||||
from typing import List
|
||||
|
||||
from metagpt.actions.write_analysis_code import BaseWriteAnalysisCode
|
||||
from metagpt.logs import logger
|
||||
|
|
@ -82,11 +82,6 @@ def messages_to_str(messages: List[Message]) -> str:
|
|||
|
||||
class DebugCode(BaseWriteAnalysisCode):
|
||||
name: str = "debugcode"
|
||||
context: Optional[str] = None
|
||||
llm: None
|
||||
|
||||
def __init__(self, **kwargs: Any):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
async def run_reflection(
|
||||
self,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import re
|
|||
import traceback
|
||||
from abc import ABC, abstractmethod
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Tuple, Union
|
||||
from typing import Any, Dict, List, Tuple, Union
|
||||
|
||||
import nbformat
|
||||
from nbclient import NotebookClient
|
||||
|
|
@ -48,23 +48,25 @@ class ExecuteCode(ABC):
|
|||
class ExecutePyCode(ExecuteCode, Action):
|
||||
"""execute code, return result to llm, and display it."""
|
||||
|
||||
nb: Any
|
||||
nb_client: Any
|
||||
console: Console
|
||||
interaction: str
|
||||
timeout: int = 600
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name: str = "python_executor",
|
||||
context=None,
|
||||
llm=None,
|
||||
nb=None,
|
||||
timeout: int = 600,
|
||||
timeout=600,
|
||||
):
|
||||
super().__init__(name, context, llm)
|
||||
if nb is None:
|
||||
self.nb = nbformat.v4.new_notebook()
|
||||
else:
|
||||
self.nb = nb
|
||||
self.timeout = timeout
|
||||
self.nb_client = NotebookClient(self.nb, timeout=self.timeout)
|
||||
self.console = Console()
|
||||
self.interaction = "ipython" if self.is_ipython() else "terminal"
|
||||
nb = nb or nbformat.v4.new_notebook()
|
||||
super().__init__(
|
||||
nb=nb,
|
||||
nb_client=NotebookClient(nb, timeout=timeout),
|
||||
timeout=timeout,
|
||||
console=Console(),
|
||||
interaction=("ipython" if self.is_ipython() else "terminal"),
|
||||
)
|
||||
|
||||
async def build(self):
|
||||
if self.nb_client.kc is None or not await self.nb_client.kc.is_alive():
|
||||
|
|
|
|||
|
|
@ -7,16 +7,13 @@ from metagpt.utils.common import CodeParser, create_func_config, remove_comments
|
|||
|
||||
|
||||
class SummarizeAnalysis(Action):
|
||||
PROMPT_TEMPLATE = """
|
||||
PROMPT_TEMPLATE: str = """
|
||||
# Context
|
||||
{context}
|
||||
# Summary
|
||||
Output a 30-word summary on analysis tool and modeling algorithms you have used, and the corresponding result. Make sure to announce the complete path to your test prediction file. Your summary:
|
||||
"""
|
||||
|
||||
def __init__(self, name: str = "", context=None, llm=None) -> str:
|
||||
super().__init__(name, context, llm)
|
||||
|
||||
async def run(self, conmpleted_plan: Plan) -> str:
|
||||
tasks = json.dumps(
|
||||
[task.dict() for task in conmpleted_plan.tasks],
|
||||
|
|
@ -29,7 +26,7 @@ class SummarizeAnalysis(Action):
|
|||
|
||||
|
||||
class Reflect(Action):
|
||||
PROMPT_TEMPLATE = """
|
||||
PROMPT_TEMPLATE: str = """
|
||||
# Context
|
||||
__context__
|
||||
# Latest User Requirement
|
||||
|
|
@ -45,7 +42,7 @@ class Reflect(Action):
|
|||
}
|
||||
```
|
||||
"""
|
||||
REWRITE_PLAN_INSTRUCTION = """Take this reflection for rewriting plan, modify the current plan in place, make reference to your specific instruction, think about you should
|
||||
REWRITE_PLAN_INSTRUCTION: str = """Take this reflection for rewriting plan, modify the current plan in place, make reference to your specific instruction, think about you should
|
||||
change which task, add or delete what tasks in the plan. Only make necessary changes, keep reusable tasks unchanged, output the COMPLETE new plan starting from the first task. Your plan should have no more than 5 tasks."""
|
||||
|
||||
async def run(self, context: str, user_requirement: str = "") -> str:
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ from metagpt.utils.common import create_func_config, remove_comments
|
|||
|
||||
|
||||
class BaseWriteAnalysisCode(Action):
|
||||
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. Must reuse variables in the lastest other code directly, dont creat it again, it is very import for you. Use !pip install in a standalone block to install missing packages.Usually the libraries you need are already installed.Dont check if packages already imported.**""" # prompt reference: https://github.com/KillianLucas/open-interpreter/blob/v0.1.4/interpreter/system_message.txt
|
||||
DEFAULT_SYSTEM_MSG: str = """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. Must reuse variables in the lastest other code directly, dont creat it again, it is very import for you. Use !pip install in a standalone block to install missing packages.Usually the libraries you need are already installed.Dont check if packages already imported.**""" # 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 process_msg(self, prompt: Union[str, List[Dict], Message, List[Message]], system_msg: str = None):
|
||||
|
|
@ -76,9 +76,6 @@ class BaseWriteAnalysisCode(Action):
|
|||
class WriteCodeByGenerate(BaseWriteAnalysisCode):
|
||||
"""Write code fully by generation"""
|
||||
|
||||
def __init__(self, name: str = "", context=None, llm=None) -> str:
|
||||
super().__init__(name, context, llm)
|
||||
|
||||
async def run(
|
||||
self,
|
||||
context: [List[Message]],
|
||||
|
|
@ -95,12 +92,14 @@ class WriteCodeByGenerate(BaseWriteAnalysisCode):
|
|||
class WriteCodeWithTools(BaseWriteAnalysisCode):
|
||||
"""Write code with help of local available tools. Choose tools first, then generate code to use the tools"""
|
||||
|
||||
def __init__(self, name: str = "", context=None, llm=None, schema_path=None):
|
||||
super().__init__(name, context, llm)
|
||||
self.schema_path = schema_path
|
||||
self.available_tools = {}
|
||||
schema_path: str = ""
|
||||
available_tools: dict = {}
|
||||
|
||||
if self.schema_path is not None:
|
||||
def __init__(self, schema_path="", **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.schema_path = schema_path
|
||||
|
||||
if schema_path:
|
||||
self._load_tools(schema_path)
|
||||
|
||||
def _load_tools(self, schema_path, schema_module=None):
|
||||
|
|
@ -223,7 +222,7 @@ class WriteCodeWithTools(BaseWriteAnalysisCode):
|
|||
|
||||
|
||||
class MakeTools(WriteCodeByGenerate):
|
||||
DEFAULT_SYSTEM_MSG = """Convert any codes provied for you to a very General Function Code startswith `def`.\n
|
||||
DEFAULT_SYSTEM_MSG: str = """Convert any codes provied for you to a very General Function Code startswith `def`.\n
|
||||
**Notice:
|
||||
1. Your code must contain a general function start with `def`.
|
||||
2. Refactor your code to get the most efficient implementation for large input data in the shortest amount of time.
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ from metagpt.utils.common import CodeParser, create_func_config
|
|||
|
||||
|
||||
class WritePlan(Action):
|
||||
PROMPT_TEMPLATE = """
|
||||
PROMPT_TEMPLATE: str = """
|
||||
# Context:
|
||||
__context__
|
||||
# Task:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue