= """Write a concise summary of the following:"{text}"CONCISE SUMMARY:"""prompt = PromptTemplate.from_template(prompt_template)# Define LLM chainllm = ChatOpenAI(temperature=0, model_name="gpt-3.5-turbo-16k")llm_chain = LLMChain(llm=llm, prompt=prompt)# Define StuffDocumentsChainstuff_chain = StuffDocumentsChain(    llm_chain=llm_chain, document_variable_name="text")docs = loader.load()print(stuff_chain.run(docs))    The article discusses the concept of building autonomous agents powered by large language models (LLMs). It explores the components of such agents, including planning, memory, and tool use. The article provides case studies and proof-of-concept examples of LLM-powered agents in various domains, such as scientific discovery and generative agents simulation. It also highlights the challenges and limitations of using LLMs in agent systems.Great! We can see that we reproduce the earlier result using the load_summarize_chain.Go deeper‚ÄãYou can easily customize the prompt. You can easily try different LLMs, (e.g., Claude) via the llm parameter.Option 2. Map-Reduce‚ÄãLet's unpack the map reduce approach. For this, we'll first map each document to an individual summary using an LLMChain. Then we'll use a ReduceDocumentsChain to combine those summaries into a single global summary.First, we specfy the LLMChain to use for mapping each document to an individual summary:from langchain.chains.mapreduce import MapReduceChainfrom langchain.text_splitter import CharacterTextSplitterfrom langchain.chains import ReduceDocumentsChain, MapReduceDocumentsChainllm = ChatOpenAI(temperature=0)# Mapmap_template = """The following is a set of documents{docs}Based on this list of docs, please identify the main themes Helpful Answer:"""map_prompt = PromptTemplate.from_template(map_template)map_chain = LLMChain(llm=llm, prompt=map_prompt)We can also use the Prompt Hub to store and fetch prompts.This will work with your LangSmith API key.For example, see the map prompt here.from
Open In Colab
Open In Colab ->: = """Write a concise summary of the following:"{text}"CONCISE SUMMARY:"""prompt = PromptTemplate.from_template(prompt_template)# Define LLM chainllm = ChatOpenAI(temperature=0, model_name="gpt-3.5-turbo-16k")llm_chain = LLMChain(llm=llm, prompt=prompt)# Define StuffDocumentsChainstuff_chain = StuffDocumentsChain(    llm_chain=llm_chain, document_variable_name="text")docs = loader.load()print(stuff_chain.run(docs))    The article discusses the concept of building autonomous agents powered by large language models (LLMs). It explores the components of such agents, including planning, memory, and tool use. The article provides case studies and proof-of-concept examples of LLM-powered agents in various domains, such as scientific discovery and generative agents simulation. It also highlights the challenges and limitations of using LLMs in agent systems.Great! We can see that we reproduce the earlier result using the load_summarize_chain.Go deeper‚ÄãYou can easily customize the prompt. You can easily try different LLMs, (e.g., Claude) via the llm parameter.Option 2. Map-Reduce‚ÄãLet's unpack the map reduce approach. For this, we'll first map each document to an individual summary using an LLMChain. Then we'll use a ReduceDocumentsChain to combine those summaries into a single global summary.First, we specfy the LLMChain to use for mapping each document to an individual summary:from langchain.chains.mapreduce import MapReduceChainfrom langchain.text_splitter import CharacterTextSplitterfrom langchain.chains import ReduceDocumentsChain, MapReduceDocumentsChainllm = ChatOpenAI(temperature=0)# Mapmap_template = """The following is a set of documents{docs}Based on this list of docs, please identify the main themes Helpful Answer:"""map_prompt = PromptTemplate.from_template(map_template)map_chain = LLMChain(llm=llm, prompt=map_prompt)We can also use the Prompt Hub to store and fetch prompts.This will work with your LangSmith API key.For example, see the map prompt here.from