LangChain-25 ReAct 让大模型自己思考和决策下一步 AutoGPT实现途径、AGI重要里程碑

请添加图片描述

背景介绍

大模型ReAct(Reasoning and Acting)是一种新兴的技术框架,旨在通过逻辑推理和行动序列的构建,使大型语言模型(LLM)能够达成特定的目标。这一框架的核心思想是赋予机器模型类似人类的推理和行动能力,从而在各种任务和环境中实现更高效、更智能的决策和操作。

核心组成

ReAct框架主要由三个关键概念组成:Thought(思考)、Act(行动)、和Obs(观察)。

  • Thought:由LLM模型生成,是LLM产生行为和依据的基础。它代表了模型在面对特定任务时的逻辑推理过程,是决策的前提。
  • Act:指LLM判断本次需要执行的具体行为。这通常涉及选择合适的工具或API,并生成所需的参数,以实现目标行动。
  • Obs:LLM框架对于外界输入的获取,类似于LLM的“五官”,将外界的反馈信息同步给LLM模型,协助模型进一步的做分析或者决策。

安装依赖


Prompt

# Get the prompt to use - you can modify this!
# Answer the following questions as best you can. You have access to the following tools:
#
# {tools}
#
# Use the following format:
#
# Question: the input question you must answer
# Thought: you should always think about what to do
# Action: the action to take, should be one of [{tool_names}]
# Action Input: the input to the action
# Observation: the result of the action
# ... (this Thought/Action/Action Input/Observation can repeat N times)
# Thought: I now know the final answer
# Final Answer: the final answer to the original input question
#
# Begin!
#
# Question: {input}
# Thought:{agent_scratchpad}

编写代码

from langchain import hub
from langchain.agents import AgentExecutor, create_react_agent
from langchain_community.tools.tavily_search import TavilySearchResults
from langchain_openai import OpenAItools = [TavilySearchResults(max_results=1)]
# Get the prompt to use - you can modify this!
# Answer the following questions as best you can. You have access to the following tools:
#
# {tools}
#
# Use the following format:
#
# Question: the input question you must answer
# Thought: you should always think about what to do
# Action: the action to take, should be one of [{tool_names}]
# Action Input: the input to the action
# Observation: the result of the action
# ... (this Thought/Action/Action Input/Observation can repeat N times)
# Thought: I now know the final answer
# Final Answer: the final answer to the original input question
#
# Begin!
#
# Question: {input}
# Thought:{agent_scratchpad}
prompt = hub.pull("hwchase17/react")# Choose the LLM to use
llm = OpenAI(model="gpt-3.5-turbo",temperature=0
)# Construct the ReAct agent
agent = create_react_agent(llm, tools, prompt)
# Create an agent executor by passing in the agent and tools
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)message1 = agent_executor.invoke({"input": "what is LangChain?"})
print(f"message1: {message1}")

执行结果

我们可以看到,大模型自己进行思考,并进行下一步。(详细可看执行日志)

