GPT实战系列-LangChain如何构建基通义千问的多工具链

GPT实战系列-LangChain如何构建基通义千问的多工具链

LLM大模型:

GPT实战系列-探究GPT等大模型的文本生成

GPT实战系列-Baichuan2等大模型的计算精度与量化

GPT实战系列-GPT训练的Pretraining,SFT,Reward Modeling,RLHF

GPT实战系列-ChatGLM3本地部署CUDA11+1080Ti+显卡24G实战方案

GPT实战系列-Baichuan2本地化部署实战方案

GPT实战系列-大话LLM大模型训练

随着OpenAI的GPT-4这样的大型语言模型(LLMs)已经风靡全球,现在让它们自动执行各种任务,如回答问题、翻译语言、分析文本等。LLMs是在交互上真正体验到像“人工智能”。

如何管理这些模块呢?

LangChain在这方面发挥重要作用。LangChain使构建由LLMs驱动的应用程序变得简单,使用LangChain,可以在统一的界面中轻松与不同类型的LLMs进行交互,管理模型版本,管理对话版本,并将LLMs连接在一起。

准备

本例子中,采用通义千问作为LLM

# 引入需要的模块
from langchain.chains import LLMChain, SimpleSequentialChainfrom langchain import PromptTemplateimport os

设置 千问的相关环境,和模型接口函数:

from langchain_community.llms import Tongyi
os.environ["DASHSCOPE_API_KEY"] = "your key"
llm = Tongyi()

构建第一个Prompt链

LangChain可以连接到自己定义的工具,也可以连接到内嵌的tool提供商。此处,先用Prompt构建简单的链路。

# 第一步 prompt工具链
template = "Can you provide a brief summary of the movie {movie_title}? Please keep it concise."first_prompt = PromptTemplate(input_variables=["movie_title"],template=template)chain_one = LLMChain(llm=llm, prompt=first_prompt)

构建第二个Prompt链

# 第二步 prompt工具链second_prompt = PromptTemplate(input_variables=["actor"],template="Can you list three movies featuring {actor}?")chain_two = LLMChain(llm=llm, prompt=second_prompt)

可以看到 两个int 参数:

multiply
multiply(a: int, b: int) -> int - Multiply two numbers.
{'a': {'title': 'A', 'type': 'integer'}, 'b': {'title': 'B', 'type': 'integer'}}

SimpleSequentialChain把链串起来

通过SimpleSequentialChain 把 各个链串起来,形成信息处理流。

# 结合第一和第二链
overall_chain = SimpleSequentialChain(chains=[chain_one, chain_two], verbose=True)final_answer = overall_chain.run("Inception")print(final_answer)

最后打印,实现功能。效果取决于定义的Prompt和模型的能力,得到类似的输出::

> Entering new SimpleSequentialChain chain...
Inception is a 2010 science fiction thriller film directed by Christopher Nolan. The movie follows Dom Cobb (Leonardo DiCaprio), an expert thief who specializes in infiltrating people's dreams to steal their ideas. Cobb is offered a chance to have his criminal history erased if he completes an impossible task: implanting an idea into the subconscious mind of a wealthy businessman, Robert Fischer (Cillian Murphy). To do this, Cobb assembles a team including a chemist, an architect, and a forger, and they delve into multiple layers of dream-sharing, facing challenges like time dilation and the risk of being trapped in their own subconscious. As the dreamscapes become more complex, Cobb's haunted past threatens to derail the mission and jeopardize the lives of his team members. The film explores themes of reality, dreams, and the power of the human mind.
1. The Matrix (1999) - This science fiction action film, directed by the Wachowskis, also blurs the lines between reality and the virtual world. It follows Neo (Keanu Reeves), a computer programmer who discovers that his reality is actually a simulated world created by intelligent machines. With the help of a group of rebels, including Morpheus (Laurence Fishburne) and Trinity (Carrie-Anne Moss), Neo learns to manipulate this simulated reality and fights against the machine-controlled dystopia.2. Interstellar (2014) - Another Christopher Nolan-directed film, Interstellar explores the boundaries of space, time, and human endeavor. Matthew McConaughey plays Cooper, a former pilot and engineer who leads an expedition through a wormhole in search of a new habitable planet for humanity. The movie delves into complex scientific concepts like relativity and the fifth dimension while examining the emotional impact of leaving loved ones behind.3. Paprika (2006) - This Japanese animated psychological science fiction film, directed by Satoshi Kon, revolves around a device that allows therapists to enter and explore their patients' dreams. Dr. Atsuko Chiba, using her alter ego Paprika, must navigate a chaotic dreamscape when the device falls into the wrong hands, causing dream and reality to merge dangerously. The film explores similar themes of dreams and their impact on the human psyche as Inception.> Finished chain.
1. The Matrix (1999) - This science fiction action film, directed by the Wachowskis, also blurs the lines between reality and the virtual world. It follows Neo (Keanu Reeves), a computer programmer who discovers that his reality is actually a simulated world created by intelligent machines. With the help of a group of rebels, including Morpheus (Laurence Fishburne) and Trinity (Carrie-Anne Moss), Neo learns to manipulate this simulated reality and fights against the machine-controlled dystopia.2. Interstellar (2014) - Another Christopher Nolan-directed film, Interstellar explores the boundaries of space, time, and human endeavor. Matthew McConaughey plays Cooper, a former pilot and engineer who leads an expedition through a wormhole in search of a new habitable planet for humanity. The movie delves into complex scientific concepts like relativity and the fifth dimension while examining the emotional impact of leaving loved ones behind.3. Paprika (2006) - This Japanese animated psychological science fiction film, directed by Satoshi Kon, revolves around a device that allows therapists to enter and explore their patients' dreams. Dr. Atsuko Chiba, using her alter ego Paprika, must navigate a chaotic dreamscape when the device falls into the wrong hands, causing dream and reality to merge dangerously. The film explores similar themes of dreams and their impact on the human psyche as Inception.

