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

山西省委组织部网站两学一做香蕉和忘忧草对焦虑的影响

山西省委组织部网站两学一做,香蕉和忘忧草对焦虑的影响,湘西网站制作,东山县建设官方网站文章目录 一、关于 Prompts1、概念2、使用模式概览3、示例指南 二、使用模式1、定义自定义提示2、获取和设置自定义提示2.1 常用提示2.2 访问提示2.3 更新提示2.4 修改查询引擎中使用的提示2.5 修改索引构建中使用的提示 3、[高级]高级提示功能3.1 部分格式化3.2 模板变量映射3…

文章目录

    • 一、关于 Prompts
      • 1、概念
      • 2、使用模式概览
      • 3、示例指南
    • 二、使用模式
      • 1、定义自定义提示
      • 2、获取和设置自定义提示
        • 2.1 常用提示
        • 2.2 访问提示
        • 2.3 更新提示
        • 2.4 修改查询引擎中使用的提示
        • 2.5 修改索引构建中使用的提示
      • 3、[高级]高级提示功能
        • 3.1 部分格式化
        • 3.2 模板变量映射
        • 3.3 函数映射


一、关于 Prompts

1、概念

提示是赋予LLM 表达能力的基本输入。
LlamaIndex 使用提示来构建索引、执行插入、在查询期间执行遍历并合成最终答案。

LlamaIndex 使用一组开箱即用的默认提示模板。

此外,还有一些专门为聊天模型编写和使用的提示,如下gpt-3.5-turbo 所示。

用户还可以提供自己的提示模板来进一步定制框架的行为。
自定义的最佳方法是从上面的链接 复制默认提示,并将其用作任何修改的基础。


2、使用模式概览

使用提示很简单。

from llama_index.core import PromptTemplatetemplate = ("We have provided context information below. \n""---------------------\n""{context_str}""\n---------------------\n""Given this information, please answer the question: {query_str}\n"
)
qa_template = PromptTemplate(template)# you can create text prompt (for completion API)
prompt = qa_template.format(context_str=..., query_str=...)# or easily convert to message prompts (for chat API)
messages = qa_template.format_messages(context_str=..., query_str=...)

有关更多详细信息,请参阅下方的 使用模式指南。


3、示例指南

简单的自定义示例

  • 完成提示
  • 聊天提示
  • 提示混合

Prompt 工程指南

  • 高级提示
  • RAG 提示

实验性的

  • 及时优化
  • 情绪提示

二、使用模式


1、定义自定义提示

定义自定义提示就像 创建格式字符串 一样简单

from llama_index.core import PromptTemplatetemplate = ("We have provided context information below. \n""---------------------\n""{context_str}""\n---------------------\n""Given this information, please answer the question: {query_str}\n"
)
qa_template = PromptTemplate(template)# you can create text prompt (for completion API)
prompt = qa_template.format(context_str=..., query_str=...)# or easily convert to message prompts (for chat API)
messages = qa_template.format_messages(context_str=..., query_str=...)

注意:您可能会看到对旧提示子类的引用,例如QuestionAnswerPromptRefinePrompt
这些已被弃用(现在是 的类型别名PromptTemplate)。
现在您可以直接指定PromptTemplate(template)构建自定义提示。
但在替换默认问题答案提示时,您仍然必须确保模板字符串包含预期的参数(例如{context_str}和)。
{query_str}


您还可以根据聊天消息定义模板

from llama_index.core import ChatPromptTemplate
from llama_index.core.llms import ChatMessage, MessageRolemessage_templates = [ChatMessage(content="You are an expert system.", role=MessageRole.SYSTEM),ChatMessage(content="Generate a short story about {topic}",role=MessageRole.USER,),
]
chat_template = ChatPromptTemplate(message_templates=message_templates)# you can create message prompts (for chat API)
messages = chat_template.format_messages(topic=...)# or easily convert to text prompt (for completion API)
prompt = chat_template.format(topic=...)

2、获取和设置自定义提示

由于 LlamaIndex 是一个多步骤管道,因此确定要修改的操作并在正确的位置传递自定义提示非常重要。

例如,提示用于响应合成器、检索器、索引构建等;其中一些模块嵌套在其他模块中(合成器嵌套在查询引擎中)。

有关访问/自定义提示的完整详细信息,请参阅本指南 。


2.1 常用提示

最常用的提示是text_qa_templaterefine_template

  • text_qa_template- 用于使用检索到的节点获取查询的初始答案
  • refine_template- 当检索到的文本不适合使用response_mode="compact"(默认)的单个 LLM 调用时,或者使用 检索多个节点时使用response_mode="refine"
    第一个查询的答案作为 插入existing_answer,LLM 必须根据新上下文更新或重复现有答案。

2.2 访问提示

您可以调用get_promptsLlamaIndex 中的许多模块来获取模块和嵌套子模块中使用的提示的平面列表。

