line):                if current_sender and current_content:                    results = self._append_message_to_results(                        results, current_sender, current_timestamp, current_content)                current_sender, current_timestamp = re.match(self._message_line_regex, line).groups()                current_content = []            else:                current_content.append(line.strip())        if current_sender and current_content:            results = self._append_message_to_results(                results, current_sender, current_timestamp, current_content)        return chat_loaders.ChatSession(messages=results)    def lazy_load(self) -> Iterator[chat_loaders.ChatSession]:        """        Lazy load the messages from the chat file and yield them in the required format.        Yields:            A `ChatSession` object containing the loaded chat messages.        """        yield self._load_single_chat_session_from_txt(self.path)2. Create loaderâ€‹We will point to the file we just wrote to disk.loader = WeChatChatLoader(    path="./wechat_chats.txt",)3. Load Messagesâ€‹Assuming the format is correct, the loader will convert the chats to langchain messages.from typing import Listfrom langchain.chat_loaders.base import ChatSessionfrom langchain.chat_loaders.utils import (    map_ai_messages,    merge_chat_runs,)raw_messages = loader.lazy_load()# Merge consecutive messages from the same sender into a single messagemerged_messages = merge_chat_runs(raw_messages)# Convert messages from "ç”·æœ‹å�‹" to AI messagesmessages: List[ChatSession] = list(map_ai_messages(merged_messages, sender="ç”·æœ‹å�‹"))messages    [{'messages': [HumanMessage(content='å¤©æ°”æœ‰ç‚¹å‡‰', additional_kwargs={'sender': 'å¥³æœ‹å�‹', 'events': [{'message_time': '2023/09/16 2:51 PM'}]}, example=False),       AIMessage(content='ç��ç°Ÿå‡‰é£�è‘—ï¼Œç‘¶ç�´å¯„æ�¨ç”Ÿã€‚åµ‡å�›æ‡’ä¹¦æœ­ï¼Œåº•ç‰©æ…°ç§‹æƒ…ã€‚', additional_kwargs={'sender': 'ç”·æœ‹å�‹', 'events': [{'message_time':
There is not yet a straightforward way to export personal WeChat messages. However if you just need no more than few hundreds of messages for model fine-tuning or few-shot examples, this notebook shows how to create your own chat loader that works on copy-pasted WeChat messages to a list of LangChain messages.
There is not yet a straightforward way to export personal WeChat messages. However if you just need no more than few hundreds of messages for model fine-tuning or few-shot examples, this notebook shows how to create your own chat loader that works on copy-pasted WeChat messages to a list of LangChain messages. ->: line):                if current_sender and current_content:                    results = self._append_message_to_results(                        results, current_sender, current_timestamp, current_content)                current_sender, current_timestamp = re.match(self._message_line_regex, line).groups()                current_content = []            else:                current_content.append(line.strip())        if current_sender and current_content:            results = self._append_message_to_results(                results, current_sender, current_timestamp, current_content)        return chat_loaders.ChatSession(messages=results)    def lazy_load(self) -> Iterator[chat_loaders.ChatSession]:        """        Lazy load the messages from the chat file and yield them in the required format.        Yields:            A `ChatSession` object containing the loaded chat messages.        """        yield self._load_single_chat_session_from_txt(self.path)2. Create loaderâ€‹We will point to the file we just wrote to disk.loader = WeChatChatLoader(    path="./wechat_chats.txt",)3. Load Messagesâ€‹Assuming the format is correct, the loader will convert the chats to langchain messages.from typing import Listfrom langchain.chat_loaders.base import ChatSessionfrom langchain.chat_loaders.utils import (    map_ai_messages,    merge_chat_runs,)raw_messages = loader.lazy_load()# Merge consecutive messages from the same sender into a single messagemerged_messages = merge_chat_runs(raw_messages)# Convert messages from "ç”·æœ‹å�‹" to AI messagesmessages: List[ChatSession] = list(map_ai_messages(merged_messages, sender="ç”·æœ‹å�‹"))messages    [{'messages': [HumanMessage(content='å¤©æ°”æœ‰ç‚¹å‡‰', additional_kwargs={'sender': 'å¥³æœ‹å�‹', 'events': [{'message_time': '2023/09/16 2:51 PM'}]}, example=False),       AIMessage(content='ç��ç°Ÿå‡‰é£�è‘—ï¼Œç‘¶ç�´å¯„æ�¨ç”Ÿã€‚åµ‡å�›æ‡’ä¹¦æœ­ï¼Œåº•ç‰©æ…°ç§‹æƒ…ã€‚', additional_kwargs={'sender': 'ç”·æœ‹å�‹', 'events': [{'message_time':