Skip to content

Commit

Permalink
Merge pull request #202 from Soulter/201-error-when-editing
Browse files Browse the repository at this point in the history
Fix an error when change conversation which context has been edited.
  • Loading branch information
Soulter authored Apr 24, 2024
2 parents c25ad1b + a074eca commit 9333f70
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/hugchat/hugchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
Expand All @@ -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(
Expand Down

0 comments on commit 9333f70

Please sign in to comment.