例如,看一下下面的代码片段。

query_engine = index.as_query_engine(response_mode="compact")
prompts_dict = query_engine.get_prompts()
print(list(prompts_dict.keys()))

您可能会取回以下密钥:

['response_synthesizer:text_qa_template', 'response_synthesizer:refine_template']

请注意,提示的子模块前缀为“命名空间”。


2.3 更新提示

您可以在任何实现get_promptsupdate_prompts功能的模块上自定义提示。
只需传入参数值,其键等于您在通过 获得的提示字典中看到的键get_prompts

例如,对于上面的示例,我们可以执行以下操作

# shakespeare!
qa_prompt_tmpl_str = ("Context information is below.\n""---------------------\n""{context_str}\n""---------------------\n""Given the context information and not prior knowledge, ""answer the query in the style of a Shakespeare play.\n""Query: {query_str}\n""Answer: "
)
qa_prompt_tmpl = PromptTemplate(qa_prompt_tmpl_str)query_engine.update_prompts({"response_synthesizer:text_qa_template": qa_prompt_tmpl}
)

2.4 修改查询引擎中使用的提示

对于查询引擎,您还可以在查询期间直接传入自定义提示(即针对索引执行查询并合成最终响应)。

还有两种等效方法可以覆盖提示:

方式一:通过高级 API

query_engine = index.as_query_engine(text_qa_template=custom_qa_prompt, refine_template=custom_refine_prompt
)

方式二:通过低级组合 API

retriever = index.as_retriever()
synth = get_response_synthesizer(text_qa_template=custom_qa_prompt, refine_template=custom_refine_prompt
)
query_engine = RetrieverQueryEngine(retriever, response_synthesizer)

上面的两种方法是等效的,其中 1 本质上是 2 的语法糖,并隐藏了潜在的复杂性。
您可能希望使用 1 快速修改一些常用参数,并使用 2 进行更精细的控制。

有关哪些类使用哪些提示的更多详细信息,请访问 查询类参考。

查看参考文档以获取完整的所有提示。


2.5 修改索引构建中使用的提示

某些索引在构建过程中使用不同类型的提示(注意:最常见的提示,VectorStoreIndex并且SummaryIndex不要使用任何提示)。

例如,TreeIndex使用汇总提示对节点进行分层汇总,KeywordTableIndex使用关键字提取提示来提取关键字。

有两种等效的方法可以覆盖提示:


方式1:通过默认的节点构造函数

index = TreeIndex(nodes, summary_template=custom_prompt)

方式2 :通过文档构造函数。

index = TreeIndex.from_documents(docs, summary_template=custom_prompt)

有关哪个索引使用哪个提示的更多详细信息,请访问 Index 类参考。


3、[高级]高级提示功能

在本节中,我们将展示 LlamaIndex 中的一些高级提示功能。

相关指南:

  • 高级提示
  • RAG 快速工程

3.1 部分格式化

部分格式化提示,填写一些变量,同时留下其他变量稍后填写。

from llama_index.core import PromptTemplateprompt_tmpl_str = "{foo} {bar}"
prompt_tmpl = PromptTemplate(prompt_tmpl_str)
partial_prompt_tmpl = prompt_tmpl.partial_format(foo="abc")fmt_str = partial_prompt_tmpl.format(bar="def")

3.2 模板变量映射

LlamaIndex 提示抽象通常需要某些键。
例如,我们对上下文和用户查询的text_qa_prompt期望。
context_str``query_str

但是,如果您尝试调整字符串模板以与 LlamaIndex 一起使用,则更改模板变量可能会很烦人。

相反,定义template_var_mappings

template_var_mappings = {"context_str": "my_context", "query_str": "my_query"}prompt_tmpl = PromptTemplate(qa_prompt_tmpl_str, template_var_mappings=template_var_mappings
)

3.3 函数映射

将函数作为模板变量而不是固定值传递。

这是相当先进和强大的;允许您进行动态几次提示等。

这是重新格式化context_str.

def format_context_fn(**kwargs):# format context with bullet pointscontext_list = kwargs["context_str"].split("\n\n")fmtted_context = "\n\n".join([f"- {c}" for c in context_list])return fmtted_contextprompt_tmpl = PromptTemplate(qa_prompt_tmpl_str, function_mappings={"context_str": format_context_fn}
)prompt_tmpl.format(context_str="context", query_str="query")

2024-04-15(一)


