|
21 | 21 | from .request import ChatHubRequest |
22 | 22 | from .upload_image import upload_image, upload_image_url |
23 | 23 | from .utilities import append_identifier |
24 | | -from .utilities import get_ran_hex |
25 | 24 | from .utilities import guess_locale |
26 | 25 |
|
27 | 26 | ssl_context = ssl.create_default_context() |
@@ -62,36 +61,7 @@ def __init__( |
62 | 61 | self.encrypted_conversation_signature = conversation.struct["encryptedConversationSignature"] |
63 | 62 | else: |
64 | 63 | self.encrypted_conversation_signature = None |
65 | | - |
66 | | - async def get_conversation( |
67 | | - self, |
68 | | - conversation_id: str = None, |
69 | | - conversation_signature: str = None, |
70 | | - client_id: str = None, |
71 | | - ) -> dict: |
72 | | - self.conversation_id = conversation_id or self.request.conversation_id |
73 | | - conversation_signature = ( |
74 | | - conversation_signature or self.request.conversation_signature |
75 | | - ) |
76 | | - client_id = client_id or self.request.client_id |
77 | | - url = f"https://sydney.bing.com/sydney/GetConversation" \ |
78 | | - f"?conversationId={conversation_id}" \ |
79 | | - f"&source=cib&participantId={client_id}" \ |
80 | | - f"&conversationSignature={conversation_signature}" \ |
81 | | - f"&traceId={get_ran_hex()}" |
82 | | - response = await self.session.get(url) |
83 | | - return response.json() |
84 | | - |
85 | | - async def get_activity(self) -> dict: |
86 | | - url = "https://www.bing.com/turing/conversation/chats" |
87 | | - headers = HEADERS_INIT_CONVER.copy() |
88 | | - if self.cookies is not None: |
89 | | - for cookie in self.cookies: |
90 | | - if cookie["name"] == "_U": |
91 | | - headers["Cookie"] = f"SUID=A; _U={cookie['value']};" |
92 | | - break |
93 | | - response = await self.session.get(url, headers=headers) |
94 | | - return response.json() |
| 64 | + self.conversation = conversation |
95 | 65 |
|
96 | 66 | async def ask_stream( |
97 | 67 | self, |
@@ -221,28 +191,20 @@ async def ask_stream( |
221 | 191 | elif raw: |
222 | 192 | yield False, response |
223 | 193 |
|
224 | | - async def delete_conversation( |
225 | | - self, |
226 | | - conversation_id: str = None, |
227 | | - conversation_signature: str = None, |
228 | | - client_id: str = None, |
229 | | - ) -> None: |
230 | | - conversation_id = conversation_id or self.request.conversation_id |
231 | | - conversation_signature = ( |
232 | | - conversation_signature or self.request.conversation_signature |
233 | | - ) |
234 | | - client_id = client_id or self.request.client_id |
235 | | - url = "https://sydney.bing.com/sydney/DeleteSingleConversation" |
236 | | - await self.session.post( |
237 | | - url, |
238 | | - json={ |
239 | | - "conversationId": conversation_id, |
240 | | - "conversationSignature": conversation_signature, |
241 | | - "participant": {"id": client_id}, |
242 | | - "source": "cib", |
243 | | - "optionsSets": ["autosave"], |
244 | | - }, |
245 | | - ) |
246 | | - |
247 | 194 | async def close(self) -> None: |
248 | 195 | await self.session.aclose() |
| 196 | + |
| 197 | + async def get_conversation(self): |
| 198 | + return { |
| 199 | + "conversation_id": self.conversation_id, |
| 200 | + "client_id": self.request.client_id, |
| 201 | + "encrypted_conversation_signature": self.encrypted_conversation_signature, |
| 202 | + "conversation_signature": self.request.conversation_signature, |
| 203 | + } |
| 204 | + |
| 205 | + async def set_conversation(self, conversation_dict: dict): |
| 206 | + self.conversation.struct["conversationId"] = conversation_dict.get("conversation_id") |
| 207 | + self.conversation.struct["client_id"] = conversation_dict.get("client_id") |
| 208 | + self.conversation.struct[ |
| 209 | + "encrypted_conversation_signature"] = conversation_dict.get("encrypted_conversation_signature") |
| 210 | + self.conversation.struct["conversation_signature"] = conversation_dict.get("conversation_signature") |
0 commit comments