LangChain学习二:提示-实战(上半部分)

文章目录

  • 上一节内容:LangChain学习一:模型-实战
  • 学习目标:提示词及提示词模板的运用
  • 学习内容一:什么是提示词?
  • 学习内容二:提示词模板
    • 2.1 入门
    • 2.2 模板格式
    • 2.3 验证模板
    • 2.4 序列化提示模板
    • 2.5 将少量示例传递给提示模板(few_shot)
    • 2.6 选择提示模板的示例
        • 2.6.1 基于长度的示例选择器
  • 学习内容三:聊天提示模板
    • 3.1 聊天提示模板
      • 3.1 .1 实战:首先需要声明和定义一个模板
      • 3.1 .2 实战:把提示词模板放入系统消息提示模板、人类消息提示模板等,并进行组合放入大模型
        • 3.1.2.1 提示词模板放入SystemMessagePromptTemplate、HumanMessagePromptTemplate、ChatPromptTemplate等
        • 3.1.2.2 不同类型的 MessagePromptTemplate
    • 3.2 实例选择器

上一节内容:LangChain学习一:模型-实战

LangChain学习一:模型-实战

学习目标:提示词及提示词模板的运用


学习内容一:什么是提示词?

大白话就是我们问大模型的问题

在这里插入图片描述

学习内容二:提示词模板

  提示模板是生成提示的可重复方法。
就是一个字符串,这个字符串里面包含{变量},我们要用的时候把变量进行赋值,赋值之后我们的模板就实例化成了一句话

提示模板可能包含:

对语言模型的指导,

一组少量示例,以帮助语言模型生成更好的响应,

对语言模型的提问。

2.1 入门

from langchain import PromptTemplate

template = """
给我介绍一下{product}?
"""

prompt = PromptTemplate(
    input_variables=["product"],
    template=template,
)
out=prompt.format(product="华为")
print(out)

在这里插入图片描述
{product}这里声明了一个变量,也可以说是占位符(可以是多个),
然后PromptTemplate进行实例化input_variables代表变量的列表,这里的值一定要和我们声明的相同,template就是我们的定义模板是那句话

prompt.format就是通过变量名='实际值’进行实例化

还有一种方式是,先声明后赋值

from langchain import PromptTemplate

template = """
给我介绍一下{product}?
"""

prompt_template = PromptTemplate.from_template(template)
out=prompt_template.format(product="华为")
print(out)

效果和上面一样
在这里插入图片描述

2.2 模板格式

以上2种情况是默认Python f-string处理的,比如说,下面这个例子,我们就想让字符串里面包含{ok}

from langchain import PromptTemplate

template = """
给我介绍一下{product}{ok}?
"""

prompt = PromptTemplate(
    input_variables=["product"],
    template=template,
)
out=prompt.format(product="华为")
print(out)

在这里插入图片描述
这时候我们就可以通过 template_format 参数指定其他模板格式:
这里我们介绍一下 jinja2
在这里插入图片描述
需要加载依赖包

pip install jinja2
from langchain import PromptTemplate

# Make sure jinja2 is installed before running this

template = "请给我介绍一下 {{ project }} {ok}"
prompt_template = PromptTemplate.from_template(template=template, template_format="jinja2")

out=prompt_template.format(project="华为")
print(out)


在这里插入图片描述

这时候我们发现{ok}就可以显示了

2.3 验证模板

我们在实例化PromptTemplate的时候input_variables可以帮我们校验
template里面是否包含变量,如果不包含就会报错

prompt_template = PromptTemplate(template=template,
                                 input_variables=["project", "foo"]) 

在这里插入图片描述
我们可以通过validate_template=False来禁止此行为

template = "请给我介绍一下 {project}"
prompt_template = PromptTemplate(template=template,
                                 input_variables=["project", "foo"],
                                 validate_template=False) 
                                 out=prompt_template.format(project="华为")

在这里插入图片描述
注意注意,这里out=prompt_template.format(project="华为")project一定要在template 里面存在,并且不能有其他的变量,不然都会报错

2.4 序列化提示模板

from langchain import PromptTemplate


template = "请给我介绍一下 {project}"
prompt_template = PromptTemplate.from_template(template=template)
# 保存
prompt_template.save("awesome_prompt.json") # Save to JSON file
 

在这里插入图片描述