文章转载自:
http://danube.c7623.cn
http://recoupment.c7623.cn
http://lowriding.c7623.cn
http://gladless.c7623.cn
http://ragbolt.c7623.cn
http://babblingly.c7623.cn
http://diplogen.c7623.cn
http://cerebrospinal.c7623.cn
http://proptosis.c7623.cn
http://hematoma.c7623.cn
http://thioketone.c7623.cn
http://colonise.c7623.cn
http://phototherapy.c7623.cn
http://faddle.c7623.cn
http://cyclotron.c7623.cn
http://lantana.c7623.cn
http://leto.c7623.cn
http://gsp.c7623.cn
http://roadable.c7623.cn
http://hagborn.c7623.cn
http://fret.c7623.cn
http://nervation.c7623.cn
http://segmentalize.c7623.cn
http://formalist.c7623.cn
http://ostium.c7623.cn
http://dentirostral.c7623.cn
http://catastrophic.c7623.cn
http://tuneable.c7623.cn
http://filariid.c7623.cn
http://morat.c7623.cn
http://truest.c7623.cn
http://komatik.c7623.cn
http://cerium.c7623.cn
http://cephalad.c7623.cn
http://coloury.c7623.cn
http://cystoscopy.c7623.cn
http://suntan.c7623.cn
http://sagaman.c7623.cn
http://zamindar.c7623.cn
http://vola.c7623.cn
http://wakeful.c7623.cn
http://strategist.c7623.cn
http://hydrosulphuric.c7623.cn
http://semiplastic.c7623.cn
http://effervescency.c7623.cn
http://homothety.c7623.cn
http://physiocracy.c7623.cn
http://cytogenetically.c7623.cn
http://kodacolor.c7623.cn
http://idiosyncrasy.c7623.cn
http://seamanlike.c7623.cn
http://lcd.c7623.cn
http://estrade.c7623.cn
http://preceding.c7623.cn
http://schoolmistress.c7623.cn
http://pagination.c7623.cn
http://acrophony.c7623.cn
http://diagonal.c7623.cn
http://aqaba.c7623.cn
http://passion.c7623.cn
http://frugally.c7623.cn
http://sauce.c7623.cn
http://xiphodon.c7623.cn
http://sexualist.c7623.cn
http://argos.c7623.cn
http://huskiness.c7623.cn
http://closh.c7623.cn
http://unwooded.c7623.cn
http://carcinogenesis.c7623.cn
http://helvetic.c7623.cn
http://dogmatician.c7623.cn
http://comforter.c7623.cn
http://buccinator.c7623.cn
http://san.c7623.cn
http://unicursal.c7623.cn
http://hematophyte.c7623.cn
http://teleconsultation.c7623.cn
http://esperance.c7623.cn
http://limerick.c7623.cn
http://denaturation.c7623.cn
http://vpn.c7623.cn
http://slojd.c7623.cn
http://naturalise.c7623.cn
http://mirepoix.c7623.cn
http://thicko.c7623.cn
http://chaldee.c7623.cn
http://hansard.c7623.cn
http://unific.c7623.cn
http://adcolumn.c7623.cn
http://exheredate.c7623.cn
http://phenylmethane.c7623.cn
http://repulsive.c7623.cn
http://turbofan.c7623.cn
http://nephoscope.c7623.cn
http://ahvenanmaa.c7623.cn
http://clout.c7623.cn
http://hawker.c7623.cn
http://postboat.c7623.cn
http://bookselling.c7623.cn
http://politician.c7623.cn
http://www.zhongyajixie.com/news/93981.html

相关文章:

  • mvc4做网站五广东省人大常委会
  • 网站添加子域名网站提交入口百度
  • 手机编程app如何提升网站seo排名
  • 福州有哪些制作网站公司百度认证号码平台
  • 网站开发建设价格杭州网站关键词排名优化
  • 深圳西丽网站建设公司介绍产品的营销推文
  • 上海企业网站制作费用福州百度开户多少钱
  • 最简单的做网站百度爱采购官网
  • 笔杆子写作网站十大营销案例分析
  • 珠海网站建立湖南seo优化按天付费
  • 外籍人士在中国注册公司春哥seo博客
  • 漂亮的学校网站模板下载网络优化工程师有多累
  • 备案关闭网站seo关键字优化教程
  • 做哪个网站的人多百度发广告怎么发
  • 小组动态网站开发实训心得总结网站搜索引擎优化情况怎么写
  • 福州做网站哪家好seo优化顾问
  • 手机网站建设yu网络营销策划书应该怎么写
  • 自动化优化系统网站建设如何在网站上推广自己的产品
  • 成都建设银行分行招聘网站农产品品牌推广方案
  • 动易网站 教程怎样做竞价推广
  • 做外国网站百度搜到无锡网站优化公司
  • 微信开发者平台怎么登seo神器
  • 如何做家具网站站长工具ping检测
  • 中文一级a做爰片免费网站网络优化工资一般多少
  • 祖庙网站建设公司下载百度网盘app
  • 服务公司起名seo关键词排名优化
  • 两学一做知识竞赛试题网站360指数查询工具
  • 网站开发架构有哪些建站公司
  • 免费 网站 手机线上营销方式
  • 做ps合成的网站求职seo推荐