From ec069381fb927616d0c445f6a9509e6f0389851d Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Tue, 25 Jul 2023 15:12:19 -0400 Subject: [PATCH] Remove operator overloading for BaseMessage (#8245) This PR removes operator overloading for base message. Removing the `+` operating from base message will help make sure that: 1) There's no need to re-define `+` for message chunks 2) That there's no unexpected behavior in terms of types changing (adding two messages yields a ChatPromptTemplate which is not a message) --- libs/langchain/langchain/schema/messages.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/libs/langchain/langchain/schema/messages.py b/libs/langchain/langchain/schema/messages.py index cd85e879a0..a0cbf978d2 100644 --- a/libs/langchain/langchain/schema/messages.py +++ b/libs/langchain/langchain/schema/messages.py @@ -1,15 +1,12 @@ from __future__ import annotations from abc import abstractmethod -from typing import TYPE_CHECKING, Any, List, Sequence +from typing import List, Sequence from pydantic import Field from langchain.load.serializable import Serializable -if TYPE_CHECKING: - from langchain.prompts.chat import ChatPromptTemplate - def get_buffer_string( messages: Sequence[BaseMessage], human_prefix: str = "Human", ai_prefix: str = "AI" @@ -80,12 +77,6 @@ class BaseMessage(Serializable): """Whether this class is LangChain serializable.""" return True - def __add__(self, other: Any) -> ChatPromptTemplate: - from langchain.prompts.chat import ChatPromptTemplate - - prompt = ChatPromptTemplate(messages=[self]) - return prompt + other - class HumanMessage(BaseMessage): """A Message from a human."""