1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Aggregating output from langchain LCEL elements

Discussão em 'Python' iniciado por Stack, Setembro 28, 2024 às 03:12.

  1. Stack

    Stack Membro Participativo

    I have two chains, one that generates a document and one that creates a short document resume. I want to chain them, using the output from the first on inside the other one. But I want to get both outputs in the result.

    Before LCEL, I could do it using LLMChain's output_key parameter. With LCEL, there seems to be a RunnablePassthrough class, but I don't seem to get how to use it to aggregate the output. Code example:

    generate_document_chain = generate_document_prompt | llm | StrOutputParser()
    resume_document_chain = resume_document_prompt | llm | StrOutputParser()

    aggregated_chain = generate_document_chain | resume_document_chain
    content = aggregated_chain.invoke({"topic": topic})

    Continue reading...

Compartilhe esta Página