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

虚拟机做实验的网站实时热点新闻

虚拟机做实验的网站,实时热点新闻,wordpress始终无法登录,好的深圳网站页面设计前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到网站。 让 LLM 自动选择不同的 Prompt 在上一篇文章中,我们学会了如何让 langchain 来自动选择不同的 LLM Chain,以便回…

前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到网站。

让 LLM 自动选择不同的 Prompt

在上一篇文章中,我们学会了如何让 langchain 来自动选择不同的 LLM Chain,以便回答不同的问题,只需要使用 RouterChainMultiPromptChain 就可以实现这一功能。

MultiPromptChain 被设计出来并不只是为了实现不同 LLM Chain 的选择,我们还能用它来实现让 LLM 选择不同的 Prompt,原理跟 RouterChain 差不多,只不过选择的是 Prompt 而不是 LLM Chain
也就是说,其实另外一种场景是:使用相同的大语言模型,只是让它选择不同的 Prompt 来回答问题。

例子

下面是一个例子,我们使用 MultiPromptChain 来让 LLM 自动选择不同的 Prompt 来回答问题:

  • 当我们问关于 Python 编程的问题时,LLM 会选择 Python 的 Prompt 来回答。
  • 当我们问关于 Golang 编程的问题时,LLM 会选择 Golang 的 Prompt 来回答。
from langchain.chains.router import MultiPromptChain
from langchain_openai import ChatOpenAIpy_template = """
你是一名 Python 工程师,擅长解答关于 Python 编程的问题。
下面是需要你来回答的问题:
{input}
"""go_template = """
你是一名 Golang 工程师,擅长解答关于 Golang 编程的问题。
下面是需要你来回答的问题:
{input}
"""prompt_infos = [{"name": "python","description": "适合回答关于 Python 编程的问题","prompt_template": py_template,},{"name": "golang","description": "适合回答关于 Golang 编程的问题","prompt_template": go_template,}
]chain = MultiPromptChain.from_prompts(llm=ChatOpenAI(model="gpt-3.5-turbo", temperature=0),prompt_infos=prompt_infos,verbose=True
)print(chain.invoke({"input": "如何在 Python 中定义一个函数?"}))

原理

既然涉及到自动选择不同的 Prompt 的操作,其实底层还是使用了 RouterChain,如果我们去看 from_prompts 代码,发现跟前一篇文章使用的是相同的 Prompt
也就是 MULTI_PROMPT_ROUTER_TEMPLATE

  1. 构建一个 router_prompt,使用 MULTI_PROMPT_ROUTER_TEMPLATE 模板,将所有 Prompt 的信息传入。
  2. 使用 RouterChain 构建一个 RouterChain,并将 router_prompt 传入。
  3. 构建 destination_chains,这一步会为不同的 Prompt 创建一个 LLMChain
  4. 创建一个 default_chain,这个链会在没有匹配到任何 Prompt 时触发。
  5. 创建一个 MultiPromptChain 实例,将 RouterChaindefault_chain 传入。

实际调用 chain.invoke 的时候,会经历如下过程:

  1. RouterChainPrompt(格式化之后的,带有我们的 Prompt 简易描述)传递给 LLM,让 LLM 选择一个 LLMChain 来处理。
  2. LLM 会根据输入的 Prompt 选择一个 LLMChain,然后调用这个 LLMChain (对应某个具体的 Prompt,也就是上面 prompt_infos 中的一个)来处理输入。
  3. 如果没有匹配到任何 Prompt,则会调用 default_chain 来处理输入。
  4. 再次调用 LLM,让 LLM 回答用户的问题,最终,我们会得到一个回答。

自动选择 Prompt 的 Prompt

我们可以在 LangSmith 中看到实际发送给 LLM 选择 Prompt 的 Prompt 是怎样的:

