update ser&deser unittest

This commit is contained in:
better629 2023-12-29 04:27:44 +08:00
parent 311e48b604
commit e52957026b
28 changed files with 27 additions and 35 deletions

View file

@ -52,7 +52,7 @@ Now you should start rewriting the code:
class DebugError(Action):
name: str = "DebugError"
context: RunCodeContext = Field(default_factory=RunCodeContext)
llm: BaseLLM = Field(default_factory=LLM)
llm: BaseLLM = Field(default_factory=LLM, exclude=True)
async def run(self, *args, **kwargs) -> str:
output_doc = await FileRepository.get_file(

View file

@ -44,7 +44,7 @@ NEW_REQ_TEMPLATE = """
class WriteDesign(Action):
name: str = ""
context: Optional[str] = None
llm: BaseLLM = Field(default_factory=LLM)
llm: BaseLLM = Field(default_factory=LLM, exclude=True)
desc: str = (
"Based on the PRD, think about the system design, and design the corresponding APIs, "
"data structures, library tables, processes, and paths. Please provide your design, feedback "

View file

@ -18,7 +18,7 @@ from metagpt.provider.base_llm import BaseLLM
class DesignReview(Action):
name: str = "DesignReview"
context: Optional[str] = None
llm: BaseLLM = Field(default_factory=LLM)
llm: BaseLLM = Field(default_factory=LLM, exclude=True)
async def run(self, prd, api_design):
prompt = (

View file

@ -17,7 +17,7 @@ from metagpt.schema import Message
class ExecuteTask(Action):
name: str = "ExecuteTask"
context: list[Message] = []
llm: BaseLLM = Field(default_factory=LLM)
llm: BaseLLM = Field(default_factory=LLM, exclude=True)
async def run(self, *args, **kwargs):
pass

View file

@ -42,7 +42,7 @@ class InvoiceOCR(Action):
name: str = "InvoiceOCR"
context: Optional[str] = None
llm: BaseLLM = Field(default_factory=LLM)
llm: BaseLLM = Field(default_factory=LLM, exclude=True)
@staticmethod
async def _check_file_type(file_path: Path) -> str:

View file

@ -28,7 +28,7 @@ class PrepareDocuments(Action):
name: str = "PrepareDocuments"
context: Optional[str] = None
llm: BaseLLM = Field(default_factory=LLM)
llm: BaseLLM = Field(default_factory=LLM, exclude=True)
def _init_repo(self):
"""Initialize the Git environment."""

View file

@ -43,7 +43,7 @@ NEW_REQ_TEMPLATE = """
class WriteTasks(Action):
name: str = "CreateTasks"
context: Optional[str] = None
llm: BaseLLM = Field(default_factory=LLM)
llm: BaseLLM = Field(default_factory=LLM, exclude=True)
async def run(self, with_messages, schema=CONFIG.prompt_schema):
system_design_file_repo = CONFIG.git_repo.new_file_repository(SYSTEM_DESIGN_FILE_REPO)

View file

@ -82,7 +82,7 @@ class CollectLinks(Action):
name: str = "CollectLinks"
context: Optional[str] = None
llm: BaseLLM = Field(default_factory=LLM)
llm: BaseLLM = Field(default_factory=LLM, exclude=True)
desc: str = "Collect links from a search engine."
search_engine: SearchEngine = Field(default_factory=SearchEngine)

View file

@ -79,7 +79,7 @@ standard errors:
class RunCode(Action):
name: str = "RunCode"
context: RunCodeContext = Field(default_factory=RunCodeContext)
llm: BaseLLM = Field(default_factory=LLM)
llm: BaseLLM = Field(default_factory=LLM, exclude=True)
@classmethod
@handle_exception

View file

@ -109,7 +109,7 @@ You are a member of a professional butler team and will provide helpful suggesti
class SearchAndSummarize(Action):
name: str = ""
content: Optional[str] = None
llm: BaseLLM = Field(default_factory=LLM)
llm: BaseLLM = Field(default_factory=LLM, exclude=True)
config: None = Field(default_factory=Config)
engine: Optional[SearchEngineType] = CONFIG.search_engine
search_func: Optional[Any] = None

View file

@ -95,7 +95,7 @@ flowchart TB
class SummarizeCode(Action):
name: str = "SummarizeCode"
context: CodeSummarizeContext = Field(default_factory=CodeSummarizeContext)
llm: BaseLLM = Field(default_factory=LLM)
llm: BaseLLM = Field(default_factory=LLM, exclude=True)
@retry(stop=stop_after_attempt(2), wait=wait_random_exponential(min=1, max=60))
async def summarize_code(self, prompt):

View file

@ -90,7 +90,7 @@ ATTENTION: Use '##' to SPLIT SECTIONS, not '#'. Output format carefully referenc
class WriteCode(Action):
name: str = "WriteCode"
context: Document = Field(default_factory=Document)
llm: BaseLLM = Field(default_factory=LLM)
llm: BaseLLM = Field(default_factory=LLM, exclude=True)
@retry(wait=wait_random_exponential(min=1, max=60), stop=stop_after_attempt(6))
async def write_code(self, prompt) -> str:

View file

@ -123,7 +123,7 @@ REWRITE_CODE_TEMPLATE = """
class WriteCodeReview(Action):
name: str = "WriteCodeReview"
context: CodingContext = Field(default_factory=CodingContext)
llm: BaseLLM = Field(default_factory=LLM)
llm: BaseLLM = Field(default_factory=LLM, exclude=True)
@retry(wait=wait_random_exponential(min=1, max=60), stop=stop_after_attempt(6))
async def write_code_review_and_rewrite(self, context_prompt, cr_prompt, filename):

View file

@ -163,7 +163,7 @@ class WriteDocstring(Action):
desc: str = "Write docstring for code."
context: Optional[str] = None
llm: BaseLLM = Field(default_factory=LLM)
llm: BaseLLM = Field(default_factory=LLM, exclude=True)
async def run(
self,

View file

@ -68,7 +68,7 @@ NEW_REQ_TEMPLATE = """
class WritePRD(Action):
name: str = ""
content: Optional[str] = None
llm: BaseLLM = Field(default_factory=LLM)
llm: BaseLLM = Field(default_factory=LLM, exclude=True)
async def run(self, with_messages, schema=CONFIG.prompt_schema, *args, **kwargs) -> ActionOutput | Message:
# Determine which requirement documents need to be rewritten: Use LLM to assess whether new requirements are

View file

@ -18,7 +18,7 @@ from metagpt.provider.base_llm import BaseLLM
class WritePRDReview(Action):
name: str = ""
context: Optional[str] = None
llm: BaseLLM = Field(default_factory=LLM)
llm: BaseLLM = Field(default_factory=LLM, exclude=True)
prd: Optional[str] = None
desc: str = "Based on the PRD, conduct a PRD Review, providing clear and detailed feedback"

View file

@ -38,7 +38,7 @@ class WriteReview(Action):
"""Write a review for the given context."""
name: str = "WriteReview"
llm: BaseLLM = Field(default_factory=LLM)
llm: BaseLLM = Field(default_factory=LLM, exclude=True)
async def run(self, context):
return await WRITE_REVIEW_NODE.fill(context=context, llm=self.llm, schema="json")

View file

@ -20,7 +20,7 @@ class WriteTeachingPlanPart(Action):
"""Write Teaching Plan Part"""
context: Optional[str] = None
llm: BaseLLM = Field(default_factory=LLM)
llm: BaseLLM = Field(default_factory=LLM, exclude=True)
topic: str = ""
language: str = "Chinese"
rsp: Optional[str] = None

View file

@ -45,7 +45,7 @@ you should correctly import the necessary classes based on these file locations!
class WriteTest(Action):
name: str = "WriteTest"
context: Optional[TestingContext] = None
llm: BaseLLM = Field(default_factory=LLM)
llm: BaseLLM = Field(default_factory=LLM, exclude=True)
async def write_code(self, prompt):
code_rsp = await self._aask(prompt)

View file

@ -27,7 +27,7 @@ class WriteDirectory(Action):
"""
name: str = "WriteDirectory"
llm: BaseLLM = Field(default_factory=LLM)
llm: BaseLLM = Field(default_factory=LLM, exclude=True)
language: str = "Chinese"
async def run(self, topic: str, *args, **kwargs) -> Dict:

View file

@ -174,7 +174,7 @@ class Message(BaseModel):
role: str = "user" # system / user / assistant
cause_by: str = Field(default="", validate_default=True)
sent_from: str = Field(default="", validate_default=True)
send_to: set = Field(default={MESSAGE_ROUTE_TO_ALL}, validate_default=True)
send_to: set[str] = Field(default={MESSAGE_ROUTE_TO_ALL}, validate_default=True)
@field_validator("id", mode="before")
@classmethod

View file

@ -28,5 +28,5 @@ async def test_action_deserialize():
new_action = Action(**serialized_data)
assert new_action.name == ""
assert new_action.llm == LLM()
assert isinstance(new_action.llm, type(LLM()))
assert len(await new_action._aask("who are you")) > 0

View file

@ -13,6 +13,7 @@ from metagpt.schema import Message
from metagpt.utils.common import any_to_str
from tests.metagpt.serialize_deserialize.test_serdeser_base import (
ActionOK,
ActionRaise,
RoleC,
serdeser_path,
)
@ -55,9 +56,9 @@ def test_environment_serdeser():
assert len(new_env.roles) == 1
assert list(new_env.roles.values())[0].states == list(environment.roles.values())[0].states
assert list(new_env.roles.values())[0].actions == list(environment.roles.values())[0].actions
assert isinstance(list(environment.roles.values())[0].actions[0], ActionOK)
assert type(list(new_env.roles.values())[0].actions[0]) == ActionOK
assert type(list(new_env.roles.values())[0].actions[1]) == ActionRaise
def test_environment_serdeser_v2():

View file

@ -6,7 +6,6 @@
import pytest
from metagpt.actions import WriteCode
from metagpt.llm import LLM
from metagpt.schema import CodingContext, Document
@ -28,5 +27,4 @@ async def test_write_code_deserialize():
new_action = WriteCode(**serialized_data)
assert new_action.name == "WriteCode"
assert new_action.llm == LLM()
await action.run()

View file

@ -5,7 +5,6 @@
import pytest
from metagpt.actions import WriteCodeReview
from metagpt.llm import LLM
from metagpt.schema import CodingContext, Document
@ -28,5 +27,4 @@ def div(a: int, b: int = 0):
new_action = WriteCodeReview(**serialized_data)
assert new_action.name == "WriteCodeReview"
assert new_action.llm == LLM()
await new_action.run()

View file

@ -5,7 +5,6 @@
import pytest
from metagpt.actions import WriteDesign, WriteTasks
from metagpt.llm import LLM
def test_write_design_serialize():
@ -28,7 +27,6 @@ async def test_write_design_deserialize():
serialized_data = action.model_dump()
new_action = WriteDesign(**serialized_data)
assert new_action.name == ""
assert new_action.llm == LLM()
await new_action.run(with_messages="write a cli snake game")
@ -38,5 +36,4 @@ async def test_write_task_deserialize():
serialized_data = action.model_dump()
new_action = WriteTasks(**serialized_data)
assert new_action.name == "CreateTasks"
assert new_action.llm == LLM()
await new_action.run(with_messages="write a cli snake game")

View file

@ -6,7 +6,6 @@
import pytest
from metagpt.actions import WritePRD
from metagpt.llm import LLM
from metagpt.schema import Message
@ -23,6 +22,5 @@ async def test_action_deserialize():
serialized_data = action.model_dump()
new_action = WritePRD(**serialized_data)
assert new_action.name == ""
assert new_action.llm == LLM()
action_output = await new_action.run(with_messages=Message(content="write a cli snake game"))
assert len(action_output.content) > 0

View file

@ -4,7 +4,7 @@
@Desc : the unittest of serialize
"""
from typing import List, Tuple
from typing import List
from metagpt.actions import WritePRD
from metagpt.actions.action_node import ActionNode
@ -27,7 +27,7 @@ def test_actionoutout_schema_to_mapping():
"properties": {"field": {"title": "field", "type": "array", "items": {"type": "string"}}},
}
mapping = actionoutout_schema_to_mapping(schema)
assert mapping["field"] == (List[str], ...)
assert mapping["field"] == (list[str], ...)
schema = {
"title": "test",
@ -46,7 +46,7 @@ def test_actionoutout_schema_to_mapping():
},
}
mapping = actionoutout_schema_to_mapping(schema)
assert mapping["field"] == (List[Tuple[str, str]], ...)
assert mapping["field"] == (list[list[str]], ...)
assert True, True