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

桥梁建设期刊的投稿网站网站开发合同管辖权异议

桥梁建设期刊的投稿网站,网站开发合同管辖权异议,铁岭网站建设 258魔站,wordpress国人主题原文地址#xff1a;【LangChain系列 11】Prompt模版——拼装组合 本文速读#xff1a; 多prompt模版组合 单prompt模版拼装 在平常业务开发中#xff0c;我们常常需要把一些公共模块提取出来作为一个独立的部分#xff0c;然后将业务中去将这些模块进行组合。在LLM应用…原文地址【LangChain系列 11】Prompt模版——拼装组合 本文速读 多prompt模版组合 单prompt模版拼装 在平常业务开发中我们常常需要把一些公共模块提取出来作为一个独立的部分然后将业务中去将这些模块进行组合。在LLM应用开发中我们也会需要采用这种思想比如将一些公共的promt模版独立出来这样prompt模版就可以更好地复用减少不必要的代码保持代码和逻辑的简洁。 LangChain对prompt模版的组合提供两种方式 1. 针对多个prompt模版进行组合。 2. 将多个部分拼装成一个prompt模版。 01 多prompt模版组合 LangChain提供了PipelinePrompt来进行多prompt模版组合。一个PipelinePrompt包含两个部分 最终的prompt模版最终生成的prompt模版。 待组合的prompt模版它是一个列表列表里的每一项包含一个名字和一个prompt模版。 如下面代码所示full_prompt就是最终的 prompt模版input_prompts就是 待组合的prompt模版将input_prompts中的prompt模版最终组合成了full_prompt。 from langchain.prompts.pipeline import PipelinePromptTemplate from langchain.prompts.prompt import PromptTemplatefull_template {introduction}{example}{start} full_prompt PromptTemplate.from_template(full_template)introduction_template You are impersonating {person}. introduction_prompt PromptTemplate.from_template(introduction_template)example_template Heres an example of an interaction: Q: {example_q} A: {example_a} example_prompt PromptTemplate.from_template(example_template)start_template Now, do this for real!Q: {input} A: start_prompt PromptTemplate.from_template(start_template)input_prompts [(introduction, introduction_prompt),(example, example_prompt),(start, start_prompt) ] pipeline_prompt PipelinePromptTemplate(final_promptfull_prompt, pipeline_promptsinput_prompts) print(pipeline_prompt.input_variables) 输出结果 [example_a, person, example_q, input] 执行下面代码 print(pipeline_prompt.format(personElon Musk,example_qWhats your favorite car?,example_aTesla,inputWhats your favorite social media site? )) 输出结果 You are impersonating Elon Musk.Heres an example of an interaction: Q: Whats your favorite car?A: TeslaNow, do this for real!Q: Whats your favorite social media site?A: 02 单prompt模版拼装 单prompt模版拼装是指将多个部分拼装成一个完整的prompt模版一般来说是将字符串与prompt模版拼成一个新的prompt模版。下面主要介绍字符串prompt模版和对话prompt模版这两种模版的拼装通过两个代码示例来介绍它们的用法。 字符串prompt模版 在下面代码中将一个字符串prompt模版和两个字符串通过  拼装起来。 from langchain.prompts import PromptTemplateprompt (PromptTemplate.from_template(Tell me a joke about {topic}) , make it funny \n\nand in {language} ) print(prompt) 输出结果 PromptTemplate(input_variables[language, topic], output_parserNone, partial_variables{}, templateTell me a joke about {topic}, make it funny\n\nand in {language}, template_formatf-string, validate_templateTrue) 执行代码 print(prompt.format(topicsports, languagespanish)) 输出结果 Tell me a joke about sports, make it funny\n\nand in spanish 同样我们可以在LLMChain中使用这个拼装的prompt。 from langchain.chat_models import ChatOpenAI from langchain.chains import LLMChainmodel ChatOpenAI(openai_api_keyxxx) chain LLMChain(llmmodel, promptprompt) chain.run(topicsports, languagespanish) 执行代码输出结果 ¿Por qué el futbolista llevaba un paraguas al partido?\n\nPorque pronosticaban lluvia de goles. 对话prompt模版 在下面代码中将对话prompt中的Message和字符串通过 进行拼装形成一个新的prompt模版不仅可以将Message进行拼装而且可以将MessagePrompt进行拼装不过先要将MessagePrompt中的变量进行赋值。 from langchain.prompts import ChatPromptTemplate, HumanMessagePromptTemplate from langchain.schema import HumanMessage, AIMessage, SystemMessageprompt SystemMessage(contentYou are a nice pirate) new_prompt (prompt HumanMessage(contenthi) AIMessage(contentwhat?) {input} )print(new_prompt.format_messages(inputi said hi)) 输出结果 [SystemMessage(contentYou are a nice pirate, additional_kwargs{}),HumanMessage(contenthi, additional_kwargs{}, exampleFalse),AIMessage(contentwhat?, additional_kwargs{}, exampleFalse),HumanMessage(contenti said hi, additional_kwargs{}, exampleFalse)] 同样地可以在LLMChain中使用它 from langchain.chat_models import ChatOpenAI from langchain.chains import LLMChainmodel ChatOpenAI(openai_api_keyxxx) chain LLMChain(llmmodel, promptnew_prompt) chain.run(i said hi) 执行代码输出结果 Oh, hello! How can I assist you today? 本文小结 本文主要介绍了prompt模版的拼装组合既可以将多个prompt模版进行组合也可以对单个prompt模版进行拼装。 更多最新文章请关注公众号大白爱爬山
http://www.w-s-a.com/news/96397/

相关文章:

  • 群晖 nas 做网站建设网站的报价
  • 白山做网站网站建设 app 优化
  • 畜牧业网站建设官方网站下载拼多多app
  • 网站规划和布局备案网站地址
  • 站长工具流量统计招工信息发布平台
  • 上海网站建设公司排行建设无障碍网站
  • phpcms网站打不开网页制作网站设计稿
  • 博客网站开发环境wordpress 中英文双语
  • 做网站报价表群辉装wordpress
  • 请人做游戏的网站视觉设计师的工作内容
  • 昆明网站建设知名企业博客网站开发
  • 如何做网站网页免费thinkphp网站后台模板
  • 怎么自己做优惠券网站济南小程序开发
  • 南昌网站专业制作做仿站如何获取网站源码
  • qq钓鱼网站wordpress 企业站模板
  • 推进文明网站建设免费设计公司logo设计
  • 做电脑租赁网站server 2008 网站部署
  • 做网站的公司一年能赚多少钱wordpress作者增加分类插件
  • 苏州尚云网站建设专业摄影网站推荐
  • 020网站开发微信公众号直接链接网站怎么做
  • 学做烘焙的网站某网站注册需要邮箱是怎么弄
  • 网站的特效代码公司网站开发的工作内容
  • 网站制作哪家好商城网站建设预算要多少钱
  • 怎么做律所的官方网站微网站可以做商城吗
  • 通用网站后台管理系统(php版)网站备案ip查询网站查询
  • 制作网站代码吗江阴网站建设推广
  • 汕头建网站wordpress文章网址采集
  • 十大景观设计网站用vue框架做的网站
  • 福建省建设监理网官方网站做外贸网站卖什么东西好
  • 公司做网站排名东莞关键词优化推广