赞
踩
Interface官方文档
1、langchain采用了一个叫“Runnable” 的标准协议/接口,给用户组合部件(component)形成chains,标准化的接口还包括:
invoke:单输入
batch:通过列表进行多输入
同时提供以上接口的异步方式
2、component的输入输出类型表
Component | Input Type | Output Type |
---|---|---|
Prompt | Dictionary | PromptValue |
ChatModel | Single string, list of chat messages or a PromptValue | ChatMessage |
LLM | Single string, list of chat messages or a PromptValue | String |
OutputParser | The output of an LLM or ChatModel | Depends on the parser |
Retriever | Single string | List of Documents |
Tool | Single string or dictionary, depending on the tool | Depends 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"}])
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。