summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/bing/conversation.py
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-01-10 10:34:56 +0100
committerGitHub <noreply@github.com>2024-01-10 10:34:56 +0100
commitbee75be8e38d25c4568c641412a49b576d425b24 (patch)
tree63ea1505dbe2b84c3011164a7b2699e642d94c19 /g4f/Provider/bing/conversation.py
parentMerge pull request #1441 from w453y/patch-1 (diff)
downloadgpt4free-bee75be8e38d25c4568c641412a49b576d425b24.tar
gpt4free-bee75be8e38d25c4568c641412a49b576d425b24.tar.gz
gpt4free-bee75be8e38d25c4568c641412a49b576d425b24.tar.bz2
gpt4free-bee75be8e38d25c4568c641412a49b576d425b24.tar.lz
gpt4free-bee75be8e38d25c4568c641412a49b576d425b24.tar.xz
gpt4free-bee75be8e38d25c4568c641412a49b576d425b24.tar.zst
gpt4free-bee75be8e38d25c4568c641412a49b576d425b24.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/bing/conversation.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/g4f/Provider/bing/conversation.py b/g4f/Provider/bing/conversation.py
new file mode 100644
index 00000000..ef45cd82
--- /dev/null
+++ b/g4f/Provider/bing/conversation.py
@@ -0,0 +1,43 @@
+from aiohttp import ClientSession
+
+
+class Conversation():
+ def __init__(self, conversationId: str, clientId: str, conversationSignature: str) -> None:
+ self.conversationId = conversationId
+ self.clientId = clientId
+ self.conversationSignature = conversationSignature
+
+async def create_conversation(session: ClientSession, proxy: str = None) -> Conversation:
+ url = 'https://www.bing.com/turing/conversation/create?bundleVersion=1.1199.4'
+ async with session.get(url, proxy=proxy) as response:
+ data = await response.json()
+
+ conversationId = data.get('conversationId')
+ clientId = data.get('clientId')
+ conversationSignature = response.headers.get('X-Sydney-Encryptedconversationsignature')
+
+ if not conversationId or not clientId or not conversationSignature:
+ raise Exception('Failed to create conversation.')
+ return Conversation(conversationId, clientId, conversationSignature)
+
+async def list_conversations(session: ClientSession) -> list:
+ url = "https://www.bing.com/turing/conversation/chats"
+ async with session.get(url) as response:
+ response = await response.json()
+ return response["chats"]
+
+async def delete_conversation(session: ClientSession, conversation: Conversation, proxy: str = None) -> list:
+ url = "https://sydney.bing.com/sydney/DeleteSingleConversation"
+ json = {
+ "conversationId": conversation.conversationId,
+ "conversationSignature": conversation.conversationSignature,
+ "participant": {"id": conversation.clientId},
+ "source": "cib",
+ "optionsSets": ["autosave"]
+ }
+ try:
+ async with session.post(url, json=json, proxy=proxy) as response:
+ response = await response.json()
+ return response["result"]["value"] == "Success"
+ except:
+ return False \ No newline at end of file