mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-27 15:00:23 +00:00
patch[Community] Optimize methods in several ChatLoaders (#24806)
There are some static methods in ChatLoaders, try to add @staticmethod decorator for them.
This commit is contained in:
parent
644e0d3463
commit
b38c83ff93
@ -38,7 +38,8 @@ class LangSmithRunChatLoader(BaseChatLoader):
|
|||||||
self.runs = runs
|
self.runs = runs
|
||||||
self.client = client or Client()
|
self.client = client or Client()
|
||||||
|
|
||||||
def _load_single_chat_session(self, llm_run: "Run") -> ChatSession:
|
@staticmethod
|
||||||
|
def _load_single_chat_session(llm_run: "Run") -> ChatSession:
|
||||||
"""
|
"""
|
||||||
Convert an individual LangSmith LLM run to a ChatSession.
|
Convert an individual LangSmith LLM run to a ChatSession.
|
||||||
|
|
||||||
|
@ -28,7 +28,8 @@ class SlackChatLoader(BaseChatLoader):
|
|||||||
if not self.zip_path.exists():
|
if not self.zip_path.exists():
|
||||||
raise FileNotFoundError(f"File {self.zip_path} not found")
|
raise FileNotFoundError(f"File {self.zip_path} not found")
|
||||||
|
|
||||||
def _load_single_chat_session(self, messages: List[Dict]) -> ChatSession:
|
@staticmethod
|
||||||
|
def _load_single_chat_session(messages: List[Dict]) -> ChatSession:
|
||||||
results: List[Union[AIMessage, HumanMessage]] = []
|
results: List[Union[AIMessage, HumanMessage]] = []
|
||||||
previous_sender = None
|
previous_sender = None
|
||||||
for message in messages:
|
for message in messages:
|
||||||
@ -63,7 +64,8 @@ class SlackChatLoader(BaseChatLoader):
|
|||||||
previous_sender = sender
|
previous_sender = sender
|
||||||
return ChatSession(messages=results)
|
return ChatSession(messages=results)
|
||||||
|
|
||||||
def _read_json(self, zip_file: zipfile.ZipFile, file_path: str) -> List[dict]:
|
@staticmethod
|
||||||
|
def _read_json(zip_file: zipfile.ZipFile, file_path: str) -> List[dict]:
|
||||||
"""Read JSON data from a zip subfile."""
|
"""Read JSON data from a zip subfile."""
|
||||||
with zip_file.open(file_path, "r") as f:
|
with zip_file.open(file_path, "r") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
@ -36,7 +36,8 @@ class TelegramChatLoader(BaseChatLoader):
|
|||||||
"""
|
"""
|
||||||
self.path = path if isinstance(path, str) else str(path)
|
self.path = path if isinstance(path, str) else str(path)
|
||||||
|
|
||||||
def _load_single_chat_session_html(self, file_path: str) -> ChatSession:
|
@staticmethod
|
||||||
|
def _load_single_chat_session_html(file_path: str) -> ChatSession:
|
||||||
"""Load a single chat session from an HTML file.
|
"""Load a single chat session from an HTML file.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -82,7 +83,8 @@ class TelegramChatLoader(BaseChatLoader):
|
|||||||
|
|
||||||
return ChatSession(messages=results)
|
return ChatSession(messages=results)
|
||||||
|
|
||||||
def _load_single_chat_session_json(self, file_path: str) -> ChatSession:
|
@staticmethod
|
||||||
|
def _load_single_chat_session_json(file_path: str) -> ChatSession:
|
||||||
"""Load a single chat session from a JSON file.
|
"""Load a single chat session from a JSON file.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -113,7 +115,8 @@ class TelegramChatLoader(BaseChatLoader):
|
|||||||
|
|
||||||
return ChatSession(messages=results)
|
return ChatSession(messages=results)
|
||||||
|
|
||||||
def _iterate_files(self, path: str) -> Iterator[str]:
|
@staticmethod
|
||||||
|
def _iterate_files(path: str) -> Iterator[str]:
|
||||||
"""Iterate over files in a directory or zip file.
|
"""Iterate over files in a directory or zip file.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -86,7 +86,8 @@ class WhatsAppChatLoader(BaseChatLoader):
|
|||||||
logger.debug(f"Could not parse line: {line}")
|
logger.debug(f"Could not parse line: {line}")
|
||||||
return ChatSession(messages=results)
|
return ChatSession(messages=results)
|
||||||
|
|
||||||
def _iterate_files(self, path: str) -> Iterator[str]:
|
@staticmethod
|
||||||
|
def _iterate_files(path: str) -> Iterator[str]:
|
||||||
"""Iterate over the files in a directory or zip file.
|
"""Iterate over the files in a directory or zip file.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
Loading…
Reference in New Issue
Block a user