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)
pull/8250/head
Eugene Yurtsev 1 year ago committed by GitHub
parent 30c2d3cd06
commit ec069381fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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."""

Loading…
Cancel
Save