[docs]defcreate_summarize_prompt(prompt_message:BaseMessage=HumanMessage(content="Please summarize the documents in a concise manner."),extra_prompt_messages:List[BaseMessagePromptTemplate]=[],)->ChatPromptTemplate:"""Create prompt for this agent. Args: system_message: Message to use as the system message that will be the first in the prompt. extra_prompt_messages: Prompt messages that will be placed between the system message and the new human input. Returns: A prompt template to pass into this agent. """extra_prompt_messages=extra_prompt_messagesor[]messages:List[Union[BaseMessagePromptTemplate,BaseMessage]]ifprompt_message:messages=[prompt_message]else:messages=[prompt_message]+extra_prompt_messagesreturnChatPromptTemplate(messages=messages)
[docs]@beta(message="""Makes use of Cohere's grounded RAG summarization, which may change in a later langchain-cohere version""")defload_summarize_chain(llm:BaseLanguageModel,chain_type:str="stuff",**kwargs:Any,)->RunnableSerializable:"""Load summarizing chain. Args: llm: Language Model to use in the chain. chain_type: Type of document combining chain to use. Currently, only "stuff" is supported in this implementation. verbose: Whether chains should be run in verbose mode or not. Note that this applies to all chains that make up the final chain. Returns: A chain to use for summarizing. """loader_mapping:Dict[str,Callable[[BaseLanguageModel[Any],BasePromptTemplate[Any]],RunnableSerializable[Any,Any],],]={"stuff":_load_stuff_chain,}ifchain_typenotinloader_mapping:raiseValueError(f"Got unsupported chain type: {chain_type}. "f"Should be one of {loader_mapping.keys()}")returnloader_mapping[chain_type](llm,**kwargs)# type: ignore[call-arg]