Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an error when change conversation which context has been edited. #202

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading