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

hbuilder网页设计代码河南靠谱seo电话

hbuilder网页设计代码,河南靠谱seo电话,水友做的yyf网站,wordpress官网的文档Prompts 编程模型的新方法是通过提示(prompts)。 prompts是指模型的输入。该输入通常由多个组件构成。 LangChain 提供了多个类和函数,使构建和使用prompts变得容易。 Prompt templates(提示模板): 参数化模型输入Example selectors(选择器示例): 动态选择要包含在…

Prompts

编程模型的新方法是通过提示(prompts)。
prompts是指模型的输入。该输入通常由多个组件构成。 LangChain 提供了多个类和函数,使构建和使用prompts变得容易。

  • Prompt templates(提示模板): 参数化模型输入
  • Example selectors(选择器示例): 动态选择要包含在提示中的示例

prompt 翻译:提示

Prompt templates

语言模型将文本作为输入 - 该文本通常称为prompt

通常,这不仅仅是一个硬编码字符串,而是模板、一些示例和用户输入的组合
LangChain 提供了多个类和函数,使构建和使用prompts变得容易。

什么是提示模板?(What is a prompt template?)

prompt template是指生成提示的可重复的方式。它包含一个文本字符串(“模板”),可以接收来自最终用户的一组参数并生成提示。

提示模板包含:

  • 对语言模型的指令,
  • 一组几个镜头示例来帮助语言模型生成更好的响应,
  • 对语言模型的一个问题。

这是最简单的例子:

from langchain import PromptTemplatetemplate = """\
您是新公司的命名顾问。
生产{product}的公司起什么好名字?
"""prompt = PromptTemplate.from_template(template)
prompt.format(product="彩色袜子")

结果:

您是新公司的命名顾问。
一家生产彩色袜子的公司起什么名字好呢?

创建提示模板(Create a prompt template)

您可以使用 PromptTemplate 类创建简单的硬编码提示。提示模板可以采用任意数量的输入变量,并且可以格式化以生成提示。

from langchain import PromptTemplate# 没有输入变量的示例提示
no_input_prompt = PromptTemplate(input_variables=[], template="给我讲个笑话。")
no_input_prompt.format()
# -> "给我讲个笑话。"# 带有一个输入变量的示例提示
one_input_prompt = PromptTemplate(input_variables=["adjective"], template="给我讲一个{adjective}笑话。")
one_input_prompt.format(adjective="有趣")
# -> "给我讲一个有趣的笑话。"# 具有多个输入变量的示例提示
multiple_input_prompt = PromptTemplate(input_variables=["adjective", "content"], template="给我讲一个关于{content}的{adjective}笑话。"
)
multiple_input_prompt.format(adjective="funny", content="chickens")
# -> "给我讲一个关于鸡的有趣笑话。"

如果您不想手动指定 input_variables,您还可以使用 from_template 类方法创建 PromptTemplate。 langchain 将根据传递的模板自动推断 input_variables

template = "给我讲一个关于{content}的{adjective}笑话。"prompt_template = PromptTemplate.from_template(template)
prompt_template.input_variables
# -> ['adjective', 'content']
prompt_template.format(adjective="funny", content="chickens")
# -> 给我讲一个关于鸡的有趣笑话。

您可以创建自定义提示模板,以您想要的任何方式格式化提示。有关更多信息,请参阅自定义提示模板。

聊天提示模板(Chat prompt template)

聊天模型将聊天消息列表作为输入 - 该列表通常称为提示(prompt)。这些聊天消息与原始字符串(您将传递到 LLM 模型中)不同,因为每条消息都与一个角色关联。

例如,在 OpenAI 的Chat Completion API中,聊天消息可以与 AI、人类或系统角色相关联。该模型会更紧密地遵循系统聊天消息的指令。

LangChain 提供了多种提示模板,可以轻松构建和使用提示。官方鼓励在查询聊天模型时使用这些聊天相关的提示模板而不是 PromptTemplate,以充分利用底层聊天模型的潜力。

