diff --git a/metagpt/strategy/tot.py b/metagpt/strategy/tot.py index a32cfdf40..4f33698bf 100644 --- a/metagpt/strategy/tot.py +++ b/metagpt/strategy/tot.py @@ -5,7 +5,7 @@ import asyncio from typing import Any, List -from pydantic import BaseModel, Field +from pydantic import BaseModel, ConfigDict, Field from metagpt.llm import LLM from metagpt.logs import logger @@ -29,6 +29,8 @@ Output a list of jsons following the format: class ThoughtSolverBase(BaseModel): + model_config = ConfigDict(arbitrary_types_allowed=True) + thought_tree: str = "" llm: BaseLLM = Field(default_factory=LLM, exclude=True) config: ThoughtSolverConfig = Field(default_factory=ThoughtSolverConfig) diff --git a/requirements.txt b/requirements.txt index 832b4c1c8..c04c6cc7f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -58,3 +58,4 @@ websockets~=12.0 networkx~=3.2.1 google-generativeai==0.3.1 playwright==1.40.0 +anytree diff --git a/tests/metagpt/strategy/__init__.py b/tests/metagpt/strategy/__init__.py new file mode 100644 index 000000000..e95a9b4ed --- /dev/null +++ b/tests/metagpt/strategy/__init__.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +@Time : 2023/12/30 00:33 +@Author : alexanderwu +@File : __init__.py +""" diff --git a/metagpt/strategy/examples/__init__.py b/tests/metagpt/strategy/examples/__init__.py similarity index 100% rename from metagpt/strategy/examples/__init__.py rename to tests/metagpt/strategy/examples/__init__.py diff --git a/metagpt/strategy/examples/creative_writing.py b/tests/metagpt/strategy/examples/creative_writing.py similarity index 87% rename from metagpt/strategy/examples/creative_writing.py rename to tests/metagpt/strategy/examples/creative_writing.py index 94efd9264..59a3c94d7 100644 --- a/metagpt/strategy/examples/creative_writing.py +++ b/tests/metagpt/strategy/examples/creative_writing.py @@ -3,8 +3,8 @@ # @Author : stellahong (stellahong@fuzhi.ai) # @Desc : import re +from typing import Dict -from metagpt.strategy.prompt_templates.creative_writing import cot_prompt, vote_prompt from metagpt.strategy.tot import TreeofThought from metagpt.strategy.tot_schema import ( BaseEvaluator, @@ -12,6 +12,10 @@ from metagpt.strategy.tot_schema import ( Strategy, ThoughtSolverConfig, ) +from tests.metagpt.strategy.prompt_templates.creative_writing import ( + cot_prompt, + vote_prompt, +) class TextGenParser(BaseParser): @@ -31,8 +35,8 @@ class TextGenParser(BaseParser): class TextGenEvaluator(BaseEvaluator): - value_map = {"impossible": 0.001, "likely": 1, "sure": 20} # TODO: ad hoc - status_map = {val: key for key, val in value_map.items()} + value_map: Dict[str, float] = {"impossible": 0.001, "likely": 1, "sure": 20} # TODO: ad hoc + status_map: Dict = {val: key for key, val in value_map.items()} def __call__(self, evaluation: str, **kwargs) -> float: try: @@ -59,7 +63,7 @@ class TextGenEvaluator(BaseEvaluator): return status -if __name__ == "__main__": +def test_creative_writing(): import asyncio initial_prompt = """It isn't difficult to do a handstand if you just stand on your hands. It caught him off guard that space smelled of seared steak. When she didn’t like a guy who was trying to pick her up, she started using sign language. Each person who knows you has a different perception of who you are.""" diff --git a/metagpt/strategy/examples/game24.py b/tests/metagpt/strategy/examples/game24.py similarity index 85% rename from metagpt/strategy/examples/game24.py rename to tests/metagpt/strategy/examples/game24.py index 32e4ede02..c26c8da88 100644 --- a/metagpt/strategy/examples/game24.py +++ b/tests/metagpt/strategy/examples/game24.py @@ -3,8 +3,8 @@ # @Author : stellahong (stellahong@fuzhi.ai) # @Desc : import re +from typing import Dict -from metagpt.strategy.prompt_templates.game24 import propose_prompt, value_prompt from metagpt.strategy.tot import TreeofThought from metagpt.strategy.tot_schema import ( BaseEvaluator, @@ -12,6 +12,7 @@ from metagpt.strategy.tot_schema import ( Strategy, ThoughtSolverConfig, ) +from tests.metagpt.strategy.prompt_templates.game24 import propose_prompt, value_prompt class Game24Parser(BaseParser): @@ -31,8 +32,8 @@ class Game24Parser(BaseParser): class Game24Evaluator(BaseEvaluator): - value_map = {"impossible": 0.001, "likely": 1, "sure": 20} # TODO: ad hoc - status_map = {val: key for key, val in value_map.items()} + value_map: Dict[str, float] = {"impossible": 0.001, "likely": 1, "sure": 20} # TODO: ad hoc + status_map: Dict = {val: key for key, val in value_map.items()} def __call__(self, evaluation: str, **kwargs) -> float: try: @@ -51,7 +52,7 @@ class Game24Evaluator(BaseEvaluator): return status -if __name__ == "__main__": +def test_game24(): import asyncio initial_prompt = """4 5 6 10""" diff --git a/metagpt/strategy/prompt_templates/__init__.py b/tests/metagpt/strategy/prompt_templates/__init__.py similarity index 100% rename from metagpt/strategy/prompt_templates/__init__.py rename to tests/metagpt/strategy/prompt_templates/__init__.py diff --git a/metagpt/strategy/prompt_templates/creative_writing.py b/tests/metagpt/strategy/prompt_templates/creative_writing.py similarity index 100% rename from metagpt/strategy/prompt_templates/creative_writing.py rename to tests/metagpt/strategy/prompt_templates/creative_writing.py diff --git a/metagpt/strategy/prompt_templates/game24.py b/tests/metagpt/strategy/prompt_templates/game24.py similarity index 100% rename from metagpt/strategy/prompt_templates/game24.py rename to tests/metagpt/strategy/prompt_templates/game24.py