formatting

This commit is contained in:
garylin2099 2023-11-17 14:40:07 +08:00
parent 7bf808ee25
commit 705a3e962b
2 changed files with 18 additions and 5 deletions

View file

@ -9,6 +9,7 @@ import asyncio
import fire
from metagpt.llm import LLM
from metagpt.actions import Action
from metagpt.roles import Role
from metagpt.schema import Message
@ -22,7 +23,7 @@ class SimpleWriteCode(Action):
your code:
"""
def __init__(self, name="SimpleWriteCode", context=None, llm=None):
def __init__(self, name: str = "SimpleWriteCode", context=None, llm: LLM = None):
super().__init__(name, context, llm)
async def run(self, instruction: str):
@ -42,8 +43,9 @@ class SimpleWriteCode(Action):
code_text = match.group(1) if match else rsp
return code_text
class SimpleRunCode(Action):
def __init__(self, name="SimpleRunCode", context=None, llm=None):
def __init__(self, name: str = "SimpleRunCode", context=None, llm: LLM = None):
super().__init__(name, context, llm)
async def run(self, code_text: str):
@ -52,6 +54,7 @@ class SimpleRunCode(Action):
logger.info(f"{code_result=}")
return code_result
class SimpleCoder(Role):
def __init__(
self,
@ -73,6 +76,7 @@ class SimpleCoder(Role):
return msg
class RunnableCoder(Role):
def __init__(
self,
@ -97,6 +101,7 @@ class RunnableCoder(Role):
self._rc.memory.add(msg)
return msg
def main(msg="write a function that calculates the product of a list and run it"):
# role = SimpleCoder()
role = RunnableCoder()

View file

@ -6,6 +6,8 @@ Author: garylin2099
import re
import asyncio
import fire
from metagpt.llm import LLM
from metagpt.actions import Action, BossRequirement
from metagpt.roles import Role
from metagpt.team import Team
@ -26,7 +28,7 @@ class SimpleWriteCode(Action):
your code:
"""
def __init__(self, name="SimpleWriteCode", context=None, llm=None):
def __init__(self, name: str = "SimpleWriteCode", context=None, llm: LLM = None):
super().__init__(name, context, llm)
async def run(self, instruction: str):
@ -39,6 +41,7 @@ class SimpleWriteCode(Action):
return code_text
class SimpleCoder(Role):
def __init__(
self,
@ -50,6 +53,7 @@ class SimpleCoder(Role):
self._watch([BossRequirement])
self._init_actions([SimpleWriteCode])
class SimpleWriteTest(Action):
PROMPT_TEMPLATE = """
@ -59,7 +63,7 @@ class SimpleWriteTest(Action):
your code:
"""
def __init__(self, name="SimpleWriteTest", context=None, llm=None):
def __init__(self, name: str = "SimpleWriteTest", context=None, llm: LLM = None):
super().__init__(name, context, llm)
async def run(self, context: str, k: int = 3):
@ -72,6 +76,7 @@ class SimpleWriteTest(Action):
return code_text
class SimpleTester(Role):
def __init__(
self,
@ -96,6 +101,7 @@ class SimpleTester(Role):
return msg
class SimpleWriteReview(Action):
PROMPT_TEMPLATE = """
@ -103,7 +109,7 @@ class SimpleWriteReview(Action):
Review the test cases and provide one critical comments:
"""
def __init__(self, name="SimpleWriteReview", context=None, llm=None):
def __init__(self, name: str = "SimpleWriteReview", context=None, llm: LLM = None):
super().__init__(name, context, llm)
async def run(self, context: str):
@ -114,6 +120,7 @@ class SimpleWriteReview(Action):
return rsp
class SimpleReviewer(Role):
def __init__(
self,
@ -125,6 +132,7 @@ class SimpleReviewer(Role):
self._init_actions([SimpleWriteReview])
self._watch([SimpleWriteTest])
async def main(
idea: str = "write a function that calculates the product of a list",
investment: float = 3.0,