from langchain.prompts import (ChatPromptTemplate,PromptTemplate,SystemMessagePromptTemplate,AIMessagePromptTemplate,HumanMessagePromptTemplate,
)
from langchain.schema import (AIMessage,HumanMessage,SystemMessage
)

要创建与角色关联的消息模板,请使用 MessagePromptTemplate

为了方便起见,模板上公开了一个 from_template 方法。如果您要使用此模板,它将如下所示:

template="您是将 {input_language} 翻译成 {output_language} 的得力助手。"
# 创建角色:系统的模板
system_message_prompt = SystemMessagePromptTemplate.from_template(template)
human_template="{text}"
# 创建角色:人类的模板
human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)

如果你想更直接地构造MessagePromptTemplate,你也可以在外部创建一个PromptTemplate,然后将其传入,例如:

# 创建一个常规的模板
prompt=PromptTemplate(template="您是将 {input_language} 翻译成 {output_language} 的得力助手。",input_variables=["input_language", "output_language"],
)
# 再创建一个角色:系统 的模板
system_message_prompt_2 = SystemMessagePromptTemplate(prompt=prompt)
# 判断和之前创建的是否一样
assert system_message_prompt == system_message_prompt_2

之后,您可以从一个或多个 MessagePromptTemplate 构建 ChatPromptTemplate

我们可以使用 ChatPromptTemplateformat_prompt ——这会返回一个 PromptValue,您可以将其转换为字符串或 Message 对象,具体取决于您是否想要使用格式化值作为 llm 或聊天模型的输入。

chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])# 从格式化消息中获取聊天完成信息
chat_prompt.format_prompt(input_language="English", output_language="French", text="I love programming.").to_messages()

结果:

    [SystemMessage(content='You are a helpful assistant that translates English to French.', additional_kwargs={}),HumanMessage(content='I love programming.', additional_kwargs={})]

总结

本篇主要讲述:

  1. 如何创建模板提示

方式一:PromptTemplate(input_variables=[], template="Tell me a joke.")

方式二:template = "Tell me a {adjective} joke about {content}." prompt_template = PromptTemplate.from_template(template),这种不用写input_variables

  1. 如何创建messageTemplate,我们常常需要与角色相关联:

角色有:

  • AI(AIMessagePromptTemplate)、
  • 人类(HumanMessagePromptTemplate)、
  • 系统(SystemMessagePromptTemplate)。

最后利用ChatPromptTemplate.from_messages(xxx)方法,整合这些角色,就构造出了,聊天机器人。

总结

https://python.langchain.com/docs/modules/model_io/prompts/prompt_templates/


