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

想做网站濮阳网站建设优秀的设计网站有哪些

想做网站濮阳网站建设,优秀的设计网站有哪些,如果制作一个自己的网站,世界军事新闻介绍 大家好#xff0c;博主又来给大家分享知识了。这次又要给大家分享什么呢#xff1f;哈哈。这次要给大家分享的是微软AutoGen框架的高级且重要的功能#xff1a;Memory。在微软AutoGen中#xff0c;Memory(记忆)是一个重要概念#xff0c;它主要用于存储和管理智能体…介绍 大家好博主又来给大家分享知识了。这次又要给大家分享什么呢哈哈。这次要给大家分享的是微软AutoGen框架的高级且重要的功能Memory。在微软AutoGen中Memory(记忆)是一个重要概念它主要用于存储和管理智能体之间交互的历史信息有助于智能体在对话和协作过程中参考过往内容以更智能地推进任务。那我们直接进入正题。 Memory 在几种用例中维护一个有用事实的存储库是很有价值的这些事实能在特定步骤即将开始前被智能地添加到智能体的上下文中。这里的典型用例是检索增强生成(RAG)模式在这种模式下一个查询被用于从数据库中检索相关信息然后这些信息会被添加到智能体的上下文中。 AgentChat提供了一种记忆协议该协议可以进行扩展以实现这一功能。其关键方法包括查询(query)、更新上下文(update_context)、添加(add)、清除(clear)和关闭(close)。 添加(add)向记忆存储中添加新的条目。查询(query)从记忆存储中检索相关信息。更新上下文(update_context)通过添加检索到的信息来改变智能体的内部模型上下文(在助理智能体类中使用)。清除(clear)从记忆存储中清除所有条目。关闭(close)清理记忆存储所使用的任何资源。 ListMemory示例 Python类autogen_core.memory.ListMemory作为Python类autogen_core.memory.Memory协议的一个示例实现被提供。它是一个基于简单列表的记忆实现方式按时间顺序保存记忆内容将最新的记忆添加到模型的上下文中。这种实现方式设计得简单直接且具有可预测性便于理解和调试。我们通过一个示例来演示我们将使用ListMemory来维护一个用户偏好的记忆库并展示随着时间推移它如何被用来为智能体的回复提供一致的上下文信息。 完整代码 import asyncio from autogen_agentchat.agents import AssistantAgent from autogen_agentchat.ui import Console from autogen_core.memory import ListMemory, MemoryContent, MemoryMimeType from autogen_ext.models.openai import OpenAIChatCompletionClient# 初始化用户记忆 user_memory ListMemory()async def get_weather(city: str, units: str imperial) - str:if units imperial:return fThe weather in {city} is 73 °F and Sunny.elif units metric:return fThe weather in {city} is 23 °C and Sunny.else:return fSorry, I dont know the weather in {city}.async def run_stream() - None:# 将用户偏好添加到记忆中await user_memory.add(MemoryContent(contentThe weather should be in metric units, mime_typeMemoryMimeType.TEXT))await user_memory.add(MemoryContent(contentMeal recipe must be vegan, mime_typeMemoryMimeType.TEXT))assistant_agent AssistantAgent(nameassistant_agent,model_clientOpenAIChatCompletionClient(modelgpt-4o,),tools[get_weather],memory[user_memory],)stream assistant_agent.run_stream(taskWhat is the weather in Beijing?)await Console(stream)asyncio.run(run_stream()) 运行结果 ---------- user ---------- What is the weather in Beijing? ---------- assistant_agent ---------- [MemoryContent(contentThe weather should be in metric units, mime_typeMemoryMimeType.TEXT: text/plain, metadataNone), MemoryContent(contentMeal recipe must be vegan, mime_typeMemoryMimeType.TEXT: text/plain, metadataNone)] ---------- assistant_agent ---------- [FunctionCall(idcall_pHq4p89gW6oGjGr3VsVETCYX, arguments{city:Beijing,units:metric}, nameget_weather)] ---------- assistant_agent ---------- [FunctionExecutionResult(contentThe weather in Beijing is 23 °C and Sunny., call_idcall_pHq4p89gW6oGjGr3VsVETCYX)] ---------- assistant_agent ---------- The weather in Beijing is 23 °C and Sunny.进程已结束退出代码为 0 我们可以查看发现assistant_agent的模型上下文实际上已用检索到的记忆条目进行了更新。transform方法被用于将检索到的记忆条目格式化为可供智能体使用的字符串。在这种情况下我们只是简单地将每个记忆条目的内容连接成一个单一的字符串。 从上述内容我们可以看到正如用户偏好中所要求的那样天气信息是以摄氏度为单位返回的。 同样地假设我们另外提出一个关于制定一份餐食计划的问题智能体能够从记忆存储中检索到相关信息并给出个性化的回复。 完整代码 import asyncio from autogen_agentchat.agents import AssistantAgent from autogen_agentchat.ui import Console from autogen_core.memory import ListMemory, MemoryContent, MemoryMimeType from autogen_ext.models.openai import OpenAIChatCompletionClient# 初始化用户记忆 user_memory ListMemory()async def get_weather(city: str, units: str imperial) - str:if units imperial:return fThe weather in {city} is 73 °F and Sunny.elif units metric:return fThe weather in {city} is 23 °C and Sunny.else:return fSorry, I dont know the weather in {city}.async def run_stream() - None:# 将用户偏好添加到记忆中await user_memory.add(MemoryContent(contentThe weather should be in metric units, mime_typeMemoryMimeType.TEXT))await user_memory.add(MemoryContent(contentMeal recipe must be vegan, mime_typeMemoryMimeType.TEXT))assistant_agent AssistantAgent(nameassistant_agent,model_clientOpenAIChatCompletionClient(modelgpt-4o,),tools[get_weather],memory[user_memory],)await assistant_agent._model_context.get_messages()stream assistant_agent.run_stream(taskWrite brief meal recipe with broth)await Console(stream)asyncio.run(run_stream()) 运行结果 ---------- user ---------- Write brief meal recipe with broth ---------- assistant_agent ---------- [MemoryContent(contentThe weather should be in metric units, mime_typeMemoryMimeType.TEXT: text/plain, metadataNone), MemoryContent(contentMeal recipe must be vegan, mime_typeMemoryMimeType.TEXT: text/plain, metadataNone)] ---------- assistant_agent ---------- Heres a simple vegan meal recipe using broth:**Vegan Vegetable Soup****Ingredients:** - 1 liter vegetable broth - 1 cup chopped carrots - 1 cup chopped celery - 1 cup diced tomatoes - 1 cup chopped zucchini - 1 cup cooked chickpeas (optional) - 2 cloves garlic, minced - 1 tablespoon olive oil - Salt and pepper to taste - Fresh parsley for garnish**Instructions:** 1. Heat olive oil in a large pot over medium heat. 2. Add minced garlic and sauté until fragrant (about 1 minute). 3. Add carrots, celery, zucchini, and diced tomatoes to the pot. Stir and cook for 5 minutes. 4. Pour in the vegetable broth and bring it to a boil. 5. Lower the heat and let the soup simmer for 20–25 minutes, until the vegetables are tender. 6. Add cooked chickpeas (if using), and season with salt and pepper. 7. Garnish with fresh parsley before serving. Enjoy your warm vegan vegetable soup! TERMINATE进程已结束退出代码为 0 自定义记忆存储(向量数据库等) 我们可以基于记忆协议来实现更复杂的记忆存储方式。例如我们可以实现一个自定义的记忆存储系统利用向量数据库来存储和检索信息或者创建一个使用机器学习模型的记忆存储系统以便根据用户的偏好等生成个性化的回复。 具体来说我们需要重载add、query和update_context方法以实现所需的功能并将记忆存储传递给你的智能体。 完整代码 import asyncio from typing import Any from autogen_agentchat.agents import AssistantAgent from autogen_agentchat.ui import Console from autogen_core import CancellationToken from autogen_core.memory import Memory, MemoryContent, MemoryMimeType, UpdateContextResult from autogen_core.model_context import ChatCompletionContext from autogen_ext.models.openai import OpenAIChatCompletionClient# 自定义记忆存储类 class CustomMemory(Memory):def __init__(self):self.memory_store []async def add(self, entry: MemoryContent, cancellation_token: CancellationToken | None None) - None:self.memory_store.append(entry)print(fAdded entry: {entry.content})async def query(self, query_str: str | MemoryContent, cancellation_token: CancellationToken | None None,**kwargs: Any) - list[Any]:passasync def update_context(self, agent: ChatCompletionContext) - UpdateContextResult:passasync def clear(self):self.memory_store []print(Memory store cleared)async def close(self):print(Memory store closed)async def get_weather(city: str, units: str imperial) - str:if units imperial:return fThe weather in {city} is 73 °F and Sunny.elif units metric:return fThe weather in {city} is 23 °C and Sunny.else:return fSorry, I dont know the weather in {city}.async def run_stream() - None:# 初始化自定义用户记忆user_memory CustomMemory()# 将用户偏好添加到记忆中await user_memory.add(MemoryContent(contentThe weather should be in metric units, mime_typeMemoryMimeType.TEXT))await user_memory.add(MemoryContent(contentMeal recipe must be vegan, mime_typeMemoryMimeType.TEXT))assistant_agent AssistantAgent(nameassistant_agent,model_clientOpenAIChatCompletionClient(modelgpt-4o,),tools[get_weather],memory[user_memory],)await assistant_agent._model_context.get_messages()stream assistant_agent.run_stream(taskWrite brief meal recipe with broth)await Console(stream)asyncio.run(run_stream()) 运行结果 Added entry: The weather should be in metric units Added entry: Meal recipe must be vegan ---------- user ---------- Write brief meal recipe with broth ---------- assistant_agent ---------- **Chicken Broth Soup****Ingredients:** - 4 cups chicken broth - 1 cup shredded cooked chicken - 1 cup chopped vegetables (carrots, celery, peas) - 1/2 cup small pasta or rice - 1-2 garlic cloves (minced) - Salt and pepper to taste - 1 tbsp olive oil**Instructions:** 1. In a pot, heat olive oil over medium heat and sauté garlic until fragrant. 2. Add vegetables and cook for 2-3 minutes. 3. Pour in chicken broth and bring to a boil. 4. Add pasta or rice and cook according to package directions. 5. Stir in shredded chicken, season with salt and pepper, and simmer for 5-10 minutes. 6. Serve hot and enjoy!TERMINATE进程已结束退出代码为 0 说明 如果大家在运行上述代码的时候有AutoGen相关的提示或报错(例如该参数不存在没有此类方法等)请尝试更新一下AutoGen博主在分享这篇博文的时候AutoGen的版本是0.4.6稳定版。 安装或更新命令 pip install -U autogen-agentchat autogen-ext[openai,azure] 另外大家要根据业务需求设置使用的LLM不一定要按照我给大家分享代码中的设置来如果只是为了测试并看运行结果可直接复制粘贴代码(完整代码)。 结束 好了以上就是本次分享的全部内容细心的小伙伴可能会发现该功能有点类似于之前博主给大家分享的Managing State(管理状态)机制。那么它们二者之间的区别是什么呢博主在这里给大家整理如下 在微软的AutoGen框架中Memory和Managing State机制在功能和应用场景上存在一些区别。 Memory 功能特性Memory主要用于存储和检索与交互过程相关的信息它提供了一种结构化的方式来保存历史对话、用户偏好、任务相关的上下文等内容。通过记忆功能智能体可以参考之前的交互信息从而在后续的对话或任务处理中提供更连贯、更符合上下文的回复。例如用户在之前的对话中提到了自己喜欢的食物类型如素食记忆模块可以存储这个信息当后续询问关于餐食推荐的问题时智能体能够从记忆中检索到该信息并据此给出合适的建议。接口和方法Memory通常定义了一系列接口和方法如add(添加记忆条目)、query(根据特定条件检索记忆条目)、update_context(将检索到的记忆信息更新到智能体的上下文)等。这些方法使得开发者可以方便地操作记忆存储实现对记忆数据的管理和利用。比如通过add方法可以将新的用户输入或重要信息添加到记忆中query方法则可以根据关键词或其他条件从记忆中查找相关的历史记录。应用场景主要应用于多轮对话场景帮助智能体维护对话的上下文连贯性提升对话质量也适用于需要记住用户特定偏好、设置等信息的场景以便为用户提供个性化的服务。例如在智能客服系统中记忆功能可以记录用户之前反馈的问题和解决方案当用户再次咨询类似问题时客服智能体能够快速给出准确的答复。 Managing State 功能特性Managing State机制更侧重于管理智能体在执行任务过程中的整体状态信息。这包括任务的当前阶段、已经执行的操作、任务的目标和约束条件等。它关注的是智能体在处理复杂任务时的状态流转和协调确保智能体能够按照正确的流程和逻辑完成任务。例如在一个涉及多个步骤的任务(如策划一次旅行包括选择目的地、预订机票、酒店等步骤)中管理状态机制会记录每个步骤的完成情况和相关的状态信息以便智能体能够合理地推进后续操作。实现方式管理状态可能涉及到状态机、状态变量的维护和更新等技术手段。通过定义不同的状态和状态转换规则智能体可以根据当前的任务状态决定下一步的行动。例如当智能体处于 “预订机票” 的状态时它会执行与机票预订相关的操作如查询航班信息、选择合适的航班等并在预订成功后更新状态为 “机票已预订”。应用场景主要应用于复杂任务的执行和管理如工作流自动化、多步骤问题解决等场景。在这些场景中智能体需要根据不同的状态来协调多个子任务的执行确保任务能够顺利完成。例如在一个项目管理智能体中管理状态机制可以跟踪项目的各个阶段(如规划、执行、监控等)并根据项目状态做出相应的决策和调整。 综上所述Memory主要聚焦于存储和利用交互历史和上下文信息而Managing State更关注智能体在任务执行过程中的状态管理和协调两者在AutoGen中分别承担着不同但又相互关联的重要角色共同支持智能体的高效运行和复杂任务处理。 通过本次分享大家有所收获吗请大家多去大胆的尝试和使用。博主还是那句话成功总是在不断的失败中试验出来的敢于尝试就已经成功了一半。这次分享就到这如果大家对博主分享的内容感兴趣或有帮助请点赞和关注。大家的点赞和关注是博主持续分享的动力博主也希望让更多的人学习到新的知识。
http://www.hkea.cn/news/14399793/

