长春餐饮网站建设wordpress页面构造器

news/2025/10/8 20:57:32/文章来源:
长春餐饮网站建设,wordpress页面构造器,本地电脑做服务器 建网站,长链接转换成短链接分类目录#xff1a;《自然语言处理从入门到应用》总目录 在本文中#xff0c;我们将学习如何在LangChain中创建简单的链式连接并添加组件以及运行它。链式连接允许我们将多个组件组合在一起#xff0c;创建一个统一的应用程序。例如#xff0c;我们可以创建一个链式连接《自然语言处理从入门到应用》总目录 在本文中我们将学习如何在LangChain中创建简单的链式连接并添加组件以及运行它。链式连接允许我们将多个组件组合在一起创建一个统一的应用程序。例如我们可以创建一个链式连接接收用户输入使用PromptTemplate对其进行格式化然后将格式化后的响应传递给LLM。我们可以通过将多个链式连接组合在一起或将链式连接与其他组件组合来构建更复杂的链式连接。 快速入门使用LLMChain LLMChain是一个简单的链式连接它接收一个prompt模板使用用户输入对其进行格式化并返回LLM的响应。要使用LLMChain首先创建一个prompt模板。 from langchain.prompts import PromptTemplate from langchain.llms import OpenAIllm OpenAI(temperature0.9) prompt PromptTemplate(input_variables[product],templateWhat is a good name for a company that makes {product}?, )现在我们可以创建一个非常简单的链式连接它将接收用户输入使用它来格式化prompt并将其发送到LLM。 from langchain.chains import LLMChain chain LLMChain(llmllm, promptprompt)# 仅指定输入变量运行链式连接。 print(chain.run(colorful socks))输出 Colorful Toes Co.如果有多个变量我们可以使用字典一次输入它们。 prompt PromptTemplate(input_variables[company, product],templateWhat is a good name for {company} that makes {product}?, ) chain LLMChain(llmllm, promptprompt) print(chain.run({company: ABC Startup,product: colorful socks}))输出 Socktopia Colourful Creations.我们也可以在LLMChain中使用聊天模型 from langchain.chat_models import ChatOpenAI from langchain.prompts.chat import (ChatPromptTemplate,HumanMessagePromptTemplate, )human_message_prompt HumanMessagePromptTemplate(promptPromptTemplate(templateWhat is a good name for a company that makes {product}?,input_variables[product],))chat_prompt_template ChatPromptTemplate.from_messages([human_message_prompt]) chat ChatOpenAI(temperature0.9) chain LLMChain(llmchat, promptchat_prompt_template) print(chain.run(colorful socks))输出 Rainbow Socks Co.调用链式连接的不同方式 所有继承自Chain的类都提供了几种运行链式连接逻辑的方式。其中最直接的一种方式是使用 __call__ chat ChatOpenAI(temperature0) prompt_template Tell me a {adjective} joke llm_chain LLMChain(llmchat,promptPromptTemplate.from_template(prompt_template) )llm_chain(inputs{adjective:corny})输出 {adjective: corny,text: Why did the tomato turn red? Because it saw the salad dressing!}默认情况下__call__ 方法会返回输入和输出的键值对。我们可以通过将return_only_outputs设置为True来配置它仅返回输出的键值对。 llm_chain(corny, return_only_outputsTrue) {text: Why did the tomato turn red? Because it saw the salad dressing!}如果Chain只输出一个输出键即其output_keys中只有一个元素则可以使用run方法。需要注意的是run方法输出一个字符串而不是字典。 # llm_chain only has one output key, so we can use run llm_chain.output_keys输出 [text]输入 llm_chain.run({adjective:corny})输出 Why did the tomato turn red? Because it saw the salad dressing!在只有一个输入键的情况下我们可以直接输入字符串无需指定输入映射。 # These two are equivalent llm_chain.run({adjective:corny}) llm_chain.run(corny)# These two are also equivalent llm_chain(corny) llm_chain({adjective:corny})输出 {adjective: corny,text: Why did the tomato turn red? Because it saw the salad dressing!}我们可以通过Chain对象的run方法将其作为Agent中的Tool进行简单集成。 为链式连接添加记忆 Chain支持将BaseMemory对象作为其memory参数从而使Chain对象能够在多次调用之间保留数据。换句话说memory参数使Chain成为一个有状态的对象。 from langchain.chains import ConversationChain from langchain.memory import ConversationBufferMemoryconversation ConversationChain(llmchat,memoryConversationBufferMemory() )conversation.run(Answer briefly. What are the first 3 colors of a rainbow?) # - The first three colors of a rainbow are red, orange, and yellow. conversation.run(And the next 4?) # - The next four colors of a rainbow are green, blue, indigo, and violet.输出 The next four colors of a rainbow are green, blue, indigo, and violet.基本上BaseMemory定义了langchain存储记忆的接口。它允许通过load_memory_variables方法读取存储的数据并通过save_context方法存储新数据。我们可以在《自然语言处理从入门到应用——LangChain记忆Memory》系列文章了解更多信息。 调试链式连接 仅从输出中调试Chain对象可能会很困难因为大多数Chain对象涉及相当数量的输入prompt预处理和LLM输出后处理。将verbose设置为True将在运行时打印出Chain对象的一些内部状态。 conversation ConversationChain(llmchat,memoryConversationBufferMemory(),verboseTrue ) conversation.run(What is ChatGPT?)日志输出 Entering new ConversationChain chain... Prompt after formatting: The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.Current conversation:Human: What is ChatGPT? AI: Finished chain.输出 ChatGPT is an AI language model developed by OpenAI. It is based on the GPT-3 architecture and is capable of generating human-like responses to text prompts. ChatGPT has been trained on a massive amount of text data and can understand and respond to a wide range of topics. It is often used for chatbots, virtual assistants, and other conversational AI applications.使用SequentialChain将链式连接组合起来 在调用语言模型之后的下一步是对语言模型进行一系列的调用。我们可以使用顺序链式连接来实现这一点顺序链式连接按照预定义的顺序执行其链接。具体而言我们将使用SimpleSequentialChain。这是最简单的顺序链式连接类型其中每个步骤都具有单个输入/输出一个步骤的输出是下一个步骤的输入。在本文中我们的顺序链式连接将首先为产品创建一个公司名称我们将重用之前初始化的LLMChain来创建这个公司名称。然后再为产品创建一个口号。我们将初始化一个新的LLMChain来创建这个口号 second_prompt PromptTemplate(input_variables[company_name],templateWrite a catchphrase for the following company: {company_name}, ) chain_two LLMChain(llmllm, promptsecond_prompt)现在我们可以将这两个LLMChain结合起来这样我们就可以一步创建一个公司名称和一个标语。 from langchain.chains import SimpleSequentialChain overall_chain SimpleSequentialChain(chains[chain, chain_two], verboseTrue)# Run the chain specifying only the input variable for the first chain. catchphrase overall_chain.run(colorful socks) print(catchphrase)日志输出 Entering new SimpleSequentialChain chain... Rainbow Socks Co.Put a little rainbow in your step! Finished chain.输出 Put a little rainbow in your step!使用Chain类创建自定义链式连接 LangChain提供了许多现成的链式连接但有时我们可能希望为特定的用例创建自定义链式连接。在这个例子中我们将创建一个自定义链式连接它将两个LLMChain的输出连接起来。 要创建一个自定义链式连接 创建一个Chain类的子类填写input_keys和output_keys属性添加_call方法展示如何执行链式连接 下面的示例演示了这些步骤 from langchain.chains import LLMChain from langchain.chains.base import Chainfrom typing import Dict, Listclass ConcatenateChain(Chain):chain_1: LLMChainchain_2: LLMChainpropertydef input_keys(self) - List[str]:# Union of the input keys of the two chains.all_input_vars set(self.chain_1.input_keys).union(set(self.chain_2.input_keys))return list(all_input_vars)propertydef output_keys(self) - List[str]:return [concat_output]def _call(self, inputs: Dict[str, str]) - Dict[str, str]:output_1 self.chain_1.run(inputs)output_2 self.chain_2.run(inputs)return {concat_output: output_1 output_2}现在我们可以尝试运行我们调用的链 prompt_1 PromptTemplate(input_variables[product],templateWhat is a good name for a company that makes {product}?, ) chain_1 LLMChain(llmllm, promptprompt_1)prompt_2 PromptTemplate(input_variables[product],templateWhat is a good slogan for a company that makes {product}?, ) chain_2 LLMChain(llmllm, promptprompt_2)concat_chain ConcatenateChain(chain_1chain_1, chain_2chain_2) concat_output concat_chain.run(colorful socks) print(fConcatenated output:\n{concat_output})输出 Concatenated output:Funky Footwear CompanyBrighten Up Your Day with Our Colorful Socks!参考文献 [1] LangChain官方网站https://www.langchain.com/ [2] LangChain ️ 中文网跟着LangChain一起学LLM/GPT开发https://www.langchain.com.cn/ [3] LangChain中文网 - LangChain 是一个用于开发由语言模型驱动的应用程序的框架http://www.cnlangchain.com/

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

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

