mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-12-25 04:01:52 +03:00
~ | g4f v-0.1.4.8 - Fixed g4f.Provider.Bing
implemented new "X-Sydney-EncryptedConversationSignature" found in headers from "turing/conversation/create"
This commit is contained in:
parent
8471ada090
commit
0bd5730bcd
@ -4,7 +4,7 @@ By using this repository or any code related to it, you agree to the [legal noti
|
|||||||
|
|
||||||
### New
|
### New
|
||||||
- official website: *https://g4f.ai*
|
- 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
|
```sh
|
||||||
pip install -U g4f
|
pip install -U g4f
|
||||||
```
|
```
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import random
|
import random
|
||||||
|
import uuid
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
@ -57,14 +58,39 @@ class Conversation():
|
|||||||
self.conversationSignature = conversationSignature
|
self.conversationSignature = conversationSignature
|
||||||
|
|
||||||
async def create_conversation(session: ClientSession) -> Conversation:
|
async def create_conversation(session: ClientSession) -> Conversation:
|
||||||
url = 'https://www.bing.com/turing/conversation/create'
|
url = 'https://www.bing.com/turing/conversation/create?bundleVersion=1.1055.6'
|
||||||
async with await session.get(url) as response:
|
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()
|
response = await response.json()
|
||||||
conversationId = response.get('conversationId')
|
conversationId = response.get('conversationId')
|
||||||
clientId = response.get('clientId')
|
clientId = response.get('clientId')
|
||||||
conversationSignature = response.get('conversationSignature')
|
|
||||||
|
|
||||||
if not conversationId or not clientId or not conversationSignature:
|
if not conversationId or not clientId:
|
||||||
raise Exception('Failed to create conversation.')
|
raise Exception('Failed to create conversation.')
|
||||||
|
|
||||||
return Conversation(conversationId, clientId, conversationSignature)
|
return Conversation(conversationId, clientId, conversationSignature)
|
||||||
@ -249,7 +275,7 @@ async def stream_generate(
|
|||||||
conversation = await retry_conversation(session)
|
conversation = await retry_conversation(session)
|
||||||
try:
|
try:
|
||||||
async with session.ws_connect(
|
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,
|
autoping=False,
|
||||||
) as wss:
|
) as wss:
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ from .typing import Any, CreateResult, Union
|
|||||||
from requests import get
|
from requests import get
|
||||||
|
|
||||||
logging = False
|
logging = False
|
||||||
version = '0.1.4.7'
|
version = '0.1.4.8'
|
||||||
|
|
||||||
def check_pypi_version():
|
def check_pypi_version():
|
||||||
try:
|
try:
|
||||||
|
2
setup.py
2
setup.py
@ -14,7 +14,7 @@ with open("requirements.txt") as f:
|
|||||||
with open("interference/requirements.txt") as f:
|
with open("interference/requirements.txt") as f:
|
||||||
api_required = f.read().splitlines()
|
api_required = f.read().splitlines()
|
||||||
|
|
||||||
VERSION = '0.1.4.7'
|
VERSION = '0.1.4.8'
|
||||||
DESCRIPTION = (
|
DESCRIPTION = (
|
||||||
"The official gpt4free repository | various collection of powerful language models"
|
"The official gpt4free repository | various collection of powerful language models"
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user