mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-11 13:55:03 +00:00
core[patch]: fix chat history circular import (#23182)
This commit is contained in:
parent
883e90d06e
commit
677408bfc9
@ -26,7 +26,6 @@ from langchain_core.messages import (
|
|||||||
get_buffer_string,
|
get_buffer_string,
|
||||||
)
|
)
|
||||||
from langchain_core.pydantic_v1 import BaseModel, Field
|
from langchain_core.pydantic_v1 import BaseModel, Field
|
||||||
from langchain_core.runnables import run_in_executor
|
|
||||||
|
|
||||||
|
|
||||||
class BaseChatMessageHistory(ABC):
|
class BaseChatMessageHistory(ABC):
|
||||||
@ -102,6 +101,8 @@ class BaseChatMessageHistory(ABC):
|
|||||||
In general, fetching messages may involve IO to the underlying
|
In general, fetching messages may involve IO to the underlying
|
||||||
persistence layer.
|
persistence layer.
|
||||||
"""
|
"""
|
||||||
|
from langchain_core.runnables.config import run_in_executor
|
||||||
|
|
||||||
return await run_in_executor(None, lambda: self.messages)
|
return await run_in_executor(None, lambda: self.messages)
|
||||||
|
|
||||||
def add_user_message(self, message: Union[HumanMessage, str]) -> None:
|
def add_user_message(self, message: Union[HumanMessage, str]) -> None:
|
||||||
@ -172,6 +173,8 @@ class BaseChatMessageHistory(ABC):
|
|||||||
Args:
|
Args:
|
||||||
messages: A list of BaseMessage objects to store.
|
messages: A list of BaseMessage objects to store.
|
||||||
"""
|
"""
|
||||||
|
from langchain_core.runnables.config import run_in_executor
|
||||||
|
|
||||||
await run_in_executor(None, self.add_messages, messages)
|
await run_in_executor(None, self.add_messages, messages)
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
@ -180,6 +183,8 @@ class BaseChatMessageHistory(ABC):
|
|||||||
|
|
||||||
async def aclear(self) -> None:
|
async def aclear(self) -> None:
|
||||||
"""Remove all messages from the store"""
|
"""Remove all messages from the store"""
|
||||||
|
from langchain_core.runnables.config import run_in_executor
|
||||||
|
|
||||||
await run_in_executor(None, self.clear)
|
await run_in_executor(None, self.clear)
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
|
@ -36,6 +36,7 @@ from langchain_core.runnables.config import (
|
|||||||
run_in_executor,
|
run_in_executor,
|
||||||
)
|
)
|
||||||
from langchain_core.runnables.fallbacks import RunnableWithFallbacks
|
from langchain_core.runnables.fallbacks import RunnableWithFallbacks
|
||||||
|
from langchain_core.runnables.history import RunnableWithMessageHistory
|
||||||
from langchain_core.runnables.passthrough import (
|
from langchain_core.runnables.passthrough import (
|
||||||
RunnableAssign,
|
RunnableAssign,
|
||||||
RunnablePassthrough,
|
RunnablePassthrough,
|
||||||
@ -78,6 +79,7 @@ __all__ = [
|
|||||||
"RunnablePick",
|
"RunnablePick",
|
||||||
"RunnableSequence",
|
"RunnableSequence",
|
||||||
"RunnableWithFallbacks",
|
"RunnableWithFallbacks",
|
||||||
|
"RunnableWithMessageHistory",
|
||||||
"get_config_list",
|
"get_config_list",
|
||||||
"aadd",
|
"aadd",
|
||||||
"add",
|
"add",
|
||||||
|
@ -26,6 +26,7 @@ EXPECTED_ALL = [
|
|||||||
"RunnablePick",
|
"RunnablePick",
|
||||||
"RunnableSequence",
|
"RunnableSequence",
|
||||||
"RunnableWithFallbacks",
|
"RunnableWithFallbacks",
|
||||||
|
"RunnableWithMessageHistory",
|
||||||
"get_config_list",
|
"get_config_list",
|
||||||
"aadd",
|
"aadd",
|
||||||
"add",
|
"add",
|
||||||
|
Loading…
Reference in New Issue
Block a user