langchain学习(四)

Interface官方文档

https://python.langchain.com/docs/expression_language/interfaceTo make it as easy as possible to create custom chains, we’vehttps://python.langchain.com/docs/expression_language/interface

1、langchain采用了一个叫“Runnable” 的标准协议/接口,给用户组合部件(component)形成chains,标准化的接口还包括:

stream:流式(实时)返回结果

invoke:单输入

batch:通过列表进行多输入

同时提供以上接口的异步方式

2、component的输入输出类型表

ComponentInput TypeOutput Type
PromptDictionaryPromptValue
ChatModelSingle string, list of chat messages or a PromptValueChatMessage
LLMSingle string, list of chat messages or a PromptValueString
OutputParserThe output of an LLM or ChatModelDepends on the parser
RetrieverSingle stringList of Documents
ToolSingle string or dictionary, depending on the toolDepends on the tool

3、并行请求

方式1通过RunnableParallel

from langchain.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnableParallel
from time import process_time
process_time()
chain1 = ChatPromptTemplate.from_template("tell me a joke about {topic}")
chain2 = (
    ChatPromptTemplate.from_template("write a short (2 line) poem about {topic}")
)
combined = RunnableParallel(joke=chain1, poem=chain2)
print(process_time())

方式2通过batch接口

combined.batch([{"topic": "bears"}, {"topic": "cats"}])

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值