Home / File/ summary.py — langchain Source File

summary.py — langchain Source File

Architecture documentation for summary.py, a python file in the langchain codebase. 12 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  3462ec59_2c76_7174_f6f5_47bb43993c57["summary.py"]
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  3462ec59_2c76_7174_f6f5_47bb43993c57 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  b19a8b7e_fbee_95b1_65b8_509a1ed3cad7["langchain_core._api"]
  3462ec59_2c76_7174_f6f5_47bb43993c57 --> b19a8b7e_fbee_95b1_65b8_509a1ed3cad7
  38c69580_3a92_51b1_7512_b0ccca9a0ef6["langchain_core.chat_history"]
  3462ec59_2c76_7174_f6f5_47bb43993c57 --> 38c69580_3a92_51b1_7512_b0ccca9a0ef6
  ba43b74d_3099_7e1c_aac3_cf594720469e["langchain_core.language_models"]
  3462ec59_2c76_7174_f6f5_47bb43993c57 --> ba43b74d_3099_7e1c_aac3_cf594720469e
  d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"]
  3462ec59_2c76_7174_f6f5_47bb43993c57 --> d758344f_537f_649e_f467_b9d7442e86df
  e6b4f61e_7b98_6666_3641_26b069517d4a["langchain_core.prompts"]
  3462ec59_2c76_7174_f6f5_47bb43993c57 --> e6b4f61e_7b98_6666_3641_26b069517d4a
  f4d905c6_a2b2_eb8f_be9b_7808b72f6a16["langchain_core.utils"]
  3462ec59_2c76_7174_f6f5_47bb43993c57 --> f4d905c6_a2b2_eb8f_be9b_7808b72f6a16
  6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"]
  3462ec59_2c76_7174_f6f5_47bb43993c57 --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7
  91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"]
  3462ec59_2c76_7174_f6f5_47bb43993c57 --> 91721f45_4909_e489_8c1f_084f8bd87145
  31974615_0d58_bd26_13f1_776e0a9d1413["langchain_classic.chains.llm"]
  3462ec59_2c76_7174_f6f5_47bb43993c57 --> 31974615_0d58_bd26_13f1_776e0a9d1413
  34f6662f_3e50_5bf7_54f1_05e82f591554["langchain_classic.memory.chat_memory"]
  3462ec59_2c76_7174_f6f5_47bb43993c57 --> 34f6662f_3e50_5bf7_54f1_05e82f591554
  006aa41a_5887_821e_0410_39c9449a6ec1["langchain_classic.memory.prompt"]
  3462ec59_2c76_7174_f6f5_47bb43993c57 --> 006aa41a_5887_821e_0410_39c9449a6ec1
  style 3462ec59_2c76_7174_f6f5_47bb43993c57 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from __future__ import annotations

from typing import Any

from langchain_core._api import deprecated
from langchain_core.chat_history import BaseChatMessageHistory
from langchain_core.language_models import BaseLanguageModel
from langchain_core.messages import BaseMessage, SystemMessage, get_buffer_string
from langchain_core.prompts import BasePromptTemplate
from langchain_core.utils import pre_init
from pydantic import BaseModel
from typing_extensions import override

from langchain_classic.chains.llm import LLMChain
from langchain_classic.memory.chat_memory import BaseChatMemory
from langchain_classic.memory.prompt import SUMMARY_PROMPT


@deprecated(
    since="0.2.12",
    removal="1.0",
    message=(
        "Refer here for how to incorporate summaries of conversation history: "
        "https://docs.langchain.com/oss/python/langgraph/add-memory#summarize-messages"
    ),
)
class SummarizerMixin(BaseModel):
    """Mixin for summarizer."""

    human_prefix: str = "Human"
    ai_prefix: str = "AI"
    llm: BaseLanguageModel
    prompt: BasePromptTemplate = SUMMARY_PROMPT
    summary_message_cls: type[BaseMessage] = SystemMessage

    def predict_new_summary(
        self,
        messages: list[BaseMessage],
        existing_summary: str,
    ) -> str:
        """Predict a new summary based on the messages and existing summary.

        Args:
            messages: List of messages to summarize.
            existing_summary: Existing summary to build upon.

        Returns:
            A new summary string.
        """
        new_lines = get_buffer_string(
            messages,
            human_prefix=self.human_prefix,
            ai_prefix=self.ai_prefix,
        )

        chain = LLMChain(llm=self.llm, prompt=self.prompt)
        return chain.predict(summary=existing_summary, new_lines=new_lines)

    async def apredict_new_summary(
        self,
// ... (109 more lines)

Subdomains

Dependencies

  • langchain_classic.chains.llm
  • langchain_classic.memory.chat_memory
  • langchain_classic.memory.prompt
  • langchain_core._api
  • langchain_core.chat_history
  • langchain_core.language_models
  • langchain_core.messages
  • langchain_core.prompts
  • langchain_core.utils
  • pydantic
  • typing
  • typing_extensions

Frequently Asked Questions

What does summary.py do?
summary.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What does summary.py depend on?
summary.py imports 12 module(s): langchain_classic.chains.llm, langchain_classic.memory.chat_memory, langchain_classic.memory.prompt, langchain_core._api, langchain_core.chat_history, langchain_core.language_models, langchain_core.messages, langchain_core.prompts, and 4 more.
Where is summary.py in the architecture?
summary.py is located at libs/langchain/langchain_classic/memory/summary.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/langchain/langchain_classic/memory).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free