Basically, as a toy problem, I’m attempting to replicate this hilarious Twitter thread where someone created a Shopify plugin generator that would read in Shopify websites, brainstorm plugin ideas, and then send marketing emails to storefront owners to see if they were interested in the plugin.
So far I have a chain called summarize_site_chain
that takes HTML for a Shopify storefront website and returns a summary of the site. I want to pipe this into another chain which I’ll call brainstorm_and_describe_idea_chain
but this is where I’m stuck. brainstorm_and_describe_idea
would work as follows:
It starts with a brainstorm prompt:
messages = [
("user", """Here is a summary of the storefront:
` ` `
{summary}
` ` `
Brainstorm a few ideas for a plugin that matchs this site and then pick the one that you think is best.""")
]
prompt = ChatPromptTemplate.from_messages(messages)
brainstorm_chain = prompt | model
And then what I would like to do is append the message resulting from brainstorm_chain
to the end of messages, and add another message to describe the winning idea in detail. Something like this.
messages.extend(
brainstorm_chain.invoke(summarize_site_output), # this line is problematic
("user", "Now take the winning idea, and write a detailed description of how the users will interact with it and how it will benefit the store.")
)
prompt = ChatPromptTemplate.from_messages(messages)
brainstorm_and_describe_idea_chain = prompt | model
Technically, I guess this could work. I could manually put all of this together like so:
summarize_site_output = summarize_site_chain.invoke(html)
< ... then run the cells above, and then ... >
plugin_idea = brainstorm_and_describe_idea_chain.invoke({})
But this totally side steps the point of LangChain. I want to be able to link summarize_site_chain
and brainstorm_and_describe_idea_chain
together and drive them like so:
full_chain = summarize_site_chain | brainstorm_and_describe_idea_chain
plugin_idea = full_chain.invoke({"html":html})
So to state my request succinctly: How do I create a Runnable (brainstorm_and_describe_idea_chain
) that does 2 runs? On the first run, it collects some brainstorming ideas. On the next run, it appends the ideas to the list of messages, adds another message (“summarize the best idea”) and then runs again. How?