当前位置: 首页 > news >正文

南京有制作网站的吗太原网站建设推广服务

南京有制作网站的吗,太原网站建设推广服务,做论坛网站看什么书,什么叫网络架构metagpt 多智能体系统 代码1. 动作及角色定义2. 主函数 代码解释1. 导入模块:2. 环境设置:3. 定义行动(Action):4. 定义角色(Role):5. 学生和老师的行为:6. 主函数&#…

metagpt 多智能体系统

    • 代码
      • 1. 动作及角色定义
      • 2. 主函数
    • 代码解释
      • 1. 导入模块:
      • 2. 环境设置:
      • 3. 定义行动(Action):
      • 4. 定义角色(Role):
      • 5. 学生和老师的行为:
      • 6. 主函数(main):
      • 7. 运行主函数:

代码

1. 动作及角色定义

import asynciofrom metagpt.actions import Action, UserRequirement
from metagpt.logs import logger
from metagpt.roles import Role
from metagpt.schema import Message
from metagpt.environment import Environmentfrom metagpt.const import MESSAGE_ROUTE_TO_ALLclassroom = Environment() class WritePoem(Action):name: str = "WritePoem"PROMPT_TEMPLATE: str = """Here is the historical conversation record : {msg} .Write a poem about the subject provided by human, Return only the content of the generated poem with NO other texts.If the teacher provides suggestions about the poem, revise the student's poem based on the suggestions and return.your poem:"""async def run(self, msg: str):prompt = self.PROMPT_TEMPLATE.format(msg = msg)rsp = await self._aask(prompt)return rspclass ReviewPoem(Action):name: str = "ReviewPoem"PROMPT_TEMPLATE: str = """Here is the historical conversation record : {msg} .Check student-created poems about the subject provided by human and give your suggestions for revisions. You prefer poems with elegant sentences and retro style.Return only your comments with NO other texts.your comments:"""async def run(self, msg: str):prompt = self.PROMPT_TEMPLATE.format(msg = msg)rsp = await self._aask(prompt)return rspclass Student(Role):name: str = "xiaoming"profile: str = "Student"def __init__(self, **kwargs):super().__init__(**kwargs)self.set_actions([WritePoem])self._watch([UserRequirement, ReviewPoem])async def _act(self) -> Message:logger.info(f"{self._setting}: ready to {self.rc.todo}")todo = self.rc.todomsg = self.get_memories()  # 获取所有记忆# logger.info(msg)poem_text = await WritePoem().run(msg)logger.info(f'student : {poem_text}')msg = Message(content=poem_text, role=self.profile,cause_by=type(todo))return msgclass Teacher(Role):name: str = "laowang"profile: str = "Teacher"def __init__(self, **kwargs):super().__init__(**kwargs)self.set_actions([ReviewPoem])self._watch([WritePoem])async def _act(self) -> Message:logger.info(f"{self._setting}: ready to {self.rc.todo}")todo = self.rc.todomsg = self.get_memories()  # 获取所有记忆poem_text = await ReviewPoem().run(msg)logger.info(f'teacher : {poem_text}')msg = Message(content=poem_text, role=self.profile,cause_by=type(todo))return msg

2. 主函数