LangChain是一个Python框架,可以使用LLMs构建应用程序。它与各种模块连接,使与LLM和提示管理,一切变得简单。

觉得有用 收藏 收藏 收藏

点个赞 点个赞 点个赞

End

GPT专栏文章:

GPT实战系列-ChatGLM3本地部署CUDA11+1080Ti+显卡24G实战方案

GPT实战系列-LangChain + ChatGLM3构建天气查询助手

大模型查询工具助手之股票免费查询接口

GPT实战系列-简单聊聊LangChain

GPT实战系列-大模型为我所用之借用ChatGLM3构建查询助手

GPT实战系列-P-Tuning本地化训练ChatGLM2等LLM模型,到底做了什么?(二)

GPT实战系列-P-Tuning本地化训练ChatGLM2等LLM模型,到底做了什么?(一)

GPT实战系列-ChatGLM2模型的微调训练参数解读

GPT实战系列-如何用自己数据微调ChatGLM2模型训练

GPT实战系列-ChatGLM2部署Ubuntu+Cuda11+显存24G实战方案

GPT实战系列-Baichuan2本地化部署实战方案

GPT实战系列-Baichuan2等大模型的计算精度与量化

GPT实战系列-GPT训练的Pretraining,SFT,Reward Modeling,RLHF

GPT实战系列-探究GPT等大模型的文本生成-CSDN博客

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

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

相关文章

.Net预处理器指令

1.最常用的预处理器指令#region #endregion,来定义可在大纲中折叠的代码区域. #region MyClass def public class MyClass { static void Main() { } } #endregion 2.定义符号预处理器指令:来定义或取消定义条件编译的符号: #…

JavaWeb基础入门——(二)MySQL数据库基础(2-SQL 结构化查询语言)

四、MySQL逻辑结构 4.1 逻辑结构 4.1 记录 五、SQL 结构化查询语言 5.1 SQL概述 SQL(Structural Query Language)结构化查询语言,用于存取、查询、更新数据以及管理关系型数据库系统 5.1.1 SQL发展 SQL是在1981年由IBM公司推出,…

深入理解 Webpack 热更新原理:提升开发效率的关键

🤍 前端开发工程师、技术日更博主、已过CET6 🍨 阿珊和她的猫_CSDN博客专家、23年度博客之星前端领域TOP1 🕠 牛客高级专题作者、打造专栏《前端面试必备》 、《2024面试高频手撕题》 🍚 蓝桥云课签约作者、上架课程《Vue.js 和 E…

了解华为(PVID VLAN)与思科的(Native VLAN)本征VLAN的区别并学习思科网络中二层交换机的三层结构局域网VLAN配置

一、什么是二层交换机? 二层交换机(Layer 2 Switch)是一种网络设备,主要工作在OSI模型的数据链路层(第二层),用于在局域网内部进行数据包的交换和转发。二层交换机通过学习MAC地址表&#xff0…

计算机服务器中了locked勒索病毒怎么解密,locked勒索病毒解密流程

科技的发展带动了企业生产,越来越多的企业开始利用计算机服务器办公,为企业的生产运营提供了极大便利,但随之而来的网络安全威胁也引起了众多企业的关注。近日,云天数据恢复中心接到许多企业的求助,企业的计算机服务器…

arthas之生产环境排查问题常用功能

背景 生产环境调试使用。对问题进行高效排查。 目录 一、watch idea安装arthas插件 idea插件下载代理配置 A. 选择Http Proxy Settings, 打开配置页面B. 选择 Auto-detect proxy settingC. 上图中选择Ok即可, plugin 列表 刷新得到插件内容 启动arthas客户端watch监听 通过art…

(关键点检测)YOLOv8实现多类人体姿态估计的输出格式分析

(关键点检测)YOLOv8实现多类人体姿态估计的输出格式分析 任务分析 所使用的数据配置文件 网络结构 导出模型 用 netron 可视化 输出格式分析 参考链接 1. 任务分析 判断人体关键点时一并给出关键点所属的类别,比如男人,女…

