首页 > 其他分享 >MultiPromptChain--场景切换

MultiPromptChain--场景切换

时间:2024-05-14 14:43:19浏览次数:12  
标签:MultiPromptChain 场景 prompt llm chain -- template router chains

from langchain_community.llms import Ollama
from langchain.chains.router import MultiPromptChain
from langchain.chains import ConversationChain
from langchain.chains.llm import LLMChain
from langchain.prompts import PromptTemplate

llm=Ollama(base_url='http://127.0.0.1:11434',
model='qwen:7b')

physics_template = """You are a very smart physics professor. \
You are great at answering questions about physics in a concise and easy to understand manner. \
When you don't know the answer to a question you admit that you don't know.

Here is a question:
{input}"""


math_template = """You are a very good mathematician. You are great at answering math questions. \
You are so good because you are able to break down hard problems into their component parts, \
answer the component parts, and then put them together to answer the broader question.

Here is a question:
{input}"""

prompt_infos = [
{
"name": "physics",
"description": "Good for answering questions about physics",
"prompt_template": physics_template,
},
{
"name": "math",
"description": "Good for answering math questions",
"prompt_template": math_template,
},
]


destination_chains = {}
for p_info in prompt_infos:
name = p_info["name"]
prompt_template = p_info["prompt_template"]
prompt = PromptTemplate(template=prompt_template, input_variables=["input"])
chain = LLMChain(llm=llm, prompt=prompt)
destination_chains[name] = chain
default_chain = ConversationChain(llm=llm, output_key="text")


from langchain.chains.router.llm_router import LLMRouterChain, RouterOutputParser
from langchain.chains.router.multi_prompt_prompt import MULTI_PROMPT_ROUTER_TEMPLATE

destinations = [f"{p['name']}: {p['description']}" for p in prompt_infos]
destinations_str = "\n".join(destinations)
router_template = MULTI_PROMPT_ROUTER_TEMPLATE.format(destinations=destinations_str)
router_prompt = PromptTemplate(
template=router_template,
input_variables=["input"],
output_parser=RouterOutputParser(),
)
router_chain = LLMRouterChain.from_llm(llm, router_prompt)

chain = MultiPromptChain(
router_chain=router_chain,
destination_chains=destination_chains,
default_chain=default_chain,
verbose=True,
)

print(chain.run("What is black body radiation?"))
 

标签:MultiPromptChain,场景,prompt,llm,chain,--,template,router,chains
From: https://www.cnblogs.com/Zhouzg-2018/p/18191237

相关文章

  • kafka数据一致性
    kafka作为商业级中间件,它在设计时优先考虑的可靠性、可用性,同时兼顾一致性,这是所有分布式都会遇到的cap理论,kafka也不例外;可靠性通过副本机制解决,可用性通过leader和follower机制来解决。   kafka的可靠性,根据ack的设置不同,可靠性不同,ack=-1可靠性最高,但效率会稍微低一点。......
  • MultiPromptChain--精简版
    fromlangchain_community.llmsimportOllamafromlangchain.chains.routerimportMultiPromptChainfromlangchain.chainsimportConversationChainfromlangchain.chains.llmimportLLMChainfromlangchain.promptsimportPromptTemplate#physics_template="&q......
  • vue+element-ui在表格中计算两数差值并让差值>20的字体显示为红色
    <el-table-columnprop="differential"label="差量"class-name="small-paddingfixed-width"><templateslot-scope="scope"><span:c......
  • easyUI datagrid 数据不显示,tablebody 高度为0 的问题
    如下图,接口请求回来数据,表头也显示出来了。打开元素,可以看到table的bbody里面是有数据的,数据也渲染到了页面表格中,但是table的height为0。 排查以下问题:检查数据源格式是否正确,如是JSON数组还是符合easyui要求的对象。确保在datagrid初始化后正确触发数据加载......
  • 系统安全性设计报告
    1.系统密码功能要求安全性要求是无纸化电子公文传输系统首先要满足的要求。由于网络环境的广泛性和复杂性等特点,普通电子文件很容易在网络传输过程中被截取或篡改。而电子公文文件必须具有保密性、严肃性和不可抵赖性的特性,绝对不允许出现此类安全漏洞。为此我们采用了RSA不对称......
  • 加固计划书
    加固计划书SDL介绍安全开发生命周期(SDL)是一种软件开发方法论,旨在通过将安全性纳入软件开发的各个阶段来创建更安全、更健壮的软件。SDL由一系列阶段和活动组成,涵盖了从需求分析到维护的整个软件开发生命周期。以下是SDL的主要阶段和相关活动:需求分析阶段:安全需求收集:确定......
  • Jenkins - [02] 安装部署
    题记部分 一、Jenkins是什么  Jenkins,原名Hudson,2011年改为现在的名字,它是一个开源的实现持续集成的软件工具。官网:https://www.jenkins.io/官网:https://www.jenkins.io/zh/(中文)  Jenkins能实时监控集成中存在的错误,提供详细的日志文件和提醒功能,还能用图表的形式......
  • OpenTelemetry agent 对 Spring Boot 应用的影响:一次 SPI 失效的
    背景前段时间公司领导让我排查一个关于在JDK21环境中使用SpringBoot配合一个JDK18新增的一个SPI(java.net.spi.InetAddressResolverProvider)不生效的问题。但这个不生效的前置条件有点多:JDK的版本得在18+SpringBoot3.x还在额外再配合使用-javaagent:openteleme......
  • 密码方案的应用
    密码方案可以应用于多种场景,包括但不限于以下几个方面:1.个人账户保护:密码方案可以用于保护个人账户的安全,例如电子邮箱、社交媒体账户、在线银行账户等。用户可以设置强密码,并定期更改密码,以防止黑客入侵。2.企业网络安全:密码方案可以用于保护企业内部网络的安全,确保只有授权......
  • Windows系统C盘瘦身
    1.windows系统休眠关闭C:\Hiberfil.sys#关闭系统休眠(可以节省6G空间)powercfg-hoff 2.将windows虚拟内存交换文件设置到D盘C:\Pagefile.sys->D:\ 2.1打开如下开关:  查看C盘根目录下的:C:\Pagefile.sys文件大小,比如12G2.2我的电脑,空白处右键-》属性 -》高级......