I’ve started working with Langchain to get a feel of it and a lot of the videos seem outdated. After some research I learned about LCEL being used as the other methods seem to be deprecated. In my code I’m trying to use the output of one chain as the input for another but it doesn’t seem to work.
def main():
prompt1 = ChatPromptTemplate.from_messages([
('system', "Answer in less than 20 words."),
('human', '{task}')
])
chain1 = prompt1 | model | {'rep1': StrOutputParser()}
prompt2 = ChatPromptTemplate.from_messages([
# ('system', "You're sleepy."),
('human', 'Translate {rep1} to the {lang} language'),
])
datamap = {
'lang': RunnablePassthrough(),
'rep1': RunnablePassthrough(),
}
chain2 = datamap | prompt2 | model | StrOutputParser()
allchain = chain1 | chain2
response = allchain.invoke({
'task': 'What date is today?',
'lang': 'french'
})
print(response)
I wrote this off the bat so I understand if it’s not optimized in any way but I’m curious to also know how this would would be done in production.