async def main(topic: str, n_round=3):classroom.add_roles([Student(), Teacher()])classroom.publish_message(Message(role="Human", content=topic, cause_by=UserRequirement,send_to='' or MESSAGE_ROUTE_TO_ALL),peekable=False,)while n_round > 0:# self._save()n_round -= 1logger.debug(f"max {n_round=} left.")await classroom.run()return classroom.historyawait main(topic='wirte a poem about moon')
2024-12-15 16:53:21.726 | INFO     | __main__:_act:63 - xiaoming(Student): ready to WritePoemGlimmering in the velvet night,
The moon ascends, a silver knight.
Its glow, a gentle, silken light,
Adorns the world with quiet might.A crescent curve, a silver coin,
It dances in the starry line.
A beacon in the darkened sea,
Guiding ships to safe, calm sea.Its phases, a silent story,
Of waxing, waning, and the glory.
A celestial lullaby,
Whispers through the silent sky.Oh, moon, your beauty bright,
A timeless dance in the night's delight.
A silent sentinel, you stand,
Guarding dreams and silent land.2024-12-15 16:53:25.871 | WARNING  | metagpt.utils.cost_manager:update_cost:49 - Model GLM-4-flash not found in TOKEN_COSTS.
2024-12-15 16:53:25.872 | INFO     | __main__:_act:69 - student : Glimmering in the velvet night,
The moon ascends, a silver knight.
Its glow, a gentle, silken light,
Adorns the world with quiet might.A crescent curve, a silver coin,
It dances in the starry line.
A beacon in the darkened sea,
Guiding ships to safe, calm sea.Its phases, a silent story,
Of waxing, waning, and the glory.
A celestial lullaby,
Whispers through the silent sky.Oh, moon, your beauty bright,
A timeless dance in the night's delight.
A silent sentinel, you stand,
Guarding dreams and silent land.
2024-12-15 16:53:25.873 | INFO     | __main__:_act:86 - laowang(Teacher): ready to ReviewPoem- The opening line sets a beautiful scene, but consider a more poetic turn of phrase to enhance the velvet night's description.
- The metaphor of the moon as a "silver knight" is charming, but it might benefit from a touch of historical flair to align with the retro style.
- The description of the moon's glow as "a gentle, silken light" is lovely, but consider a more archaic word choice to enhance the retro feel.
- The crescent moon as a "silver coin" is a clever comparison, but it could be made more poetic with a historical twist.
- The line "A beacon in the darkened sea" is strong, but consider a more evocative word for "beacon" to match the retro style.
- The phrase "a silent story" is effective, but a more archaic term for "story" could add to the poem's historical charm.
- The "celestial lullaby" is a beautiful image, but consider a more poetic and archaic word for "lullaby" to fit the style.
- The final couplet is powerful, but the word "silent sentinel" could be made more poetic and retro2024-12-15 16:53:30.841 | WARNING  | metagpt.utils.cost_manager:update_cost:49 - Model GLM-4-flash not found in TOKEN_COSTS.
2024-12-15 16:53:30.843 | INFO     | __main__:_act:91 - teacher : - The opening line sets a beautiful scene, but consider a more poetic turn of phrase to enhance the velvet night's description.
- The metaphor of the moon as a "silver knight" is charming, but it might benefit from a touch of historical flair to align with the retro style.
- The description of the moon's glow as "a gentle, silken light" is lovely, but consider a more archaic word choice to enhance the retro feel.
- The crescent moon as a "silver coin" is a clever comparison, but it could be made more poetic with a historical twist.
- The line "A beacon in the darkened sea" is strong, but consider a more evocative word for "beacon" to match the retro style.
- The phrase "a silent story" is effective, but a more archaic term for "story" could add to the poem's historical charm.
- The "celestial lullaby" is a beautiful image, but consider a more poetic and archaic word for "lullaby" to fit the style.
- The final couplet is powerful, but the word "silent sentinel" could be made more poetic and retro.
2024-12-15 16:53:30.845 | INFO     | __main__:_act:63 - xiaoming(Student): ready to WritePoem.
Gossamer shawl of night, moon ascends,
A silvery pageant, knight of the stars.
Its sheen, a tender, silken glow,
Adorns the world with hushed, serene might.A crescent crescent, silvered coin,
It pirouettes in the celestial line.
A lighthouse in the shadowed sea,
Guiding mariners to tranquil, calm sea.Its cycles, a hushed, ancient tale,
Of waxing, waning, and celestial grace.
A celestial lullaby, soft and clear,
Whispers through the silent, starry sky.Oh, moon, your radiance bright,
A timeless ballet in night's enchantment.
A silent sentinel, you stand,
Guarding2024-12-15 16:53:34.630 | WARNING  | metagpt.utils.cost_manager:update_cost:49 - Model GLM-4-flash not found in TOKEN_COSTS.
2024-12-15 16:53:34.631 | INFO     | __main__:_act:69 - student : Gossamer shawl of night, moon ascends,
A silvery pageant, knight of the stars.
Its sheen, a tender, silken glow,
Adorns the world with hushed, serene might.A crescent crescent, silvered coin,
It pirouettes in the celestial line.
A lighthouse in the shadowed sea,
Guiding mariners to tranquil, calm sea.Its cycles, a hushed, ancient tale,
Of waxing, waning, and celestial grace.
A celestial lullaby, soft and clear,
Whispers through the silent, starry sky.Oh, moon, your radiance bright,
A timeless ballet in night's enchantment.
A silent sentinel, you stand,
Guarding dreams and tranquil land.dreams and tranquil land.'\nHuman: wirte a poem about moon\nStudent: Glimmering in the velvet night,\nThe moon ascends, a silver knight.\nIts glow, a gentle, silken light,\nAdorns the world with quiet might.\n\nA crescent curve, a silver coin,\nIt dances in the starry line.\nA beacon in the darkened sea,\nGuiding ships to safe, calm sea.\n\nIts phases, a silent story,\nOf waxing, waning, and the glory.\nA celestial lullaby,\nWhispers through the silent sky.\n\nOh, moon, your beauty bright,\nA timeless dance in the night\'s delight.\nA silent sentinel, you stand,\nGuarding dreams and silent land.\nTeacher: - The opening line sets a beautiful scene, but consider a more poetic turn of phrase to enhance the velvet night\'s description.\n- The metaphor of the moon as a "silver knight" is charming, but it might benefit from a touch of historical flair to align with the retro style.\n- The description of the moon\'s glow as "a gentle, silken light" is lovely, but consider a more archaic word choice to enhance the retro feel.\n- The crescent moon as a "silver coin" is a clever comparison, but it could be made more poetic with a historical twist.\n- The line "A beacon in the darkened sea" is strong, but consider a more evocative word for "beacon" to match the retro style.\n- The phrase "a silent story" is effective, but a more archaic term for "story" could add to the poem\'s historical charm.\n- The "celestial lullaby" is a beautiful image, but consider a more poetic and archaic word for "lullaby" to fit the style.\n- The final couplet is powerful, but the word "silent sentinel" could be made more poetic and retro.\nStudent: Gossamer shawl of night, moon ascends,\nA silvery pageant, knight of the stars.\nIts sheen, a tender, silken glow,\nAdorns the world with hushed, serene might.\n\nA crescent crescent, silvered coin,\nIt pirouettes in the celestial line.\nA lighthouse in the shadowed sea,\nGuiding mariners to tranquil, calm sea.\n\nIts cycles, a hushed, ancient tale,\nOf waxing, waning, and celestial grace.\nA celestial lullaby, soft and clear,\nWhispers through the silent, starry sky.\n\nOh, moon, your radiance bright,\nA timeless ballet in night\'s enchantment.\nA silent sentinel, you stand,\nGuarding dreams and tranquil land.'

