ChatParrotLink Class — langchain Architecture
Architecture documentation for the ChatParrotLink class in custom_chat_model.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 827d4990_b3c8_3ba7_bcd4_0a554daa3db4["ChatParrotLink"] 48aa29b8_65e7_522f_a445_a441eeb6baff["BaseChatModel"] 827d4990_b3c8_3ba7_bcd4_0a554daa3db4 -->|extends| 48aa29b8_65e7_522f_a445_a441eeb6baff e8c09d7d_da16_210c_b993_d1fd1cb09051["custom_chat_model.py"] 827d4990_b3c8_3ba7_bcd4_0a554daa3db4 -->|defined in| e8c09d7d_da16_210c_b993_d1fd1cb09051 8acc69e5_bdb4_2351_c878_2f8a36d8b3c3["_generate()"] 827d4990_b3c8_3ba7_bcd4_0a554daa3db4 -->|method| 8acc69e5_bdb4_2351_c878_2f8a36d8b3c3 ea8bbe3d_c7fc_58bc_8614_aed85432697f["_stream()"] 827d4990_b3c8_3ba7_bcd4_0a554daa3db4 -->|method| ea8bbe3d_c7fc_58bc_8614_aed85432697f f0f57b7f_37fd_95ca_4715_cd163af3cb60["_llm_type()"] 827d4990_b3c8_3ba7_bcd4_0a554daa3db4 -->|method| f0f57b7f_37fd_95ca_4715_cd163af3cb60 1c024976_5d02_41e2_d92a_8da264f528fd["_identifying_params()"] 827d4990_b3c8_3ba7_bcd4_0a554daa3db4 -->|method| 1c024976_5d02_41e2_d92a_8da264f528fd
Relationship Graph
Source Code
libs/standard-tests/tests/unit_tests/custom_chat_model.py lines 18–188
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.
This can be a call to an API, a call to a local model, or any other
implementation that generates a response to the input prompt.
Args:
messages: the prompt composed of a list of messages.
stop: a list of strings on which the model should stop generating.
If generation stops due to a stop token, the stop token itself
SHOULD BE INCLUDED as part of the output. This is not enforced
across models right now, but it's a good practice to follow since
it makes it much easier to parse the output of the model
downstream and understand why generation stopped.
run_manager: A run manager with callbacks for the LLM.
**kwargs: Additional keyword arguments.
"""
# Replace this with actual logic to generate a response from a list
# of messages.
_ = stop # Mark as used to avoid unused variable warning
_ = run_manager # Mark as used to avoid unused variable warning
_ = kwargs # Mark as used to avoid unused variable warning
last_message = messages[-1]
tokens = last_message.content[: self.parrot_buffer_length]
ct_input_tokens = sum(len(message.content) for message in messages)
ct_output_tokens = len(tokens)
message = AIMessage(
content=tokens,
additional_kwargs={}, # Used to add additional payload to the message
response_metadata={ # Use for response metadata
"time_in_seconds": 3,
"model_name": self.model_name,
},
usage_metadata={
"input_tokens": ct_input_tokens,
"output_tokens": ct_output_tokens,
"total_tokens": ct_input_tokens + ct_output_tokens,
},
)
Extends
Source
Frequently Asked Questions
What is the ChatParrotLink class?
ChatParrotLink is a class in the langchain codebase, defined in libs/standard-tests/tests/unit_tests/custom_chat_model.py.
Where is ChatParrotLink defined?
ChatParrotLink is defined in libs/standard-tests/tests/unit_tests/custom_chat_model.py at line 18.
What does ChatParrotLink extend?
ChatParrotLink extends BaseChatModel.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free