mirror of
https://github.com/hwchase17/langchain
synced 2024-11-04 06:00:26 +00:00
This PR reverts #8245, so `__add__` is defined on base messages. Resolves issue: https://github.com/langchain-ai/langchain/issues/8472
This commit is contained in:
parent
f31047a394
commit
1ec0b18379
@ -1,12 +1,15 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from abc import abstractmethod
|
||||
from typing import Any, Dict, List, Sequence
|
||||
from typing import TYPE_CHECKING, Any, Dict, 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"
|
||||
@ -77,6 +80,12 @@ 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 BaseMessageChunk(BaseMessage):
|
||||
def _merge_kwargs_dict(
|
||||
@ -102,7 +111,7 @@ class BaseMessageChunk(BaseMessage):
|
||||
)
|
||||
return merged
|
||||
|
||||
def __add__(self, other: Any) -> BaseMessageChunk:
|
||||
def __add__(self, other: Any) -> BaseMessageChunk: # type: ignore
|
||||
if isinstance(other, BaseMessageChunk):
|
||||
# If both are (subclasses of) BaseMessageChunk,
|
||||
# concat into a single BaseMessageChunk
|
||||
|
Loading…
Reference in New Issue
Block a user