相关文章:

  • 兰州西固区公司网站建设浙江中联建设集团有限公司网站
  • 骨科医院网站模板营销型网站有哪些特点
  • 京东网站建设的目的贵州两学一做教育网站
  • 网站版面设计流程包括哪些营销策略4p
  • 太原市建设工程招投标信息网站响应式网站 拖拽
  • 网站建设是必须的吗网投怎么做网站
  • 网站建设及优化 赣icp某公司网页设计
  • 东营的招聘网站哪个有用毕业设计做课程网站好
  • 简约式网站淘宝上做网站怎么样
  • 建设营销网站做网站济南西
  • 网站建设温州网站建设论文ppt
  • 免费隐私网站推广广东seo价格是多少钱
  • 竹子系统做的网站可以优化么广告行业做网站哪个好
  • 哈密建设局网站网站建设方式优化
  • 辉县市工程建设网站建设h5小游戏在线玩
  • 柳州专业做网站wap网站为什么没有了
  • 网站建设包含哪些费用qq空间主页制作网站
  • 临沂购买模板建站网站502 解决办法
  • 范例网站怎么做深圳百度关键词推广
  • 厦门海绵城市建设官方网站做外贸做的很好的网站
  • 帮朋友做网站wordpress html模式
  • 建站是什么东西图片在线设计平台
  • 吉祥物设计网站厦门网站建设合同
  • 建设银行温州支行官方网站网站开发科普书
  • 网站漂浮怎么做惠州seo按天计费
  • 无锡做企业网站西安编程培训机构
  • 做ios试玩推广网站wordpress 腾讯
  • 商城网站建设的步骤开外贸公司的流程及费用
  • 云南网络网站推广外贸网站交易平台
  • 工地招聘网站自建网站外贸怎么做