from langchain.prompts import load_prompt
loaded_prompt = load_prompt("awesome_prompt.json")
out=loaded_prompt.format(project="华为")
print(out)

在这里插入图片描述

2.5 将少量示例传递给提示模板(few_shot)

from langchain import PromptTemplate, FewShotPromptTemplate
 
# 首先,创建少数快照示例的列表。
examples = [
    {"word": "开心", "antonym": "悲伤"},
    {"word": "高", "antonym": "低"},
]
 
#接下来,我们指定模板来格式化我们提供的示例。
#为此,我们使用“PromptTemplate”类。
example_formatter_template = """
单词: {word}
反义词: {antonym}\n
"""
example_prompt = PromptTemplate(
    input_variables=["word", "antonym"],
    template=example_formatter_template,
)
 
# 最后,我们创建“FewShotPromptTemplate”对象。
few_shot_prompt = FewShotPromptTemplate(
    # 以下是我们要插入到提示中的示例。
    examples=examples,
    # 当我们将示例插入到提示中时,这就是我们想要格式化示例的方式。
    example_prompt=example_prompt,
	#前缀是位于提示中示例之前的一些文本。
	#通常,这包括入侵。
    prefix="给出每个输入的反义词",
	#后缀是在提示中的示例后面的一些文本。
	#通常,这是用户输入的位置
    suffix="单词: {input}\n反义词:",
    # 输入变量是整个提示所期望的变量.
    input_variables=["input"],
  	#example_separator是用于将前缀、examples和后缀连接在一起的字符串。
    example_separator="",
)
 
#我们现在可以使用“format”方法生成提示。
print(few_shot_prompt.format(input="big"))

 

结果

给出每个输入的反义词
单词: 开心
反义词: 悲伤


单词: 高
反义词: 低

单词: 大
反义词:

2.6 选择提示模板的示例

通俗点来说就是通过方法找到相似的示例,有以下几种方式

  • LengthBased ExampleSelector(基于长度的示例选择器):这是一种示例选择器,它根据示例的长度来选择要使用的示例。较长的示例可能包含更多的细节和信息,因此可以更全面地回答用户的问题。

  • 最大边际相关性 ExampleSelector:这种示例选择器基于与输入之间的边际相关性来选择示例。它计算每个示例与输入之间的相关性,并选择具有最高相关性的示例作为回答。

  • NGram 重叠 ExampleSelector:NGram 重叠示例选择器根据输入和示例之间的共享 N-gram 片段来选择示例。它通过匹配输入和示例之间的共同 N-gram 片段来确定最相关的示例。

  • 相似度 ExampleSelector:相似度示例选择器使用文本相似度度量来选择最相关的示例。它计算输入和示例之间的相似度,然后选择与输入最相似的示例作为回答。

这里举个例子介绍下,后面单独出一节来介绍

2.6.1 基于长度的示例选择器

总长度是由max_length控制的,如果我们输入的长一些,就会少从examples 拿一些,输入短,则反之

from langchain import PromptTemplate, FewShotPromptTemplate

# 首先,创建少数快照示例的列表。
from langchain.prompts import LengthBasedExampleSelector

examples = [
    {"word": "开心", "antonym": "悲伤"},
    {"word": "高", "antonym": "低"},
]


# 接下来,我们指定模板来格式化我们提供的示例。
# 为此,我们使用“PromptTemplate”类。
example_formatter_template = """
单词: {word}
反义词: {antonym}\n
"""
example_prompt = PromptTemplate(
    input_variables=["word", "antonym"],
    template=example_formatter_template,
)
#我们将使用' LengthBasedExampleSelector '来选择示例。
example_selector = LengthBasedExampleSelector(
    # 这些是可供选择的例子。
    examples=examples,
    #这是用于格式化示例的PromptTemplate。
    example_prompt=example_prompt,
    # 这是格式化示例的最大长度。
    # 长度由下面的get_text_length函数测量。
    max_length=25,
)
# 我们现在可以使用' example_selector '来创建' FewShotPromptTemplate '。
dynamic_prompt = FewShotPromptTemplate(
    # We provide an ExampleSelector instead of examples.
    example_selector=example_selector,
    example_prompt=example_prompt,
    prefix="给出每个输入的反义词",
    suffix="单词: {input}\n反义词:",
    input_variables=["input"],
    example_separator="",
)

# We can now generate a prompt using the `format` method.
print(dynamic_prompt.format(input="big"))

