core[patch]: fix chat history circular import (#23182)

This commit is contained in:
Bagatur 2024-06-19 09:08:36 -07:00 committed by GitHub
parent 883e90d06e
commit 677408bfc9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 1 deletions

View File

@ -26,7 +26,6 @@ from langchain_core.messages import (
get_buffer_string,
)
from langchain_core.pydantic_v1 import BaseModel, Field
from langchain_core.runnables import run_in_executor
class BaseChatMessageHistory(ABC):
@ -102,6 +101,8 @@ class BaseChatMessageHistory(ABC):
In general, fetching messages may involve IO to the underlying
persistence layer.
"""
from langchain_core.runnables.config import run_in_executor
return await run_in_executor(None, lambda: self.messages)
def add_user_message(self, message: Union[HumanMessage, str]) -> None:
@ -172,6 +173,8 @@ class BaseChatMessageHistory(ABC):
Args:
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)
@abstractmethod
@ -180,6 +183,8 @@ class BaseChatMessageHistory(ABC):
async def aclear(self) -> None:
"""Remove all messages from the store"""
from langchain_core.runnables.config import run_in_executor
await run_in_executor(None, self.clear)
def __str__(self) -> str:

View File

@ -36,6 +36,7 @@ from langchain_core.runnables.config import (
run_in_executor,
)
from langchain_core.runnables.fallbacks import RunnableWithFallbacks
from langchain_core.runnables.history import RunnableWithMessageHistory
from langchain_core.runnables.passthrough import (
RunnableAssign,
RunnablePassthrough,
@ -78,6 +79,7 @@ __all__ = [
"RunnablePick",
"RunnableSequence",
"RunnableWithFallbacks",
"RunnableWithMessageHistory",
"get_config_list",
"aadd",
"add",

View File

@ -26,6 +26,7 @@ EXPECTED_ALL = [
"RunnablePick",
"RunnableSequence",
"RunnableWithFallbacks",
"RunnableWithMessageHistory",
"get_config_list",
"aadd",
"add",