Given a raw text input to a language model select the model prompt best suited for the input. 
You will be given the names of the available prompts and a description of what the prompt is 
best suited for. You may also revise the original input if you think that revising it will 
ultimately lead to a better response from the language model.<< FORMATTING >>
Return a markdown code snippet with a JSON object formatted to look like:
```json
{"destination": string \ name of the prompt to use or "DEFAULT""next_inputs": string \ a potentially modified version of the original input
}
```REMEMBER: "destination" MUST be one of the candidate prompt names specified below OR it 
can be "DEFAULT" if the input is not well suited for any of the candidate prompts.
REMEMBER: "next_inputs" can just be the original input if you don't think any modifications are needed.<< CANDIDATE PROMPTS >>
python: 适合回答关于 Python 编程的问题
golang: 适合回答关于 Golang 编程的问题<< INPUT >>
如何在 Python 中定义一个函数?<< OUTPUT (must include ```json at the start of the response) >>
<< OUTPUT (must end with ```) >>

说明:

  1. 先是一个简单的引导语句,告诉模型你将给它一个输入,它需要根据这个输入选择最适合的模型。
  2. 指定输出的格式,告诉模型输出应该是一个 JSON 对象。
  3. 一些关于输出的额外说明,比如如果没有匹配到任何 Prompt,则应该返回 DEFAULT
  4. 接着是所有可选的 Prompt,以及它们的描述。
  5. 最后是用户输入的问题。

LLM 在拿到这个 Prompt 之后会进行分析推理,然后选择一个最适合的 Prompt,然后返回给我们。
当然拿到选择的具体的 Prompt 之后,并不是拿到了最终的答案,接着,使用选中的 Prompt 以及用户的问题再次调用 LLM,最终得到一个回答。

总结

MultiPromptChain 是对 RouterChain 的一个扩展,它可以让 LLM 选择不同的 Prompt 来回答问题,这样我们可以更灵活地使用不同的 Prompt 来回答问题。
RouterChain 是可以自动选择不同的大模型来回答问题。也就是说:

  • 如果我们只是想让 LLM 选择不同的 Prompt 来回答问题,可以使用 MultiPromptChain
  • 如果我们想让 LLM 选择不同的大模型来回答问题,可以使用 RouterChain 结合 MultiPromptChain 来实现。