代码解释

代码模拟了一个简单的对话环境,其中包括一个学生(Student)和一个老师(Teacher),他们在这个环境中交互,目的是创作和评审一首关于特定主题的诗歌。以下是代码的主要组成部分和它们的功能:

1. 导入模块:

  • asyncio:用于编写并发代码。
  • metagpt.actions、metagpt.logs、metagpt.roles、metagpt.schema、metagpt.environment、metagpt.const:这些模块是自定义的,用于定义行动(Action)、日志记录(logger)、角色(Role)、消息(Message)、环境(Environment)和常量(const)。

2. 环境设置:

  • classroom = Environment():创建一个对话环境的实例。

3. 定义行动(Action):

  • WritePoem:一个行动,用于生成诗歌。
  • ReviewPoem:一个行动,用于评审诗歌并给出修改建议。

4. 定义角色(Role):

  • Student:学生角色,可以执行WritePoem行动,并监听UserRequirement和ReviewPoem。
  • Teacher:老师角色,可以执行ReviewPoem行动,并监听WritePoem。

5. 学生和老师的行为:

  • Student的_act方法:学生根据历史对话记录生成一首诗。
  • Teacher的_act方法:老师根据历史对话记录评审诗歌并给出建议。

6. 主函数(main):

main函数接受一个主题(topic)和轮数(n_round),在对话环境中添加学生和老师角色,发布一个由人类提出的主题消息,然后运行对话环境n_round次。

7. 运行主函数:

await main(topic=‘wirte a poem about moon’):这是程序的入口点,它启动了对话环境,并设置主题为“wirte a poem about moon”。(拼写错误,应该是"write a poem about moon")。

参考链接:https://deepwisdom.feishu.cn/wiki/MLILw0EdRiyiYRkJLgOcskyAnUh

http://www.yayakq.cn/news/317932/

相关文章:

  • 淘宝客需要自己做网站吗下载百度 安装
  • 无锡网站建设推荐智勇房地产销售头像
  • 大连提高网站排名外贸人才网属于什么电子商务模式
  • 做网站的系统制作图片的软件及特点
  • 网站开发流程图和宁夏 网站制作
  • 传媒的域名做个什么网站网站建设的职业叫什么
  • 六安网站制作济宁百度推广公司
  • 做网站没流量正规重庆妇科医院
  • 网站开发算互联网公司吗响应式网站模板多少钱
  • 南京建设网站内容自适应网站的代表
  • 家具东莞网站建设技术支持一台vps主机可以建设多少个网站
  • 惊艳的网站设计山东网优
  • 手机如何创网站网站建设咨询客户话术
  • 中国建设银行网站-个人客户廊坊seo优化排名
  • 微网站建设包含哪些内容做基网站
  • 网站开发找谁哈尔滨建站怎么做
  • 如何利用源码做网站免费建立网站
  • dw做网站小技巧劲松网站建设
  • 聊城网站优化网络推广福田做网站需要多少钱
  • 最低价做网站企业网页
  • 网站和系统哪个好做删除wordpress首页链接
  • 网站注入木马飓风算法恢复的网站
  • 帮人做网站赚多少钱163邮箱注册
  • 网站黑色代码百度怎么做网站广告
  • 个人网站排行做网站留后门是怎么回事
  • 有什么做C语言的网站网上国网推广宣传语
  • 社区微网站建设方案ppt模板下载深圳办公室装修公司哪家好
  • 网站规划的基本内容有哪些网站被百度k
  • 璧山网站建设手机无法访问wordpress
  • 企业网站优化的方式搜索引擎优化步骤