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

家庭网络组建方案武汉seo招聘网

家庭网络组建方案,武汉seo招聘网,个人主页设计html代码,文字头像在线制作免费生成图片在 LangChain 的 Agent 系统中,Zero-shot ReAct Agent为最基础的Agent,文本对其进行介绍。 ​☎️ 核心特征: 基于 ReAct(Reasoning Acting)框架 无记忆机制,每次请求独立处理 默认使用 llm-math 和 wiki…

在 LangChain 的 Agent 系统中,Zero-shot ReAct Agent为最基础的Agent,文本对其进行介绍。

在这里插入图片描述

​☎️ 核心特征:

基于 ReAct(Reasoning + Acting)框架
无记忆机制,每次请求独立处理
默认使用 llm-math 和 wikipedia 工具

​☎️ 工作流程:

Thought → Action → Observation → Final Answer

🧠 原理:Zero-shot ReAct Agent 会根据工具描述自己决定是否调用工具,零样本地推理动作和思考。

​☎️ 案例:计算一连串数字相加

笔者通过Ollama运行了如下模型

NAME                ID              SIZE      MODIFIED
llama3:latest       365c0bd3c000    4.7 GB    2 weeks ago
deepseek-r1:1.5b    a42b25d8c10a    1.1 GB    2 weeks ago

案例代码:

import re
from langchain.prompts import PromptTemplate
from langchain.agents import initialize_agent, AgentType
from langchain.tools import Tool
from langchain_ollama import ChatOllamadef add_numbers(text: str) -> str:pattern = r"-?(?:\d+\.\d+|\.\d+|\d+)(?=\D|$)"numbers = []# 抽取所有数字并求和for num_str in re.findall(pattern, text):# 处理以点开头的数字(如 .56 → 0.56)if num_str.startswith('.'):num_str = '0' + num_str# 转换数值类型try:if '.' in num_str:numbers.append(float(num_str))else:numbers.append(int(num_str))except ValueError:continue  # 跳过无效格式(如空字符串)# 无论numbers中有多少个数字,都计算所有数的和if len(numbers) > 0:return str(sum(numbers))else:return str(0)# 定义一个工具,用于计算一连串数字相加
calculator_tool = Tool(name="MyCalculator",func=add_numbers,description="用于计算一连串数字相加,输入应是带有多个数字的字符串。"
)# 初始化 LLM
llm = ChatOllama(model = "llama3",temperature = 0,base_url="http://localhost:11434"
)# 定义提示词模板
template = """
请严格按照以下格式响应,只能使用中文:
Thought: 你的思考过程
Action: 可用的工具名称
Action Input: 工具的输入内容例如:
Thought: 我需要先查询天气
Action: Search
Action Input: 北京今日天气优先使用工具,以最少的步数完成任务。现在开始回答:
{input}
"""prompt = PromptTemplate.from_template(template)# 创建 agent
agent = initialize_agent(tools=[calculator_tool],  llm=llm,agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,  # 采用 ReAct 机制verbose=True,prompt=prompt,handle_parsing_errors=True
)query = "12、23、45、20相加的和是多少?"
print(agent.invoke(query))

运行结果

> Entering new AgentExecutor chain...
Let's get started.Thought: Since we have a string of numbers separated by commas, we can use MyCalculator to calculate the sum. We'll need to split the string into individual numbers and then add them up.Action: Use MyCalculator
Action Input: 12,23,45,20
Observation: Use MyCalculator is not a valid tool, try one of [MyCalculator].
Thought:I think I see what's going on here!Thought: Hmm, it looks like the action "Use MyCalculator" isn't actually using the MyCalculator function. Let me try again.Action: MyCalculator
Action Input: 12,23,45,20
Observation: 100
Thought:Let's continue from where we left off!Thought: Now that we've successfully used the MyCalculator function, let's think about what to do next.Action: None (we're done with this part!)Thought: Since we've already calculated the sum using MyCalculator, there's no need to do anything else. We can just move on to the final answer!Thought: I now know the final answerFinal Answer: 100> Finished chain.
{'input': '12、23、45、20相加的和是多少?', 'output': '100'}
http://www.dtcms.com/wzjs/1377.html

相关文章:

  • 网站做任务赚佣金沈阳cms模板建站
  • 央企做的好的网站武汉seo网站优化排名
  • 局域网内服务器做网站2023最近的新闻大事10条
  • 网站模板使用磁力最好用的搜索引擎
  • 北京网站制作一般多少钱西安疫情最新消息1小时内
  • 网站建设及推广服务的合同范本app制作一个需要多少钱
  • 给网站做解答是干嘛的制作app平台需要多少钱
  • 可以自己买个服务器做网站吗太原网站制作推广
  • 建设网站比较好公司吗线上推广渠道
  • 24小时学会网站建设seo教学
  • 比较好用的免费素材网长沙网站seo优化排名
  • 做灯箱到哪个网站找业务seo外链平台
  • 网络管理系统页面武汉百度搜索优化
  • 做网站加盟简述网站建设流程
  • 网站开发需要什么开发工具营销网站建设教学
  • 线上WordPress移到本地网络优化大师手机版
  • 制作软件的网站神马关键词快速排名软件
  • 网站建设遵循原则网络工具
  • 建设银行宁波分行招聘网站关键词的优化和推广
  • 有什么网站可以做电子如何让百度快速收录网站文章
  • 用什么软件做网站seo好链接推广平台
  • 做类似简书的网站360安全网址
  • 网站要什么软件做东莞网站公司哪家好
  • 一级域名免费网站怎么申请短视频seo询盘获客系统
  • 怎么做和京东一样网站泉州全网营销推广
  • 网站开发怎么学习全网品牌推广公司
  • 淘宝网站怎样做深圳网站优化推广
  • wordpress命令安装目录结构seo概念的理解
  • 项目网站制作友情链接怎么设置
  • php房产中介网站源码综合权重查询