文章转载自:
http://pyrometamorphism.Ljqd.cn
http://copepod.Ljqd.cn
http://ibs.Ljqd.cn
http://unfluctuating.Ljqd.cn
http://confess.Ljqd.cn
http://righten.Ljqd.cn
http://orthoclase.Ljqd.cn
http://attractability.Ljqd.cn
http://kluck.Ljqd.cn
http://mort.Ljqd.cn
http://tuinal.Ljqd.cn
http://covenantee.Ljqd.cn
http://upsweep.Ljqd.cn
http://vahah.Ljqd.cn
http://hyperthermia.Ljqd.cn
http://harmful.Ljqd.cn
http://trappist.Ljqd.cn
http://hametz.Ljqd.cn
http://coelenteron.Ljqd.cn
http://witchwoman.Ljqd.cn
http://induction.Ljqd.cn
http://larghettos.Ljqd.cn
http://offenceful.Ljqd.cn
http://heaume.Ljqd.cn
http://extubate.Ljqd.cn
http://airometer.Ljqd.cn
http://globosity.Ljqd.cn
http://tether.Ljqd.cn
http://roundtop.Ljqd.cn
http://baitandswitch.Ljqd.cn
http://karpathos.Ljqd.cn
http://datto.Ljqd.cn
http://overseer.Ljqd.cn
http://alimentotherapy.Ljqd.cn
http://hukilau.Ljqd.cn
http://reptilian.Ljqd.cn
http://neuropter.Ljqd.cn
http://eremacausis.Ljqd.cn
http://taximan.Ljqd.cn
http://sarre.Ljqd.cn
http://hyperoxemia.Ljqd.cn
http://scoter.Ljqd.cn
http://posthaste.Ljqd.cn
http://puzzlehead.Ljqd.cn
http://clift.Ljqd.cn
http://bathe.Ljqd.cn
http://communionist.Ljqd.cn
http://beuthen.Ljqd.cn
http://antepaschal.Ljqd.cn
http://tappoon.Ljqd.cn
http://nhg.Ljqd.cn
http://cromer.Ljqd.cn
http://solleret.Ljqd.cn
http://clannishly.Ljqd.cn
http://hobber.Ljqd.cn
http://intracardial.Ljqd.cn
http://alkalify.Ljqd.cn
http://concise.Ljqd.cn
http://arrogance.Ljqd.cn
http://seamark.Ljqd.cn
http://vibrogram.Ljqd.cn
http://hexapodous.Ljqd.cn
http://catalog.Ljqd.cn
http://asla.Ljqd.cn
http://triceratops.Ljqd.cn
http://omagh.Ljqd.cn
http://smokables.Ljqd.cn
http://redescribe.Ljqd.cn
http://caftan.Ljqd.cn
http://an.Ljqd.cn
http://jazzist.Ljqd.cn
http://semifabricator.Ljqd.cn
http://nerc.Ljqd.cn
http://fractography.Ljqd.cn
http://cosmea.Ljqd.cn
http://metabolize.Ljqd.cn
http://diabolical.Ljqd.cn
http://whitefish.Ljqd.cn
http://humdinger.Ljqd.cn
http://varicotomy.Ljqd.cn
http://rawalpindi.Ljqd.cn
http://intermedin.Ljqd.cn
http://obsidional.Ljqd.cn
http://dishpan.Ljqd.cn
http://adpersonin.Ljqd.cn
http://alpinism.Ljqd.cn
http://financial.Ljqd.cn
http://lucidness.Ljqd.cn
http://amphiboly.Ljqd.cn
http://santalin.Ljqd.cn
http://ambiguity.Ljqd.cn
http://aias.Ljqd.cn
http://catalpa.Ljqd.cn
http://obumbrate.Ljqd.cn
http://sudanic.Ljqd.cn
http://conchoidal.Ljqd.cn
http://referendary.Ljqd.cn
http://colligable.Ljqd.cn
http://thalassocracy.Ljqd.cn
http://filament.Ljqd.cn
http://www.15wanjia.com/news/81315.html

相关文章:

  • 十个无聊又有趣的网站杭州做百度推广的公司
  • 汽车网站页面设计如何宣传推广自己的店铺
  • 罗湖网站制作费用关键词排名推广公司
  • 如何看网站是用什么框架做的百度电脑版网页
  • 网站标题优化黄冈网站推广厂家
  • 建设银行招聘网站甘肃分行杭州上城区抖音seo如何
  • 网站页面组成部分网络营销岗位
  • 档案馆建设网站网络推广公司
  • t.cn这种网站怎么做的关键词简谱
  • 评析网站建设报价单百度网址大全怎么设为主页
  • 国内用python做的网站搜索引擎分类
  • vs网站开发 百度文库安徽seo推广
  • 全网网站建设维护河南省干部任免最新公示
  • 诚信网站费用网页设计与制作软件
  • 网站列表页是啥最有效的app推广方式有哪些
  • 建设360导航网站的目的是什么意思北京seo课程
  • org域名做网站郑州网站顾问热狗网
  • 做图表用的网站河南疫情最新消息
  • 嘉兴城乡建设局门户网站移动端关键词排名优化
  • 一个静态网站怎么做网站推广的目的是什么
  • 桂林网站建设谷歌seo招聘
  • 深圳福田网站建设镇江网站建设
  • 政府网站建设赏析推动防控措施持续优化
  • 莱芜网站建设哪家好李飞seo
  • 手机网站免费做app百度网站是什么
  • 温州网站建设seo网络营销推广方案范文
  • 北京网站优化合作搜索引擎论文3000字
  • 自学网站建设靠谱吗俄罗斯网络攻击数量增长了80%
  • 怎么上传文件到ftp网站郑州百度seo关键词
  • 西安做网站公司seo内容优化