From a074eca9203427c8e2b4acc0ab5e14214dd308fe Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Wed, 24 Apr 2024 15:18:04 +0800 Subject: [PATCH] fix: add some checks of a message node --- src/hugchat/hugchat.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/hugchat/hugchat.py b/src/hugchat/hugchat.py index 15d37cc..3a9ac03 100644 --- a/src/hugchat/hugchat.py +++ b/src/hugchat/hugchat.py @@ -511,9 +511,9 @@ def get_conversation_info(self, conversation: Conversation = None) -> Conversati if conversation is None: conversation = self.current_conversation - r = self.session.post( + r = self.session.get( self.hf_base_url + - f"/chat/conversation/{conversation.id}/__data.json", + f"/chat/conversation/{conversation.id}/__data.json?x-sveltekit-invalidated=01", headers=self.get_headers(ref=False), cookies=self.get_cookies(), ) @@ -535,14 +535,17 @@ def get_conversation_info(self, conversation: Conversation = None) -> Conversati # parse all message nodes (history) in the conversation for index in messages: # node's index _node_meta = data[index] + # created_at and updated_at may not in the metadata of a message node. + created_at = datetime.datetime.strptime( + data[_node_meta["createdAt"]][1], "%Y-%m-%dT%H:%M:%S.%fZ").timestamp() if 'createdAt' in _node_meta else None + updated_at = datetime.datetime.strptime( + data[_node_meta["updatedAt"]][1], "%Y-%m-%dT%H:%M:%S.%fZ").timestamp() if 'updatedAt' in _node_meta else None conversation.history.append(MessageNode( id=data[_node_meta["id"]], role=data[_node_meta["from"]], content=data[_node_meta["content"]], - created_at=datetime.datetime.strptime( - data[_node_meta["createdAt"]][1], "%Y-%m-%dT%H:%M:%S.%fZ").timestamp(), - updated_at=datetime.datetime.strptime( - data[_node_meta["updatedAt"]][1], "%Y-%m-%dT%H:%M:%S.%fZ").timestamp() + created_at=created_at, + updated_at=updated_at, )) logging.debug(