MetaGPT入门(二)

接着MetaGPT入门(一),在文件里再添加一个role类

python 复制代码
class SimpleCoder(Role):
    
    def __init__(
            self,
            name:str="Alice",
            profile:str="SimpleCoder",
            **kwargs
    ):
        super().__init__(name,profile,**kwargs)
        self._init_actions([WriteSimpleCode])

    async def _act(self) -> Message:
        #记录角色的相关信息
        logger.info(f'{self._setting}:ready to {self._rc.todo}')
        #获取需要执行的动作,todo will be SimpleWriteCode()
        todo = self._rc.todo
        #获取动作执行需要的信息
        msg = self.get_memories(k=1)[0]
        #开始执行动作
        code_text = await todo.run(msg.content)
        #将动作的结果封装成消息形式返回,方便与其他Agent通信使用吧
        msg = Message(content=code_text,role=self.profile, cause_by=type(todo))

        return msg

async def main():
    msg = "write a function that calculates the sum of a list"
    role = SimpleCoder()
    logger.info(msg)
    result = await role.run(msg)
    logger.info(result)

asyncio.run(main())

logger里会详细记录运行过程及各种设置,可以仔细研究

运行结果正确

相关推荐
蜗牛互联网8 分钟前
Python调用Gemini Structured Outputs实现工单路由门禁
java·开发语言·人工智能·python
TomEval24 分钟前
【测AI】第12篇:NLP / CV / 语音 —— 三大 AI 方向速通
人工智能·python·自然语言处理·aigc·测试用例
SEO_juper24 分钟前
给网页做可引用性评分:判断内容够不够让 AI 引用(GEO 工具,附代码)
开发语言·人工智能·爬虫·python·seo·独立站
AI直播技术杂谈27 分钟前
无人直播中控的硬件底线,旧电脑要满足哪些条件
网络·python·ai·云计算
Helix25032 分钟前
Python数据分析实战:Pandas清洗豆瓣短评与情感分析完整指南
python·pandas·数据清洗·情感分析··snownlp·文本数据处理
MerryLuna1 小时前
专业的EUDR机构
大数据·人工智能·python
ueotek1 小时前
Ansys Zemax丨在 OpticStudio 中拟合折射率数据
python·软件工程·ansys·光学仿真·光学设计·zeamx
czq_26867194871 小时前
Python打卡第40天
开发语言·python
不爱吃鱼的蔓热莓1 小时前
Autosar之根据ARXML中报文信息生成SWC(二)
开发语言·python
奈葵1 小时前
Python语句
开发语言·python