Skip to content

Commit

Permalink
update requirement and example, recover legacy code
Browse files Browse the repository at this point in the history
  • Loading branch information
garylin2099 committed Mar 12, 2024
1 parent a680a1a commit e960ac8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


async def main(requirement: str):
role = DataInterpreter(tools=["<all>"])
role = DataInterpreter(use_reflection=True, tools=["<all>"])
await role.run(requirement)


Expand Down
10 changes: 6 additions & 4 deletions metagpt/strategy/task_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,31 @@ class TaskTypeDef(BaseModel):


class TaskType(Enum):
"""By identifying specific types of tasks, we can inject human priors (guidance) to help task solving"""

EDA = TaskTypeDef(
name="eda",
desc="For performing exploratory data analysis",
guidance=EDA_PROMPT,
)
DATA_PREPROCESS = TaskTypeDef(
name="data_preprocess",
name="data preprocessing",
desc="For preprocessing dataset in a data analysis or machine learning task ONLY,"
"general data operation doesn't fall into this type",
guidance=DATA_PREPROCESS_PROMPT,
)
FEATURE_ENGINEERING = TaskTypeDef(
name="feature_engineering",
name="feature engineering",
desc="Only for creating new columns for input data.",
guidance=FEATURE_ENGINEERING_PROMPT,
)
MODEL_TRAIN = TaskTypeDef(
name="model_train",
name="model train",
desc="Only for training model.",
guidance=MODEL_TRAIN_PROMPT,
)
MODEL_EVALUATE = TaskTypeDef(
name="model_evaluate",
name="model evaluate",
desc="Only for evaluating model.",
guidance=MODEL_EVALUATE_PROMPT,
)
Expand Down
22 changes: 21 additions & 1 deletion metagpt/tools/tool_recommend.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ToolRecommender(BaseModel):
"""

tools: dict[str, Tool] = {}
force: bool = False
force: bool = False # whether to forcedly recommend the specified tools

@field_validator("tools", mode="before")
@classmethod
Expand Down Expand Up @@ -145,6 +145,26 @@ async def rank_tools(
return list(valid_tools.values())[:topk]


class TypeMatchToolRecommender(ToolRecommender):
"""
A legacy ToolRecommender using task type matching at the recall stage:
1. Recall: Find tools based on exact match between task type and tool tag;
2. Rank: LLM rank, the same as the default ToolRecommender.
"""

async def recall_tools(self, context: str = "", plan: Plan = None, topk: int = 20) -> list[Tool]:
if not plan:
return list(self.tools.values())[:topk]

# find tools based on exact match between task type and tool tag
task_type = plan.current_task.task_type
candidate_tools = TOOL_REGISTRY.get_tools_by_tag(task_type)
candidate_tool_names = set(self.tools.keys()) & candidate_tools.keys()
recalled_tools = [candidate_tools[tool_name] for tool_name in candidate_tool_names]

return recalled_tools[:topk]


class BM25ToolRecommender(ToolRecommender):
"""
A ToolRecommender using BM25 at the recall stage:
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ Pillow
imap_tools==1.5.0 # Used by metagpt/tools/libs/email_login.py
qianfan==0.3.2
dashscope==1.14.1
rank-bm25==0.2.2 # for tool recommendation
jieba==0.42.1 # for tool recommendation

0 comments on commit e960ac8

Please sign in to comment.