相关文章

RL | 速读 IJCAI 2025 的强化学习论文

速读一下 IJCAI 2025 的 RL 相关论文。目录359 Multi-granularity Knowledge Transfer for Continual Reinforcement Learning - 为持续 RL 而设计的多粒度知识迁移一、 研究背景与核心痛点(The Gap)二、 动机与故事…

Superhumanism

The civilizeds support Superhumanism. But they didnt support the Nazi Germany! Because they dont see the similar. Because they dont see the consequences. A normal human cannot become a superman, but if…

IDM弹窗解决 - -一叶知秋

IDM弹窗解决1、打开任务管理器,结束IDM任务(一定要结束全部的IDM任务)2、在控制面板中,打开 管理工具(有搜索)3、然后打开 本地安全策略4、找到 软件限制策略->其它规则,如果 软件限制策略 下面没有选项,就…

PHP+MySQL开发语言 在线下单订水送水小脚本源码及搭建指南

PHP+MySQL开发语言 在线下单订水送水小脚本源码及搭建指南pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consola…

Sliding Window Algorithm

核心目的 滑动窗口技术的主要目的是优化算法。它能将一个通常需要用两层嵌套循环(时间复杂度为 \(O(N^2)\))才能解决的问题,转化为只需一次单循环(时间复杂度为 \(O(N)\)),从而大大提高代码的执行效率。工作原理…

