mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-04 04:07:54 +00:00
core: chat_*
docstrings (#23412)
Added missed docstrings. Formatted docstrings to the consistent form.
This commit is contained in:
parent
3b1fcb2a65
commit
75a44fe951
@ -14,6 +14,7 @@
|
|||||||
AIMessage, HumanMessage, BaseMessage
|
AIMessage, HumanMessage, BaseMessage
|
||||||
|
|
||||||
""" # noqa: E501
|
""" # noqa: E501
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
@ -144,6 +145,10 @@ class BaseChatMessageHistory(ABC):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
message: A BaseMessage object to store.
|
message: A BaseMessage object to store.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
NotImplementedError: If the sub-class has not implemented an efficient
|
||||||
|
add_messages method.
|
||||||
"""
|
"""
|
||||||
if type(self).add_messages != BaseChatMessageHistory.add_messages:
|
if type(self).add_messages != BaseChatMessageHistory.add_messages:
|
||||||
# This means that the sub-class has implemented an efficient add_messages
|
# This means that the sub-class has implemented an efficient add_messages
|
||||||
@ -162,16 +167,16 @@ class BaseChatMessageHistory(ABC):
|
|||||||
in an efficient manner to avoid unnecessary round-trips to the underlying store.
|
in an efficient manner to avoid unnecessary round-trips to the underlying store.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
messages: A list of BaseMessage objects to store.
|
messages: A sequence of BaseMessage objects to store.
|
||||||
"""
|
"""
|
||||||
for message in messages:
|
for message in messages:
|
||||||
self.add_message(message)
|
self.add_message(message)
|
||||||
|
|
||||||
async def aadd_messages(self, messages: Sequence[BaseMessage]) -> None:
|
async def aadd_messages(self, messages: Sequence[BaseMessage]) -> None:
|
||||||
"""Add a list of messages.
|
"""Async add a list of messages.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
messages: A list of BaseMessage objects to store.
|
messages: A sequence of BaseMessage objects to store.
|
||||||
"""
|
"""
|
||||||
from langchain_core.runnables.config import run_in_executor
|
from langchain_core.runnables.config import run_in_executor
|
||||||
|
|
||||||
@ -182,7 +187,7 @@ class BaseChatMessageHistory(ABC):
|
|||||||
"""Remove all messages from the store"""
|
"""Remove all messages from the store"""
|
||||||
|
|
||||||
async def aclear(self) -> None:
|
async def aclear(self) -> None:
|
||||||
"""Remove all messages from the store"""
|
"""Async remove all messages from the store"""
|
||||||
from langchain_core.runnables.config import run_in_executor
|
from langchain_core.runnables.config import run_in_executor
|
||||||
|
|
||||||
await run_in_executor(None, self.clear)
|
await run_in_executor(None, self.clear)
|
||||||
@ -199,20 +204,24 @@ class InMemoryChatMessageHistory(BaseChatMessageHistory, BaseModel):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
messages: List[BaseMessage] = Field(default_factory=list)
|
messages: List[BaseMessage] = Field(default_factory=list)
|
||||||
|
"""A list of messages stored in memory."""
|
||||||
|
|
||||||
async def aget_messages(self) -> List[BaseMessage]:
|
async def aget_messages(self) -> List[BaseMessage]:
|
||||||
|
"""Async version of getting messages."""
|
||||||
return self.messages
|
return self.messages
|
||||||
|
|
||||||
def add_message(self, message: BaseMessage) -> None:
|
def add_message(self, message: BaseMessage) -> None:
|
||||||
"""Add a self-created message to the store"""
|
"""Add a self-created message to the store."""
|
||||||
self.messages.append(message)
|
self.messages.append(message)
|
||||||
|
|
||||||
async def aadd_messages(self, messages: Sequence[BaseMessage]) -> None:
|
async def aadd_messages(self, messages: Sequence[BaseMessage]) -> None:
|
||||||
"""Add messages to the store"""
|
"""Async add messages to the store"""
|
||||||
self.add_messages(messages)
|
self.add_messages(messages)
|
||||||
|
|
||||||
def clear(self) -> None:
|
def clear(self) -> None:
|
||||||
|
"""Clear all messages from the store."""
|
||||||
self.messages = []
|
self.messages = []
|
||||||
|
|
||||||
async def aclear(self) -> None:
|
async def aclear(self) -> None:
|
||||||
|
"""Async clear all messages from the store."""
|
||||||
self.clear()
|
self.clear()
|
||||||
|
@ -9,8 +9,16 @@ class BaseChatLoader(ABC):
|
|||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def lazy_load(self) -> Iterator[ChatSession]:
|
def lazy_load(self) -> Iterator[ChatSession]:
|
||||||
"""Lazy load the chat sessions."""
|
"""Lazy load the chat sessions.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
An iterator of chat sessions.
|
||||||
|
"""
|
||||||
|
|
||||||
def load(self) -> List[ChatSession]:
|
def load(self) -> List[ChatSession]:
|
||||||
"""Eagerly load the chat sessions into memory."""
|
"""Eagerly load the chat sessions into memory.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A list of chat sessions.
|
||||||
|
"""
|
||||||
return list(self.lazy_load())
|
return list(self.lazy_load())
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
"""**Chat Sessions** are a collection of messages and function calls.
|
"""**Chat Sessions** are a collection of messages and function calls."""
|
||||||
|
|
||||||
"""
|
|
||||||
from typing import Sequence, TypedDict
|
from typing import Sequence, TypedDict
|
||||||
|
|
||||||
from langchain_core.messages import BaseMessage
|
from langchain_core.messages import BaseMessage
|
||||||
@ -11,6 +10,6 @@ class ChatSession(TypedDict, total=False):
|
|||||||
conversation, channel, or other group of messages."""
|
conversation, channel, or other group of messages."""
|
||||||
|
|
||||||
messages: Sequence[BaseMessage]
|
messages: Sequence[BaseMessage]
|
||||||
"""The LangChain chat messages loaded from the source."""
|
"""A sequence of the LangChain chat messages loaded from the source."""
|
||||||
functions: Sequence[dict]
|
functions: Sequence[dict]
|
||||||
"""The function calling specs for the messages."""
|
"""A sequence of the function calling specs for the messages."""
|
||||||
|
Loading…
Reference in New Issue
Block a user