➜ python3 test26.py> Entering new AgentExecutor chain...I should search for LangChain to see what it is
Action: tavily_search_results_json
Action Input: "LangChain"[{'url': 'https://towardsdatascience.com/getting-started-with-langchain-a-beginners-guide-to-building-llm-powered-applications-95fc8898732c', 'content': 'linkedin.com/in/804250ab\nMore from Leonie Monigatti and Towards Data Science\nLeonie Monigatti\nin\nTowards Data Science\nRetrieval-Augmented Generation (RAG): From Theory to LangChain Implementation\nFrom the theory of the original academic paper to its Python implementation with OpenAI, Weaviate, and LangChain\n--\n2\nMarco Peixeiro\nin\nTowards Data Science\nTimeGPT: The First Foundation Model for Time Series Forecasting\nExplore the first generative pre-trained forecasting model and apply it in a project with Python\n--\n22\nRahul Nayak\nin\nTowards Data Science\nHow to Convert Any Text Into a Graph of Concepts\nA method to convert any text corpus into a Knowledge Graph using Mistral 7B.\n--\n32\nLeonie Monigatti\nin\nTowards Data Science\nRecreating Andrej Karpathy’s Weekend Project\u200a—\u200aa Movie Search Engine\nBuilding a movie recommender system with OpenAI embeddings and a vector database\n--\n3\nRecommended from Medium\nKrishna Yogi\nBuilding a question-answering system using LLM on your private data\n--\n6\nRahul Nayak\nin\nTowards Data Science\nHow to Convert Any Text Into a Graph of Concepts\nA method to convert any text corpus into a Knowledge Graph using Mistral 7B.\n--\n32\nLists\nPredictive Modeling w/ Python\nPractical Guides to Machine Learning\nNatural Language Processing\nChatGPT prompts\nOnkar Mishra\nUsing langchain for Question Answering on own data\nStep-by-step guide to using langchain to chat with own data\n--\n10\nAmogh Agastya\nin\nBetter Programming\nHarnessing Retrieval Augmented Generation With Langchain\nImplementing RAG using Langchain\n--\n6\nAnindyadeep\nHow to integrate custom LLM using langchain. This is part 1 of my mini-series: Building end to end LLM powered applications without Open AI’s API\n--\n3\nAkriti Upadhyay\nin\nAccredian\nImplementing RAG with Langchain and Hugging Face\nUsing Open Source for Information Retrieval\n--\n6\nHelp\nStatus\nAbout\nCareers\nBlog\nPrivacy\nTerms\nText to speech\nTeams A Beginner’s Guide to Building LLM-Powered Applications\nA LangChain tutorial to build anything with large language models in Python\nLeonie Monigatti\nFollow\nTowards Data Science\n--\n27\nShare\n GitHub - hwchase17/langchain: ⚡ Building applications with LLMs through composability ⚡\n⚡ Building applications with LLMs through composability ⚡ Production Support: As you move your LangChains into…\ngithub.com\nWhat is LangChain?\nLangChain is a framework built to help you build LLM-powered applications more easily by providing you with the following:\nIt is an open-source project (GitHub repository) created by Harrison Chase.\n --\n--\n27\nWritten by Leonie Monigatti\nTowards Data Science\nDeveloper Advocate @'}] I should read the first search result to learn more about LangChain
Action: tavily_search_results_json
Action Input: "LangChain tutorial"[{'url': 'https://python.langchain.com/docs/get_started/quickstart', 'content': "Once we have a key we'll want to set it as an environment variable by running:\nIf you'd prefer not to set an environment variable you can pass the key in directly via the openai_api_key named parameter when initiating the OpenAI LLM class:\nLangSmith\u200b\nMany of the applications you build with LangChain will contain multiple steps with multiple invocations of LLM calls.\n The fact that LLM and ChatModel accept the same inputs means that you can directly swap them for one another in most chains without breaking anything,\nthough it's of course important to think about how inputs are being coerced and how that may affect model performance.\n The base message interface is defined by BaseMessage, which has two required attributes:\nLangChain provides several objects to easily distinguish between different roles:\nIf none of those roles sound right, there is also a ChatMessage class where you can specify the role manually.\n This chain will take input variables, pass those to a prompt template to create a prompt, pass the prompt to a language model, and then pass the output through an (optional) output parser.\n Next steps\u200b\nWe've touched on how to build an application with LangChain, how to trace it with LangSmith, and how to serve it with LangServe.\n"}] I should read the LangChain tutorial to learn more about LangChain
Action: tavily_search_results_json
Action Input: "LangChain tutorial"[{'url': 'https://python.langchain.com/docs/additional_resources/tutorials', 'content': 'Learn how to use Langchain, a Python library for building AI applications with natural language processing and generation. Explore books, handbooks, cheatsheets, courses, and tutorials by various authors and topics.'}] I should read the LangChain tutorial to learn more about LangChain
Action: tavily_search_results_json

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/617434.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

项目5-博客系统3+接口完

1.实现显示用户信息 ⽬前⻚⾯的⽤⼾信息部分是写死的. 形如 我们期望这个信息可以随着用户登陆而发生改变. • 如果当前⻚⾯是博客列表⻚, 则显⽰当前登陆⽤⼾的信息. • 如果当前⻚⾯是博客详情⻚, 则显⽰该博客的作者⽤⼾信息. 注意: 当前我们只是实现了显⽰⽤⼾名, 没有…

