From 0bd5730bcd5de82d77d90e256661e5d9626d8264 Mon Sep 17 00:00:00 2001 From: abc <98614666+xtekky@users.noreply.github.com> Date: Wed, 4 Oct 2023 21:04:31 +0100 Subject: ~ | g4f v-0.1.4.8 - Fixed `g4f.Provider.Bing` implemented new "X-Sydney-EncryptedConversationSignature" found in headers from "turing/conversation/create" --- README.md | 2 +- g4f/Provider/Bing.py | 42 ++++++++++++++++++++++++++++++++++-------- g4f/__init__.py | 2 +- setup.py | 2 +- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index ffd406ad..1d26700d 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ By using this repository or any code related to it, you agree to the [legal noti ### New - official website: *https://g4f.ai* -- latest pypi version: ([0.1.4.7](https://pypi.org/project/g4f/0.1.4.7)): +- latest pypi version: ([0.1.4.8](https://pypi.org/project/g4f/0.1.4.8)): ```sh pip install -U g4f ``` diff --git a/g4f/Provider/Bing.py b/g4f/Provider/Bing.py index 940b3a0b..e333f132 100644 --- a/g4f/Provider/Bing.py +++ b/g4f/Provider/Bing.py @@ -1,6 +1,7 @@ from __future__ import annotations import random +import uuid import json import os import urllib.parse @@ -57,14 +58,39 @@ class Conversation(): self.conversationSignature = conversationSignature async def create_conversation(session: ClientSession) -> Conversation: - url = 'https://www.bing.com/turing/conversation/create' - async with await session.get(url) as response: - response = await response.json() + url = 'https://www.bing.com/turing/conversation/create?bundleVersion=1.1055.6' + headers = { + 'authority': 'www.bing.com', + 'accept': 'application/json', + 'accept-language': 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3', + 'cache-control': 'no-cache', + 'pragma': 'no-cache', + 'referer': 'https://www.bing.com/search?q=Bing+AI&showconv=1', + 'sec-ch-ua': '"Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117"', + 'sec-ch-ua-arch': '"arm"', + 'sec-ch-ua-bitness': '"64"', + 'sec-ch-ua-full-version': '"117.0.5938.132"', + 'sec-ch-ua-full-version-list': '"Google Chrome";v="117.0.5938.132", "Not;A=Brand";v="8.0.0.0", "Chromium";v="117.0.5938.132"', + 'sec-ch-ua-mobile': '?0', + 'sec-ch-ua-model': '""', + 'sec-ch-ua-platform': '"macOS"', + 'sec-ch-ua-platform-version': '"14.0.0"', + 'sec-fetch-dest': 'empty', + 'sec-fetch-mode': 'cors', + 'sec-fetch-site': 'same-origin', + 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36', + 'x-ms-client-request-id': str(uuid.uuid4()), + 'x-ms-useragent': 'azsdk-js-api-client-factory/1.0.0-beta.1 core-rest-pipeline/1.12.0 OS/macOS', + } + + async with await session.get(url, headers=headers) as response: + conversationSignature = response.headers.get('X-Sydney-EncryptedConversationSignature', '') + + response = await response.json() conversationId = response.get('conversationId') - clientId = response.get('clientId') - conversationSignature = response.get('conversationSignature') - - if not conversationId or not clientId or not conversationSignature: + clientId = response.get('clientId') + + if not conversationId or not clientId: raise Exception('Failed to create conversation.') return Conversation(conversationId, clientId, conversationSignature) @@ -249,7 +275,7 @@ async def stream_generate( conversation = await retry_conversation(session) try: async with session.ws_connect( - 'wss://sydney.bing.com/sydney/ChatHub', + f'wss://sydney.bing.com/sydney/ChatHub?sec_access_token={urllib.parse.quote_plus(conversation.conversationSignature)}', autoping=False, ) as wss: diff --git a/g4f/__init__.py b/g4f/__init__.py index b390775d..9fb6f672 100644 --- a/g4f/__init__.py +++ b/g4f/__init__.py @@ -5,7 +5,7 @@ from .typing import Any, CreateResult, Union from requests import get logging = False -version = '0.1.4.7' +version = '0.1.4.8' def check_pypi_version(): try: diff --git a/setup.py b/setup.py index 3a314a7d..2602caa7 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ with open("requirements.txt") as f: with open("interference/requirements.txt") as f: api_required = f.read().splitlines() -VERSION = '0.1.4.7' +VERSION = '0.1.4.8' DESCRIPTION = ( "The official gpt4free repository | various collection of powerful language models" ) -- cgit v1.2.3