【Redis知识点总结】(二)——Redis高性能IO模型剖析

Redis知识点总结(二)——Redis高性能IO模型及其事件驱动框架剖析 IO多路复用传统的阻塞式IO同步非阻塞IOIO多路复用机制 Redis的IO模型Redis的事件驱动框架 IO多路复用 Redis的高性能的秘密,在于它底层使用了IO多路复用这种高性能的网络IO&a…

vue 自定义组件绑定model+弹出选择支持上下按键选择

参考地址v-modelhttps://v2.cn.vuejs.org/v2/guide/components-custom-events.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BB%84%E4%BB%B6%E7%9A%84-v-model 原文代码 Vue.component(base-checkbox, {model: {prop: checked,event: change},props: {checked: Boolean},template: `…

前端框架的发展史

前端框架的发展历程是互联网技术演进的生动体现。从最早的简单静态页面到交互丰富的Web应用,再到如今智能化、多平台适配的复杂系统,前端框架一直扮演着关键角色。让我们一起回顾一下前端框架的发展脉络及其背后的推动力。 原始阶段:手工编写…

2.4_3 死锁的处理策略——避免死锁

文章目录 2.4_3 死锁的处理策略——避免死锁(一)什么是安全序列(二)安全序列、不安全状态、死锁的联系(三)银行家算法 总结 2.4_3 死锁的处理策略——避免死锁 银行家算法是“避免死锁”策略的最著名的一个…

Elasticsearch架构原理

一. Elasticsearch架构原理 1、Elasticsearch的节点类型 在Elasticsearch主要分成两类节点,一类是Master,一类是DataNode。 1.1 Master节点 在Elasticsearch启动时,会选举出来一个Master节点。当某个节点启动后,然后使用Zen D…

Java通过Excel批量上传数据!!!

一、首先在前端写一个上传功能。 <template><!-- 文件上传 --><el-upload class"upload-demo" drag action"" :on-change"onChange" :auto-upload"false"><el-icon class"el-icon--upload"><up…

贪心区间问题(最大不相交区间数量)

题目 给定 N 个闭区间 [ai,bi]&#xff0c;请你在数轴上选择若干区间&#xff0c;使得选中的区间之间互不相交&#xff08;包括端点&#xff09;。 输出可选取区间的最大数量。 输入格式 第一行包含整数 N&#xff0c;表示区间数。 接下来 N 行&#xff0c;每行包含两个整…

时间感知自适应RAG(TA-ARE)

原文地址&#xff1a;Time-Aware Adaptive RAG (TA-ARE) 2024 年 3 月 1 日 介绍 随着大型语言模型&#xff08;LLM&#xff09;的出现&#xff0c;出现了新兴能力的概念。前提或假设是LLMs具有隐藏的和未知的能力&#xff0c;等待被发现。企业家们渴望在LLMs中发现一些无人知晓…

论文笔记 - 基于振动信号的减速器故障诊断方法

1.论文摘要 基于振动信号的减速器故障诊断方法, 沈晴,《起重运输机械》,2018 原作者联系方式: shenqing@zmpc.com 这篇文章包含了一个从工程到数据处理和故障定位的完整过程。是一篇综述文档。它介绍了机械设备常见的三类故障(轴,齿轮、轴承)的故障特征,并在一个故障追…

2023年第三届中国高校大数据挑战赛(第二场)C题思路

赛题C&#xff1a;用户对博物馆评论的情感分析 博物馆是公共文化服务体系的重要组成部分。国家文物局发布&#xff0c;2021年我国新增备案博物馆 395 家&#xff0c;备案博物馆总数达 6183 家&#xff0c;排名全球前列&#xff1b;5605 家博物馆实现免费开放&#xff0c;占比达…

指针数组和数组指针(详细解释)

指针数组 指针数组的作用 指针数组和数组指针是C语言中常用的概念&#xff0c;它们分别有不同的作用和用法。 指针数组&#xff1a; 指针数组是一个数组&#xff0c;其中的每个元素都是指针类型。它可以用来存储多个指针&#xff0c;每个指针可以指向不同的数据类型或者相同…

xxl-job学习记录

1、应用场景 例&#xff1a; 某收银系统需要在每天凌晨统计前一天的财务分析、汇总 某银行系统需要在信用卡还款日前三天发短信提醒等 2、为什么需要使用任务调度 spring中提供了注解Scheduled的注解&#xff0c;这个注解也可以实现定时任务的执行 我们只需要在方法上使用这…

设计模式 单例模式

单例模式就是在整个程序运行的过程中&#xff0c;这个类的实例化对象只有一个。 单例模式和private static 有密切的关系。 举一个例子&#xff1a; 一个wife&#xff0c;在法律允许的范围内&#xff0c;只能有一个。 public class Wife{private static Wife wife null; //…