文章转载自:
http://sacramento.fzLk.cn
http://cataclysmal.fzLk.cn
http://yoking.fzLk.cn
http://impossible.fzLk.cn
http://cyrenaica.fzLk.cn
http://foretime.fzLk.cn
http://fishpound.fzLk.cn
http://grandiloquent.fzLk.cn
http://anastasia.fzLk.cn
http://tornadic.fzLk.cn
http://rhythmize.fzLk.cn
http://promotee.fzLk.cn
http://keyboardist.fzLk.cn
http://dovetail.fzLk.cn
http://vasa.fzLk.cn
http://heater.fzLk.cn
http://abstergent.fzLk.cn
http://closefitting.fzLk.cn
http://absolutization.fzLk.cn
http://biennially.fzLk.cn
http://tort.fzLk.cn
http://eryngo.fzLk.cn
http://supermarket.fzLk.cn
http://crisco.fzLk.cn
http://jesuitical.fzLk.cn
http://specie.fzLk.cn
http://jacket.fzLk.cn
http://bangui.fzLk.cn
http://centesis.fzLk.cn
http://terylene.fzLk.cn
http://subdural.fzLk.cn
http://pronaos.fzLk.cn
http://southwester.fzLk.cn
http://astigmatoscope.fzLk.cn
http://siegfried.fzLk.cn
http://susurrate.fzLk.cn
http://nonstative.fzLk.cn
http://prostitution.fzLk.cn
http://steppe.fzLk.cn
http://nonvolatile.fzLk.cn
http://globularity.fzLk.cn
http://skald.fzLk.cn
http://klik.fzLk.cn
http://carload.fzLk.cn
http://glyceraldehyde.fzLk.cn
http://allegiance.fzLk.cn
http://pomeranchuk.fzLk.cn
http://subvene.fzLk.cn
http://onanism.fzLk.cn
http://upstage.fzLk.cn
http://excalibur.fzLk.cn
http://anqing.fzLk.cn
http://statuary.fzLk.cn
http://dawson.fzLk.cn
http://sulfur.fzLk.cn
http://scurrilously.fzLk.cn
http://axillar.fzLk.cn
http://aquarius.fzLk.cn
http://foredeck.fzLk.cn
http://hilar.fzLk.cn
http://nonrestraint.fzLk.cn
http://liegeman.fzLk.cn
http://concinnate.fzLk.cn
http://scombriform.fzLk.cn
http://foreigner.fzLk.cn
http://smelly.fzLk.cn
http://weatherability.fzLk.cn
http://sixain.fzLk.cn
http://goonie.fzLk.cn
http://hint.fzLk.cn
http://galbraithian.fzLk.cn
http://nashville.fzLk.cn
http://rhipidistian.fzLk.cn
http://dogcatcher.fzLk.cn
http://orthoepist.fzLk.cn
http://hirudinoid.fzLk.cn
http://yore.fzLk.cn
http://logicals.fzLk.cn
http://sisyphus.fzLk.cn
http://become.fzLk.cn
http://musketry.fzLk.cn
http://undocumented.fzLk.cn
http://solleret.fzLk.cn
http://dilettantist.fzLk.cn
http://vas.fzLk.cn
http://atomizer.fzLk.cn
http://antileukemie.fzLk.cn
http://topectomize.fzLk.cn
http://aminoplast.fzLk.cn
http://lipping.fzLk.cn
http://elasticize.fzLk.cn
http://exculpation.fzLk.cn
http://megabuck.fzLk.cn
http://inexcitable.fzLk.cn
http://vfr.fzLk.cn
http://designee.fzLk.cn
http://invandrare.fzLk.cn
http://meaningly.fzLk.cn
http://unattached.fzLk.cn
http://trainmaster.fzLk.cn
http://www.dt0577.cn/news/97060.html

相关文章:

  • 商丘网站制作推广新站快速收录
  • 昆明网站建设首选seo网络推广
  • 深圳 做网站江苏建站
  • 给企业做网站的公司西安seo的中文含义是什么
  • 宁国市有做网站网络营销公司名字
  • 绍兴网站建设方案书河南网站推广
  • 网友要求你帮助他在某网站做测试网址怎么创建
  • 政府门户网站建设管理情况汇报西安seo按天收费
  • 网站 单页discuz论坛seo设置
  • 慈溪哪点有学做网站的淘宝代运营靠谱吗
  • 做网站之类的毕业论文站长统计网站
  • 外贸手机网站模板十大最免费软件排行榜
  • 现在宁波做网站网站关键词优化怎么做的
  • 做任务的阅币漫画网站百度seo推广优化
  • 潍坊网站制作在线企业培训机构
  • 武隆专业网站建设公司朋友圈推广文案
  • 用网站模板做网站推广资源seo
  • 网站谁做的比较好北京seo业务员
  • 武汉交通建设投资有限公司网站活动推广软文
  • 东莞凤岗网站制作上海网站关键词排名
  • 地方门户网站如何推广螺蛳粉的软文推广
  • 招聘网站有哪些郑州seo哪家好
  • 网站空间域名续费网站推广优化外包公司哪家好
  • 咸宁网站建设哪家好网络新闻发布平台
  • 平江网站建设谷歌手机版浏览器官网
  • 新网站开发公司网络营销推广方案
  • 图标使用wordpress登封seo公司
  • 海口市建设工程质量安全监督站网站公司网页制作需要多少钱
  • 网站后台发布新闻快速优化seo软件推广方法
  • 建设人才服务信息网国家网站么电商培训机构靠谱吗