LangChain RunnableParallel的使用

2个Chain的并行执行:

import ChatGLM
from langchain.chains import LLMChain
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate

from langchain_community.tools.tavily_search import TavilySearchResults
from langchain.chains import LLMMathChain
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_community.document_loaders import TextLoader
from langchain.text_splitter import CharacterTextSplitter
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnableParallel, RunnablePassthrough
from langchain_community.embeddings import JinaEmbeddings


llm = ChatGLM.ChatGLM_LLM()

joke_chain = ChatPromptTemplate.from_template("tell me the history of {topic}, no more than 100 words") | llm
poem_chain = (
    ChatPromptTemplate.from_template("tell me the weather about {topic},no more than 50 words") | llm
)

map_chain = RunnableParallel(joke=joke_chain, poem2=poem_chain)

print(map_chain.invoke({"topic": "beijing"}))

你可能感兴趣的:(LangChain,langchain,前端,javascript)