学习内容三:聊天提示模板

本次介绍一下几个

  • 聊天提示模板
  • LLM提示模板
  • 示例选择器
  • 输出解析器

3.1 聊天提示模板

  上一节介绍了,模型有聊天模型,也是我们常用的。这一节,我们看一下如何更好地使用聊天模型。聊天模型和LLM模型在上一节也说过了,是有不同的,聊天模型的每条信息
都与一个角色 进行关联

  因此,LangChain提供了几个相关的提示模板,以便轻松构建和处理提示。在查询聊天模型时,建议您使用这些与聊天相关的提示模板,而不是PromptTemplate,以充分发挥基础聊天模型的潜力。

"""
@FileName:chat_prompt.py
@Description:
@Author:lucky 
@Time:2023/12/9 10:41
"""
from langchain.prompts import (
    ChatPromptTemplate,
    PromptTemplate,
    SystemMessagePromptTemplate,
    AIMessagePromptTemplate,
    HumanMessagePromptTemplate,
)
from langchain.schema import (
    AIMessage,
    HumanMessage,
    SystemMessage
)

template = "你是一个很有帮助的翻译助手{input_language} 翻译成 {output_language}."
system_message_prompt = SystemMessagePromptTemplate.from_template(template)
print(system_message_prompt)
human_template = "{text}"
print("====================")
human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
print(human_message_prompt)

在这里插入图片描述
简单介绍一下

  • ChatPromptTemplate (聊天模板):
      这个模板用于生成对话的开头,它通常包含一些问候语或提醒用户如何使用机器人的信息。

  • PromptTemplate (提示模板):
      这个模板用于为用户提供特定主题或任务的提示。它可以是一个问题,要求用户提供更多信息,或者是一个指导性的陈述,告诉用户下一步该做什么

  • SystemMessagePromptTemplate(系统消息提示模板):
      这个模板用于生成系统消息,向用户提供一些重要的信息,比如机器人无法回答某个问题、请求用户提供更多细节等等。

  • AIMessagePromptTemplate (AI消息提示模板):
      这个模板用于生成 AI 机器人的回答。它基于预训练的模型,使用大量的数据和算法来生成针对用户问题的响应。

  • HumanMessagePromptTemplate(人类消息提示模板):
      这个模板用于生成人类操作者的回答,当机器人无法回答某个问题时,会将问题转交给人类操作者进行回答。

其中{}里面是变量名称,所以不要用{}在你的提示词中,如果用,那就不要用LangChain提示词模板。

3.1 .1 实战:首先需要声明和定义一个模板

from langchain.callbacks import StreamingStdOutCallbackHandler
from langchain.chat_models import ChatOpenAI
from langchain.prompts import (
    ChatPromptTemplate,
    PromptTemplate,
    SystemMessagePromptTemplate,
    AIMessagePromptTemplate,
    HumanMessagePromptTemplate,
)
from langchain.prompts.chat import ChatPromptValue
from langchain.schema import (
    AIMessage,
    HumanMessage,
    SystemMessage
)

声明一个模板,注意:{变量} 提示词模板的意思就是一个框架里面有一些变量,这些变量也可以理解成为占位符。后面使用提示词模板只要把里面的变量进行具体化就可以了

template = "你是一个很有帮助的翻译助手{input_language} 翻译成 {output_language}."

3.1 .2 实战:把提示词模板放入系统消息提示模板、人类消息提示模板等,并进行组合放入大模型

SystemMessagePromptTemplate、HumanMessagePromptTemplate等都有一个from_template方法,用于把我们提示词模板放入

3.1.2.1 提示词模板放入SystemMessagePromptTemplate、HumanMessagePromptTemplate、ChatPromptTemplate等
from langchain.callbacks import StreamingStdOutCallbackHandler
from langchain.chat_models import ChatOpenAI
from langchain.prompts import (
    ChatPromptTemplate,
    PromptTemplate,
    SystemMessagePromptTemplate,
    AIMessagePromptTemplate,
    HumanMessagePromptTemplate,
)
from langchain.prompts.chat import ChatPromptValue
from langchain.schema import (
    AIMessage,
    HumanMessage,
    SystemMessage
)
template = "你是一个很有帮助的翻译助手{input_language} 翻译成 {output_language}."
system_message_prompt = SystemMessagePromptTemplate.from_template(template)
print(f"========system_message_prompt的格式化结果:{system_message_prompt}============\n\n\n")
human_template = "{text}"
human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
print(f"========human_template的格式化结果:{human_template}============\n\n\n")

