Hansimov commited on
Commit
a5ac953
1 Parent(s): 55b0c51

:hammer: [WIP] Enabling get_message_id

Browse files
Files changed (1) hide show
  1. networks/huggingchat_streamer.py +26 -0
networks/huggingchat_streamer.py CHANGED
@@ -92,6 +92,32 @@ class HuggingchatStreamer:
92
  self.conversation_id = conversation_id
93
  return conversation_id
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
 
96
  def log_request(self, url, method="GET"):
97
  logger.note(f"> {method}:", end=" ")
 
92
  self.conversation_id = conversation_id
93
  return conversation_id
94
 
95
+ def get_message_id(self):
96
+ request_url = f"https://huggingface.co/chat/conversation/{self.conversation_id}/__data.json?x-sveltekit-invalidated=11"
97
+ request_headers = HUGGINGCHAT_POST_HEADERS
98
+ extra_headers = {
99
+ "Cookie": f"hf-chat={self.hf_chat_id}",
100
+ }
101
+ request_headers.update(extra_headers)
102
+ logger.note(f"> Message ID:", end=" ")
103
+
104
+ message_id = None
105
+ res = requests.post(
106
+ request_url,
107
+ headers=request_headers,
108
+ proxies=PROXIES,
109
+ timeout=10,
110
+ )
111
+ if res.status_code == 200:
112
+ data = res.json()
113
+ # TODO - extract message_id
114
+
115
+ logger.success(f"[{message_id}]")
116
+ else:
117
+ logger.warn(f"[{res.status_code}]")
118
+ raise ValueError("Failed to get conversation ID!")
119
+
120
+ return message_id
121
 
122
  def log_request(self, url, method="GET"):
123
  logger.note(f"> {method}:", end=" ")