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

网络公司网站程序怎样查询网站建设时间

网络公司网站程序,怎样查询网站建设时间,wordpress 更改ip,小企业网站建设厂家有哪些在 【AI的未来 - AI Agent系列】【MetaGPT】2. 实现自己的第一个Agent 中#xff0c;我们已经实现了一个简单的Agent#xff0c;实现的功能就是顺序打印数字。 文章目录 0. 本文实现内容1. 实现思路2. 完整代码及细节注释 0. 本文实现内容 今天我们来实现一个有实际意义的Ag…在 【AI的未来 - AI Agent系列】【MetaGPT】2. 实现自己的第一个Agent 中我们已经实现了一个简单的Agent实现的功能就是顺序打印数字。 文章目录 0. 本文实现内容1. 实现思路2. 完整代码及细节注释 0. 本文实现内容 今天我们来实现一个有实际意义的Agent - 实现一个技术文档助手用户只需要输入技术文档的标题例如“Git教程”Agent自动将Git教程写成文档分目录分块条理清晰并有代码示例。 先看下要实现的效果全程用户只需要输入“Git 教程” MarkDown格式分目录一级标题、二级标题有代码示例 1. 实现思路 因为token限制的原因我们先通过 LLM 大模型生成教程的目录再对目录按照二级标题进行分块对于每块目录按照标题生成详细内容最后再将标题和内容进行拼接解决 LLM 大模型长文本的限制问题。 整体流程如下下图来自《MetaGPT智能体开发入门》 分析上述流程图我们需要实现 生成文档大纲的ActionWriteDirectory子任务的ActionWriteContent在得到文档大纲之后要对大纲进行拆分本例按目录进行拆分然后根据拆分内容动态添加子任务Action让子任务去根据目录写技术文档的内容将子任务Action生成的内容最后做拼接形成最终的MarkDown文档 2. 完整代码及细节注释 直接放出完整代码代码中添加了一些细节注释来帮助你理解用的MetaGPT 0.5.2版本。建议你一定要实操一遍因为不实操你永远不知道自己会遇到多少坑… 代码并不复杂 WriteDirectory的实现基本就是我们把自己的需求放入我们准备好的提示词模板里询问大模型得到结果然后我们对得到的内容做一个解析。数据格式化WriteContent的实现直接根据传入的子标题内容调用大模型生成回答 # 加载 .env 到环境变量 from dotenv import load_dotenv, find_dotenv _ load_dotenv(find_dotenv())from datetime import datetime from typing import Dict import asyncio from metagpt.actions.write_tutorial import WriteDirectory, WriteContent from metagpt.const import TUTORIAL_PATH from metagpt.logs import logger from metagpt.roles import Role from metagpt.schema import Message from metagpt.utils.file import File import fire import timefrom typing import Dictfrom metagpt.actions import Action from metagpt.prompts.tutorial_assistant import DIRECTORY_PROMPT, CONTENT_PROMPT from metagpt.utils.common import OutputParser## 1. 生成文档大纲目录 class WriteDirectory(Action):Action class for writing tutorial directories.Args:name: The name of the action.language: The language to output, default is Chinese.def __init__(self, name: str , language: str Chinese, *args, **kwargs):super().__init__(name, *args, **kwargs)self.language languageasync def run(self, topic: str, *args, **kwargs) - Dict:COMMON_PROMPT You are now a seasoned technical professional in the field of the internet. We need you to write a technical tutorial with the topic {topic}.DIRECTORY_PROMPT COMMON_PROMPT Please provide the specific table of contents for this tutorial, strictly following the following requirements:1. The output must be strictly in the specified language, {language}.2. Answer strictly in the dictionary format like {{title: xxx, directory: [{{dir 1: [sub dir 1, sub dir 2]}}, {{dir 2: [sub dir 3, sub dir 4]}}]}}.3. The directory should be as specific and sufficient as possible, with a primary and secondary directory.The secondary directory is in the array.4. Do not have extra spaces or line breaks.5. Each directory title has practical significance.prompt DIRECTORY_PROMPT.format(topictopic, languageself.language)resp await self._aask(promptprompt)return OutputParser.extract_struct(resp, dict) ## 1.1 对结果进行校验必须符合Dict结构否则报错## 2. 子任务Action这里是根据拆分的目录标题写技术文档内容 class WriteContent(Action):Action class for writing tutorial content.Args:name: The name of the action.directory: The content to write.language: The language to output, default is Chinese.def __init__(self, name: str , directory: str , language: str Chinese, *args, **kwargs):super().__init__(name, *args, **kwargs)self.language languageself.directory directoryasync def run(self, topic: str, *args, **kwargs) - str:COMMON_PROMPT You are now a seasoned technical professional in the field of the internet. We need you to write a technical tutorial with the topic {topic}.CONTENT_PROMPT COMMON_PROMPT Now I will give you the module directory titles for the topic. Please output the detailed principle content of this title in detail. If there are code examples, please provide them according to standard code specifications. Without a code example, it is not necessary.The module directory titles for the topic is as follows:{directory}Strictly limit output according to the following requirements:1. Follow the Markdown syntax format for layout.2. If there are code examples, they must follow standard syntax specifications, have document annotations, and be displayed in code blocks.3. The output must be strictly in the specified language, {language}.4. Do not have redundant output, including concluding remarks.5. Strict requirement not to output the topic {topic}.prompt CONTENT_PROMPT.format(topictopic, languageself.language, directoryself.directory)return await self._aask(promptprompt)## 3. 技术文档角色用来执行Action class TutorialAssistant(Role):def __init__(self,name: str Stitch,profile: str Tutorial Assistant,goal: str Generate tutorial documents,constraints: str Strictly follow Markdowns syntax, with neat and standardized layout,language: str Chinese,):super().__init__(name, profile, goal, constraints)self._init_actions([WriteDirectory(languagelanguage)]) ## 3.1 初始化时先只添加WriteDirectory Action生成目录。WriteContent Action后面根据目录动态添加这里你也不知道要添加多少个添加的内容是什么。self.topic self.main_title ## 3.2 记录文章题目self.total_content ## 3.3 生成的所有内容拼接到这里self.language languageasync def _think(self) - None:Determine the next action to be taken by the role.if self._rc.todo is None:self._set_state(0) ## 3.4 转到第一个Action执行returnif self._rc.state 1 len(self._states):self._set_state(self._rc.state 1) ## 3.5 将要执行下一个Actionelse:self._rc.todo None## 3.6 根据生成的目录拆分出一级标题和二级标题动态添加到WriteContent Action中输入的titles必须是Dict类型这就要求WriteDirectory的输出必须能按Dict类型解析否则报错程序无法继续执行。async def _handle_directory(self, titles: Dict) - Message:self.main_title titles.get(title)directory f{self.main_title}\nself.total_content f# {self.main_title}actions list()for first_dir in titles.get(directory):actions.append(WriteContent(languageself.language, directoryfirst_dir)) ## 3.7 动态添加 WriteContent Action将一级目录内容传入key list(first_dir.keys())[0]directory f- {key}\nfor second_dir in first_dir[key]:directory f - {second_dir}\nself._init_actions(actions) ## 3.8 执行了这一句此时动作列表全是WriteContent了self._rc.todo Nonereturn Message(contentdirectory)async def _act(self) - Message:Perform an action as determined by the role.Returns:A message containing the result of the action.time.sleep(20) ## 3.9 这是为了避免OpenAI接口调用频率限制不是办法的办法todo self._rc.todoif type(todo) is WriteDirectory: msg self._rc.memory.get(k1)[0] ## 3.10 获取记忆这里是获取用户输入因为任何动作都还没执行所以只有用户输入self.topic msg.contentresp await todo.run(topicself.topic) ## 3.11 根据用户输入生成目录logger.info(resp)return await self._handle_directory(resp)resp await todo.run(topicself.topic) ## 3.12 走到这里的都是WriteContent Action。 这里的self.topic还是用户输入因为并没有其它地方更新该值。这里传入的目的是让WriteContent写的内容以这个为范围限制logger.info(resp)if self.total_content ! :self.total_content \n\n\nself.total_content resp ## 3.13 拼接数据return Message(contentresp, roleself.profile)async def _react(self) - Message:Execute the assistants think and actions.Returns:A message containing the final result of the assistants actions.while True:await self._think()if self._rc.todo is None:breakmsg await self._act()## 3.14 全部Action执行完毕写文件root_path TUTORIAL_PATH / datetime.now().strftime(%Y-%m-%d_%H-%M-%S)await File.write(root_path, f{self.main_title}.md, self.total_content.encode(utf-8))return msgasync def main():msg Git 教程role TutorialAssistant()logger.info(msg)result await role.run(msg)logger.info(result)asyncio.run(main())
http://www.zqtcl.cn/news/167287/