在这里插入图片描述
这时候我们可以构建一个ChatPromptTemplate(聊天模板),把我们的(系统消息提示模板)和(人类消息提示模板)组合起来,放入大模型。

组合方式:ChatPromptTemplate提供了from_messages方法

chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])

print(f"========chat_prompt的格式化结果:{chat_prompt}============3\n\n\n")

组合之后我们可以看一下chat_prompt 这个对象里面有什么,
input_variables:包含了所有的变量
messages:是个列表:包含了所有的模板对象
在这里插入图片描述

我们可以format_prompt实例化(就是把模板里面的变量进行赋值),然后通过to_messages打印他的实例结构结果

output_to_messages=chat_prompt.format_prompt(input_language="English", output_language="French", text="I love programming.").to_messages()
print(output_to_messages)

在这里插入图片描述
或者你也可以直接使用format,与上面不同的是,format直接返回的是值,或者你也可以用上面的方式使用to_string方法,都是可行的

output = chat_prompt.format(input_language="English", output_language="French", text="I love programming.")
print(f"========format的结果:{output}============4\n\n\n")


# or alternatively
output_2 = chat_prompt.format_prompt(input_language="English", output_language="French",
                                     text="I love programming.").to_string()

在这里插入图片描述
总结一下:以上把我们的(系统消息提示模板)和(人类消息提示模板)组合起来,放入ChatPromptTemplate(聊天模板)一共用了三个步骤:

  1. 分别实例化了 系统消息提示模板 和 人类消息提示模板
  2. 声明ChatPromptTemplate对象的同时把相关模板实例也放进去
  3. 对ChatPromptTemplate对象模板进行使用,把变量名换成我们想要的

其上以上三个步骤可以作为一个步骤直接使用,也就是不使用模板的方式,我们观察一下,上面的多有工作都是为了节省一些重复的工作,但是送进大模型的就是具体的话,所以直接用下面的方式

output_3=ChatPromptValue(messages=[
    SystemMessage(content='你是把英语翻译成法语的得力助手。', additional_kwargs={}),
    HumanMessage(content='I love programming.', additional_kwargs={})])
print(f"========format_prompt的结果:{output_3}===========5\n\n\n")

在这里插入图片描述
把他送入我们的模型,就可以轻易的获得我们想要的结果了

chat = ChatOpenAI(streaming=True, callbacks=[StreamingStdOutCallbackHandler()],
    verbose=True,
    # callbacks=[callback],
    openai_api_key="none",
    openai_api_base="http://127.0.0.1:8000/v1",
    model_name="Qwen-7B-Chat"
)
resp = chat(output_3.messages)
print(f"=======模型返回结果:\n{resp}\n\n")

在这里插入图片描述

3.1.2.2 不同类型的 MessagePromptTemplate

LangChain 提供了不同类型的 MessagePromptTemplate。其中最常用的是 AIMessagePromptTemplate、SystemMessagePromptTemplate 和 HumanMessagePromptTemplate,分别用于创建 AI 消息、系统消息和人类消息。

同样自定义也有两种方式

  • 使用模板
  • 直接实例化

使用模板

chat_message_prompt = ChatMessagePromptTemplate.from_template(role="Jedi", template=prompt)
chat_message_out=chat_message_prompt.format(subject="force")
print(f"========chat_message_prompt的格式化结果:{chat_message_out}============7\n\n\n")


 

直接实例化

out=ChatMessage(content='May the force be with you', additional_kwargs={}, role='Jedi')
print(f"========chat_message_prompt的格式化结果:{out}============8\n\n\n")

在这里插入图片描述
效果是一样的

至于这个做啥的,这个就是看你自己的场景了。

LangChain 还提供了 MessagesPlaceholder,该占位符可以在格式化期间完全控制要呈现的消息。当您不确定应该使用哪个消息提示模板的角色或者希望在格式化期间插入消息列表时,这可能非常有用。

就是再上一个小节里面,我们把不同的提示模板进行组合,但是前提条件都是我们知道有几个,占位符就是让我们在前提不知道几个的情况下进行的

from langchain.prompts import MessagesPlaceholder
 
human_prompt = "总结一下我们到目前为止的谈话 {word_count}单词."
human_message_template = HumanMessagePromptTemplate.from_template(human_prompt)
 
