Home / File/ custom_chat_model.py — langchain Source File

custom_chat_model.py — langchain Source File

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

File python CoreAbstractions MessageSchema 9 imports 1 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  9989bf4a_dc02_49dc_a0a6_d4c6b45c2d59["custom_chat_model.py"]
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  9989bf4a_dc02_49dc_a0a6_d4c6b45c2d59 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  ba43b74d_3099_7e1c_aac3_cf594720469e["langchain_core.language_models"]
  9989bf4a_dc02_49dc_a0a6_d4c6b45c2d59 --> ba43b74d_3099_7e1c_aac3_cf594720469e
  d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"]
  9989bf4a_dc02_49dc_a0a6_d4c6b45c2d59 --> d758344f_537f_649e_f467_b9d7442e86df
  4eb42b7a_5c64_04cb_fcec_1401d5c10628["langchain_core.messages.ai"]
  9989bf4a_dc02_49dc_a0a6_d4c6b45c2d59 --> 4eb42b7a_5c64_04cb_fcec_1401d5c10628
  ac2a9b92_4484_491e_1b48_ec85e71e1d58["langchain_core.outputs"]
  9989bf4a_dc02_49dc_a0a6_d4c6b45c2d59 --> ac2a9b92_4484_491e_1b48_ec85e71e1d58
  6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"]
  9989bf4a_dc02_49dc_a0a6_d4c6b45c2d59 --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7
  91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"]
  9989bf4a_dc02_49dc_a0a6_d4c6b45c2d59 --> 91721f45_4909_e489_8c1f_084f8bd87145
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  9989bf4a_dc02_49dc_a0a6_d4c6b45c2d59 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  f3bc7443_c889_119d_0744_aacc3620d8d2["langchain_core.callbacks"]
  9989bf4a_dc02_49dc_a0a6_d4c6b45c2d59 --> f3bc7443_c889_119d_0744_aacc3620d8d2
  style 9989bf4a_dc02_49dc_a0a6_d4c6b45c2d59 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from __future__ import annotations

from typing import TYPE_CHECKING, Any

from langchain_core.language_models import BaseChatModel
from langchain_core.messages import AIMessage, AIMessageChunk, BaseMessage
from langchain_core.messages.ai import UsageMetadata
from langchain_core.outputs import ChatGeneration, ChatGenerationChunk, ChatResult
from pydantic import Field
from typing_extensions import override

if TYPE_CHECKING:
    from collections.abc import Iterator

    from langchain_core.callbacks import CallbackManagerForLLMRun


class ChatParrotLink(BaseChatModel):
    """Chat Parrot Link.

    A custom chat model that echoes the first `parrot_buffer_length` characters
    of the input.

    When contributing an implementation to LangChain, carefully document
    the model including the initialization parameters, include
    an example of how to initialize the model and include any relevant
    links to the underlying models documentation or API.

    Example:
    ```python
    model = ChatParrotLink(parrot_buffer_length=2, model="bird-brain-001")
    result = model.invoke([HumanMessage(content="hello")])
    result = model.batch(
        [
            [HumanMessage(content="hello")],
            [HumanMessage(content="world")],
        ]
    )
    ```
    """

    model_name: str = Field(alias="model")
    """The name of the model"""
    parrot_buffer_length: int
    """The number of characters from the last message of the prompt to be echoed."""
    temperature: float | None = None
    max_tokens: int | None = None
    timeout: int | None = None
    stop: list[str] | None = None
    max_retries: int = 2

    @override
    def _generate(
        self,
        messages: list[BaseMessage],
        stop: list[str] | None = None,
        run_manager: CallbackManagerForLLMRun | None = None,
        **kwargs: Any,
    ) -> ChatResult:
        """Override the _generate method to implement the chat model logic.
// ... (129 more lines)

Subdomains

Functions

Classes

Dependencies

  • collections.abc
  • langchain_core.callbacks
  • langchain_core.language_models
  • langchain_core.messages
  • langchain_core.messages.ai
  • langchain_core.outputs
  • pydantic
  • typing
  • typing_extensions

Frequently Asked Questions

What does custom_chat_model.py do?
custom_chat_model.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, MessageSchema subdomain.
What functions are defined in custom_chat_model.py?
custom_chat_model.py defines 1 function(s): collections.
What does custom_chat_model.py depend on?
custom_chat_model.py imports 9 module(s): collections.abc, langchain_core.callbacks, langchain_core.language_models, langchain_core.messages, langchain_core.messages.ai, langchain_core.outputs, pydantic, typing, and 1 more.
Where is custom_chat_model.py in the architecture?
custom_chat_model.py is located at libs/standard-tests/tests/unit_tests/custom_chat_model.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/standard-tests/tests/unit_tests).

Analyze Your Own Codebase

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

Try Supermodel Free