相关文章:

  • 网站建设最简单的教程视频教程建设厅注册中心网站首页
  • 免费做网站凡科wordpress 分享到微信 插件
  • 购物网站项目建设内容有啥网站是专做时尚穿搭
  • 网上下载的网站模板怎么用wordpress 注册密码
  • 网站建设免费国外撤销网站备案申请书
  • 佛山做网站那家好网站建设公司如何盈利
  • 傻瓜建网站设计感网站
  • 北京网站优化软件陕西省建筑信息平台
  • 广州越秀建网站济南房产网新开楼盘
  • 线上咨询预约网站建设方案保定外贸网站制作
  • 网站流量如何增加提高工作效率的措施
  • 龙湖镇华南城网站建设.net 网站开发书籍
  • 域名费用和网站服务器费用是同样的吗推广营销方案
  • 安徽网站设计方案中文外贸网站有哪些
  • 衡阳手机网站设计响应式网站做多大的尺寸
  • 海尔电子商务网站建设预算灵台县门户网
  • 四川网站建设设计公司排名开发公司与建筑公司合作协议
  • 江西智能网站建设嘉定注册公司
  • 海口网站建设联系方式十大免费软文推广平台
  • 石碣镇做网站帮别人做网站开价
  • 站长 网站ip客户都不愿意做网站
  • 网站开发和软件开发哪个难网站备案账号
  • 2昌平区网站建设安徽盛绿建设网站
  • 商务网站建设目的天津建设网站需要的费用
  • flash 网站头部wordpress支持大文件上传
  • 网站开发方式的选择凡客设计
  • 常德建设网站如何查询某个网站的设计公司
  • wordpress 仿站教程学校ui设计培训
  • 南昌模板建站定制网站合肥瑶海区网站建设价格
  • 奥尔马手表官方网站导出wordpress文章