CSS中:root伪类的说明和使用

定义和用法 :root选择器用匹配文档的根元素。在HTML中根元素始终是HTML元素,所以也可以把:root理解为html根元素选择器,但是比html根元素的优先级高,:root伪类选择器常常被用于定义全局的CSS变量或者设置全局的CSS样式。CSS :root 选择器 | …

如何正确使用数字化仪前端信号调理?(一)

一、前言 板卡式的数字转换器和类似测量仪器,比如图1所示的德思特TS-M4i系列,都需要为各种各样的特性信号与内部模数转换器(ADC)的固定输入范围做匹配。 图1:德思特TS-M4i系列高速数字化仪,包括2或4通道版…

commit 信息风格迥异、难以阅读,如何规范?

大家好!最近很长时间没有更新了,由于加入新团队新的项目组参与新的工作,导致博客创造搁置了一段时间,今天来记录一下我最近学习到的规范。 怎么写出符合 Angular 规范的 Commit Message 呢? 这是我们团队规定的规范。…

把持中国互联网流量的“四大家族”,各个牛逼plus!

中国互联网80%流量被四大家族把持着,其余要么去这些家族批发流量,要么去抢占剩余20%。 以下是对中国互联网流量四大家族的介绍和代表性的流量入口产品: 百度系: 百度是中国最大的搜索引擎公司,其搜索引擎百度是中国互…

办公小助手来啦! Textin接口,轻松提取文件信息,让你如虎添翼!

😎大家是不是经常为了一堆文件而头疼呢?📚别担心,Textin接口它来了!🎉 一、Textin的神秘面纱 1. Textin是谁? 🔍Textin接口,一款专业的文件信息提取工具,只…

蓝桥杯嵌入式(G431)备赛笔记——DMA+ADC(单通道+多通道)

单通道&#xff1a; 开启循环模式&#xff0c;两个参数设为word u32 adc_tick0; u32 r37_value0; u32 r38_value0; float r37_volt0; float r38_volt0;//DMAADCvoid DMA_ADC() {if(uwTick-adc_tick<100) return;adc_tick uwTick;HAL_ADC_Start_DMA(&hadc2, &r37_v…

C语言——数据在内存中的存储

引言 数据是程序运行的核心。当我们用C语言编写程序时&#xff0c;我们实际上是在操纵内存中的数据。这些数据在内存中是如何储存的&#xff0c;今天我们就来学习这些内容。 基本数据类型 1.整型 int: 基本整型&#xff0c;通常占用4个字节 short: 短整型&#xff0c;通常占用…

dPET论文笔记

PBPK论文笔记 题目&#xff1a;Self-supervised Learning for Physiologically-Based Pharmacokinetic Modeling in Dynamic PET 摘要 动态正电子发射断层扫描成像 &#xff08;dPET&#xff09; 提供示踪剂的时间分辨图像。从 dPET 中提取的时间活动曲线 &#xff08;TAC&a…

tomcat中间件漏洞

目录 什么是Tmocat Tomcat弱口令 Tomcat 文件上传 (CVE-2017-12615) 什么是Tmocat Tomcat是常见的免费的web服务器. Tomcat 这个名字的来历&#xff0c;Tomcat是一种野外的猫科动物&#xff0c;不依赖人类&#xff0c;独立生活。 Tomcat的作者&#xff0c;取这个名字的初衷…

ubuntu 更改 ssh 默认端口 22 以加固安全

出于加固安全考虑&#xff0c;一般公司会禁用 ssh 的 22 端口号&#xff0c;因此我们需要改为其他端口。 1、ssh 命令行登录 进入台式机&#xff0c;修改 /etc/ssh/sshd_config 文件中的 Port 配置行&#xff0c;将 22 改为 8022&#xff0c;保存修改后&#xff0c;重启 ssh 服…

SHAP安装问题

一、安装 pip install shap -i https://pypi.tuna.tsinghua.edu.cn/simple 二、遇到问题 1、提示报错如下&#xff1a; ModuleNotFoundError: No module named numba.core 安装numba&#xff1a; pip install numba -i https://pypi.tuna.tsinghua.edu.cn/simple 提示已经…