微信企业号可以做微网站吗宿州建设银行网站

对数值进行调整在Python中对整数和浮点数进行数字计算是很容易的。但是,如果你需要对分数,数组或者日期和时间进行计算,这就会稍微复杂点。对于简单的取整操作,我们可以使用内建的round(value, ndigits)函数就可,举个例…

网站建设所需人员上海如何优化网站

动态通过网络获取json来tabbar图片和文字或其他信息转载于:https://www.cnblogs.com/TheYouth/p/6488843.html

合肥的网站建设剂屏购物网站开发流程

文章目录 5 智能指针与内存管理5.1 RAII与引用计数5.2 std::shared_ptr5.3 std::unique_ptr5.4 std::weak_ptr 6 正则表达式7 并行与并发7.1 并行基础7.2 互斥量与临界区7.3 期物7.4 条件变量7.5 原子操作与内存模型 5 智能指针与内存管理 5.1 RAII与引用计数 在传统 C 中&am…

广西柳州网站建设公司网站建设的实验总结

文章目录 生成数据帧参考 生成数据帧 代码如下,代码很简单,有几点要注意, 较高版本的MATLAB中支持0x的写法使用bitand进行位运算使用strcat函数进行字符串拼接时,如果需要插入空格,要使用双引号 cmd_ay(1) 0x33; …

图片 展示 网站模板快速seo整站优化排行

本博客参考官方文档进行介绍,全网仅此一家进行中文翻译,走过路过不要错过。 官方网址:https://www.mpi-forum.org/ 参考文档:https://www.mpi-forum.org/docs/mpi-4.1/mpi41-report.pdf 引用官方4.1文档方法: manu…

国庆模拟赛总结

2025/10/2 T1 这道题我一眼出思路呀,直接建反边然后判断一下可达性不就秒了吗,10分钟直接秒,不过有点坑,第一个点如果没出边那它就应该标记合法,这不标直接100pts->90pts,以后还是要多注意细节。还有一点很重…

深入解析:video-audio-extractor:视频转换为音频

深入解析:video-audio-extractor:视频转换为音频pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas"…

10.8 CSP-JS 模拟赛 T4. discover

思路 不难想到用数量较少的危险点来限制长方形, 进而处理正方形 现在的问题就是如何精确地刻画任意一个本质相同的长方形, 发现我们完全可以通过枚举四个危险点来刻画一个长方形 但是这样会出现大量的不合法情况\((\)即…

20251008 模拟测 总结

\(\mathcal{Preface}\) 分数 \(50+100+40+100=290\),甚至比去年低 \(15\) 分,有点受不了了。 A 题代码上挂了 \(50\) 分,C 题思维上挂了 \(60\) 分。 简称:挂了 \(50\) 分,还“挂了”\(60\) 分。 挂的最猛烈的一次…

初中学习网站大全免费哈尔滨市城乡和建设局网站

在完成了对Exchange的UM功能进行配置之后,我们要把UM的功能与Lync做集成的话还需要在Lync这边做一些配置。首先我们打开Lync前端服务器,然后打开核心组件安装目录下的Support文件夹,然后双击OcsUmUtil。打开之后我们单击加载数据,…

详细介绍:运行shell脚本时报错/bin/bash^M: 解释器错误: 没有那个文件或目录

详细介绍:运行shell脚本时报错/bin/bash^M: 解释器错误: 没有那个文件或目录pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-fam…

VuePress v2是否支持Vue2的配置?

不,VuePress v2 不支持 Vue 2 的配置和运行时。它是一个基于 Vue 3 的全新版本,与 Vue 2 完全不兼容。 以下是详细解释:❌ VuePress v1 vs v2:核心差异特性 VuePress v1 VuePress v2Vue 版本 Vue 2 ✅ Vue 3打包工…

福建省建设局网站实名制建网站的费用包括

.gitignore的使用 1、简介 .gitignore文件用于指定哪些文件或目录应该被Git忽略,即它们不会被Git跟踪和提交到版本控制中。 2、简单语法规则 1、注释:使用#符号进行注释。 2、文件和目录规则:每行一个规则,指定要忽略的文件、…

新人UP主:晓牛开发者的第一篇自我介绍博客测试发布

晓牛、开发者、程序员、开发工程师、Java、后端开发、全栈开发,热爱技术