chat_prompt = ChatPromptTemplate.from_messages([MessagesPlaceholder(variable_name="conversation"), human_message_template])
 

这里就是使用了conversation占位符。下面我们就可再次组合

human_message = HumanMessage(content="What is the best way to learn programming?")
ai_message = AIMessage(content="""\
1. Choose a programming language: Decide on a programming language that you want to learn. 
 
2. Start with the basics: Familiarize yourself with the basic programming concepts such as variables, data types and control structures.
 
3. Practice, practice, practice: The best way to learn programming is through hands-on experience\
""")
 
out=chat_prompt.format_prompt(conversation=[human_message, ai_message], word_count="10").to_messages()
print(out)
 
[HumanMessage(content='What is the best way to learn programming?', additional_kwargs={}),
 AIMessage(content='1. Choose a programming language: Decide on a programming language that you want to learn.   2. Start with the basics: Familiarize yourself with the basic programming concepts such as variables, data types and control structures.  3. Practice, practice, practice: The best way to learn programming is through hands-on experience', additional_kwargs={}),
 HumanMessage(content='Summarize our conversation so far in 10 words.', additional_kwargs={})]
 

3.2 实例选择器

说白了就是选择一些例子,给大模型。让大模型参考给出答案

下面介绍一些常用的

  • LengthBased ExampleSelector(基于长度的示例选择器):这是一种示例选择器,它根据示例的长度来选择要使用的示例。较长的示例可能包含更多的细节和信息,因此可以更全面地回答用户的问题。

  • 最大边际相关性 ExampleSelector:这种示例选择器基于与输入之间的边际相关性来选择示例。它计算每个示例与输入之间的相关性,并选择具有最高相关性的示例作为回答。

  • NGram 重叠 ExampleSelector:NGram 重叠示例选择器根据输入和示例之间的共享 N-gram 片段来选择示例。它通过匹配输入和示例之间的共同 N-gram 片段来确定最相关的示例。

  • 相似度 ExampleSelector:相似度示例选择器使用文本相似度度量来选择最相关的示例。它计算输入和示例之间的相似度,然后选择与输入最相似的示例作为回答。

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

从 AST 到代码生成:代码背后的秘密花园(下)

🤍 前端开发工程师(主业)、技术博主(副业)、已过CET6 🍨 阿珊和她的猫_CSDN个人主页 🕠 牛客高级专题作者、在牛客打造高质量专栏《前端面试必备》 🍚 蓝桥云课签约作者、已在蓝桥云…

Selenium三大等待(详解版)

一、强制等待 1.设置完等待后不管有没有找到元素,都会执行等待,等待结束后才会执行下一步 2.实例: driver webdriver.Chrome()driver.get("https://www.baidu.com")time.sleep(3) # 设置强制等待driver.quit() 二、隐性等待 …

vscode 环境配置

