sobelio / llm-chain

`llm-chain` is a powerful rust crate for building chains in large language models allowing you to summarise text and complete complex tasks
https://llm-chain.xyz
MIT License
1.3k stars 128 forks source link

Access intermediary step results #168

Open b0xtch opened 1 year ago

b0xtch commented 1 year ago

Having the ability to access the result of intermediary results, for example in a sequential chain having the ability to access {{text}}.

    let chain: Chain = Chain::new(vec![
        // First step: make a personalized birthday email
        Step::for_prompt_template(
            prompt!("You are a bot for making personalized greetings", "Make personalized birthday e-mail to the whole company for {{name}} who has their birthday on {{date}}. Include their name")
        ),

        // Second step: summarize the email into a tweet. Importantly, the text parameter becomes the result of the previous prompt.
        Step::for_prompt_template(
            prompt!( "You are an assistant for managing social media accounts for a company", "Summarize this email into a tweet to be sent by the company, use emoji if you can. \n--\n{{text}}")
        )
    ]);

Maybe its possible and I am missing something, feel free to close if that's the case.

ppppqp commented 1 year ago

Maybe we can add hooks to a Step so that the user can react to the input and output for theStep. I am thinking about adding the before and after hooks. In the before hook the user can get the input and in the after hook the user can get the output from the Step. The executor will run those hooks on execution. This will make Chain more flexible & observable & easy to debug. It also makes it possible to modify the intermediate values based on their needs.

If we agree on this, I can start working on it.

b0xtch commented 1 year ago

Maybe we can add hooks to a Step so that the user can react to the input and output for theStep. I am thinking about adding the before and after hooks. In the before hook the user can get the input and in the after hook the user can get the output from the Step. The executor will run those hooks on execution. This will make Chain more flexible & observable & easy to debug. It also makes it possible to modify the intermediate values based on their needs.

If we agree on this, I can start working on it.

Sounds like a great plan. Hooks is a great way to solve it. Being able to observe and use step_n is very helpful as it prevents having to run a completely different step to get that result, costing more.