Summarizing long videos
ln Chapter 3, we demonstrated how to summarize long videos (that don’t fit into the context window) with a map-reduce approach. We used LangGraph to design such a workflow. Of course, you can use the same approach to any similar case – for example, to summarize long text or to extract information from long audios. Let’s now do the same using LangChain only, since it will be a useful exercise that will help us to better understand some internals of the framework.
First, a PromptTemplate
doesn’t support media types (as of February 2025), so we need to convert an input to a list of messages manually. To use a parameterized chain, as a workaround, we will create a Python function that takes arguments (always provided by name) and creates a list of messages to be processed. Every message instructs an LLM to summarize a certain piece of the video (by splitting it into offset intervals), and these messages can be processed in parallel...