必备插件 配置调试 {// Use IntelliSense to learn about possible attributes.// Hover to view descriptions of existing attributes.// For more information, visit: https://go.microsoft.com/fwlink/?linkid830387"version": "0.2.0","confi…

华为OD试题六(数据最节约的备份方法、TLV解码)

1. 数据最节约的备份方法 题目描述: 有若干个文件,使用刻录光盘的方式进行备份,假设每张光盘的容量是500MB,求 使用光盘最少的文件分布方式 所有文件的大小都是整数的MB,且不超过500MB;文件不能分割、分卷…

新版Spring Security6.2案例 - Authentication用户名密码

前言: 前面有翻译了新版Spring Security6.2架构,包括总体架构,Authentication和Authorization,感兴趣可以直接点链接,这篇翻译官网给出的关于Authentication的Username/Password这页。 首先呢,官网就直接…

[Linux] LAMP架构

一、LAMP架构架构的概述 LAMP 架构是一种流行的 Web 应用程序架构,它的名称是由四个主要组件的首字母组成的: Linux(操作系统): 作为操作系统,Linux 提供了服务器的基础。它负责处理硬件资源、文件系统管理…

医院污水处理设备远程监控超标报警解决方案

行业背景 近年来,我国医疗机构建设得到了巨大的发展。根据《2022年我国卫生健康事业发展统计公报》,2022年末,全国医疗卫生机构总数达1032918个。截至2022年10月,根据全国排污许可证管理信息平台,共有 13316家医院核发…

融合人脸识别、云计算、人工智能等技术的智慧校园管理系统源码

智慧电子班牌可以实现作业布置,评分以及留言反馈;还可以提高老师的工作效率;也可以关联走班排课系统,老师和学生可以实时查看课程信息,做好课前准备,家长也可以在软件上进行请假、查询等,老师可…

智能化配电房

智能化配电房是一种集成了先进技术和智能化设备的配电房,通过智能采集终端与通信设备,实时将电气参数、运行信息和环境数据传送至智慧电力物联网平台—电易云,对配电室进行数字化升级,对运维工作数字化升级,建设电力系…

初识GroovyShell

文章目录 前言一、GroovyShell二、maven三、解决方案四、关键代码4.1 数据库配置表(pg)4.2 入参4.3 分页查询 总结 前言 项目背景:查询多个表的数据列表和详情,但不想创建过多的po、dao、resp等项目文件。 一、GroovyShell Apache Groovy是一种强大的…

谈谈MYSQL主从复制原理

目录 概述 要点binlog日志 主从复制过程 总结 概述 MySQL 主从复制是指数据可以从一个MySQL数据库服务器主节点复制到一个或多个从节点。 MySQL 默认采用异步复制方式。从节点不用一直访问主服务器来更新自己的数据,数据的更新可以在远程连接上进行&#xff0…

HTTP 500错误:服务器内部错误,原因及解决方案

大家好,今天我们来聊聊一个常见的问题——HTTP 500错误,也就是服务器内部错误。这个错误就像是一个神秘的魔法,时不时地出现在你的网页上,让你的用户和你在一片懵逼中互相猜疑。 首先,我们来了解一下这个错误。HTTP 5…

LabVIEW在高铁温度与振动监测中的应用

​LabVIEW在高铁温度与振动监测中的应用 高速铁路的可靠性和安全性是现代铁路运输系统设计和运营的重中之重。LabVIEW软件作为一个多功能、可扩展的图形编程环境,提供了一个理想的平台,用于开发高铁监测系统,不仅监测实时数据,也…

数据常见的提取和筛选方法

平时对于一些不标准的数据,需要提取或者筛选其中的部分数据。本文主要分享一些常用的办法,同时也作为一个笔记的备份。 1. 正则表达式 正则表达式比较适合提取有明确类型的数据,比如字母,数字,汉字,日期等…

python自动化测试实战 —— WebDriver API的使用

软件测试专栏 感兴趣可看:软件测试专栏 自动化测试学习部分源码 python自动化测试相关知识: 【如何学习Python自动化测试】—— 自动化测试环境搭建 【如何学习python自动化测试】—— 浏览器驱动的安装 以及 如何更…

Python中的TesserOCR:文字识别的全方位指南

更多资料获取 📚 个人网站:ipengtao.com 文字识别在图像处理领域中起到了至关重要的作用,而TesserOCR(Tesseract OCR的Python封装)为开发者提供了一个强大的工具,使得文字识别变得更加便捷。本文将通过详细…

MATLAB 最小二乘直线拟合方法二 (36)

MATLAB 最小二乘直线拟合方法二 (36) 一、算法介绍二、算法实现1.代码2.结果一、算法介绍 这里介绍另一种拟合直线点云的方法,更为简单方便,结果与前者一致,主要内容直接复制代码使用即可,原理简单看代码即可,下面是具体的实现和拟合结果展示 二、算法实现 1.代码 代…

死锁的概念

死锁(Deadlock)、饥饿(Starvation)和死循环(Infinite Loop)是计算机科学中与并发和并行处理相关的三个概念,它们描述了不同类型的问题和情况。 死锁(Deadlock): 定义: 死…

纯前端使用XLSX导出excel表格

1 单个sheet page.js(页面中的导出方法) import { exportExcel } from ../../../utils/exportExcel.js; leadOut() {const arr [{ id: 1, name: 张三, age: 14, sex: 男 },{ id: 2, name: 李四, age: 15, sex: 女 },{ id: 3, name: 王五, age: 16, sex: 男 },];const allR…

全志V3s之U-Boot

1、安装交叉编译器: ARM交叉编译器的官网:交叉编译器 a、使用wget下载: wget https://releases.linaro.org/components/toolchain/binaries/latest/arm-linux-gnueabihf/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf.tar.xzb、解…
最新文章