Repository: acheong08/EdgeGPT
File: src/EdgeGPT/chathub.py (Python)

Code before:
                                == "Apology"
                                and resp_txt
                            ):
                                response["item"]["messages"][-1][
                                    "text"
                                ] = resp_txt_no_link
                                response["item"]["messages"][-1]["adaptiveCards"][0][
                                    "body"
                                ][0]["text"] = resp_txt
                                print(
                                    "Preserved the message from being deleted",
                                    file=sys.stderr,
                                )
                            yield True, response
                            return
                        elif response.get("type") == 6:
                            await wss.send_str(append_identifier({"type": 6}))
                        elif response.get("type") == 7:
                            await wss.send_str(append_identifier({"type": 7}))

    async def _initial_handshake(self, wss: aiohttp.ClientWebSocketResponse) -> None:
        await wss.send_str(append_identifier({"protocol": "json", "version": 1}))
        await wss.receive(timeout=900)
        await wss.send_str(append_identifier({"type": 6}))

    async def close(self) -> None:
        await self.session.aclose()


Review comment (suggestion):
Would prefer to have this as `remove_conversation(conversation_id:str=None, conversation_signature:str=None,client_id:str=None)`

Code after:
                                == "Apology"
                                and resp_txt
                            ):
                                response["item"]["messages"][-1][
                                    "text"
                                ] = resp_txt_no_link
                                response["item"]["messages"][-1]["adaptiveCards"][0][
                                    "body"
                                ][0]["text"] = resp_txt
                                print(
                                    "Preserved the message from being deleted",
                                    file=sys.stderr,
                                )
                            yield True, response
                            return
                        elif response.get("type") == 6:
                            await wss.send_str(append_identifier({"type": 6}))
                        elif response.get("type") == 7:
                            await wss.send_str(append_identifier({"type": 7}))

    async def _initial_handshake(self, wss: aiohttp.ClientWebSocketResponse) -> None:
        await wss.send_str(append_identifier({"protocol": "json", "version": 1}))
        await wss.receive(timeout=900)
        await wss.send_str(append_identifier({"type": 6}))

    async def remove_and_close(self) -> None:
        conversation_id = self.request.conversation_id
        conversation_signature = self.request.conversation_signature
        client_id = self.request.client_id
        url = "https://sydney.bing.com/sydney/DeleteSingleConversation"
        await self.session.post(
            url,
            json={
                "conversationId": conversation_id,
                "conversationSignature": conversation_signature,
                "participant": {"id": client_id},
                "source": "cib",
                "optionsSets": ["autosave"]
            }
        )
        await self.session.aclose()

    async def close(self) -> None:
        await self.session.aclose()