mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-03 12:07:36 +00:00
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)
This commit is contained in:
@@ -1,15 +1,12 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
from typing import TYPE_CHECKING, Any, List, Sequence
|
from typing import List, Sequence
|
||||||
|
|
||||||
from pydantic import Field
|
from pydantic import Field
|
||||||
|
|
||||||
from langchain.load.serializable import Serializable
|
from langchain.load.serializable import Serializable
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from langchain.prompts.chat import ChatPromptTemplate
|
|
||||||
|
|
||||||
|
|
||||||
def get_buffer_string(
|
def get_buffer_string(
|
||||||
messages: Sequence[BaseMessage], human_prefix: str = "Human", ai_prefix: str = "AI"
|
messages: Sequence[BaseMessage], human_prefix: str = "Human", ai_prefix: str = "AI"
|
||||||
@@ -80,12 +77,6 @@ class BaseMessage(Serializable):
|
|||||||
"""Whether this class is LangChain serializable."""
|
"""Whether this class is LangChain serializable."""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def __add__(self, other: Any) -> ChatPromptTemplate:
|
|
||||||
from langchain.prompts.chat import ChatPromptTemplate
|
|
||||||
|
|
||||||
prompt = ChatPromptTemplate(messages=[self])
|
|
||||||
return prompt + other
|
|
||||||
|
|
||||||
|
|
||||||
class HumanMessage(BaseMessage):
|
class HumanMessage(BaseMessage):
|
||||||
"""A Message from a human."""
|
"""A Message from a human."""
|
||||||
|
Reference in New Issue
Block a user