Spaces:
Paused
Paused
:recycle: [Refactor] Seperate ConversationConnectRequestHeadersConstructor
Browse files- conversation_connector.py +22 -15
conversation_connector.py
CHANGED
|
@@ -13,6 +13,26 @@ from logger.logger import logger
|
|
| 13 |
http_proxy = "http://localhost:11111" # Replace with yours
|
| 14 |
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
class ConversationConnector:
|
| 17 |
def __init__(
|
| 18 |
self,
|
|
@@ -43,22 +63,10 @@ class ConversationConnector:
|
|
| 43 |
|
| 44 |
async def stream_chat(self, prompt=""):
|
| 45 |
self.aiohttp_session = aiohttp.ClientSession(cookies=self.cookies)
|
| 46 |
-
|
| 47 |
-
"Accept-Encoding": " gzip, deflate, br",
|
| 48 |
-
"Accept-Language": "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7",
|
| 49 |
-
"Cache-Control": "no-cache",
|
| 50 |
-
"Connection": "Upgrade",
|
| 51 |
-
"Host": "sydney.bing.com",
|
| 52 |
-
"Origin": "https://www.bing.com",
|
| 53 |
-
"Pragma": "no-cache",
|
| 54 |
-
"Sec-Websocket-Extensions": "permessage-deflate; client_max_window_bits",
|
| 55 |
-
"Sec-Websocket-Version": "13",
|
| 56 |
-
"Upgrade": "websocket",
|
| 57 |
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
|
| 58 |
-
}
|
| 59 |
self.wss = await self.aiohttp_session.ws_connect(
|
| 60 |
self.ws_url,
|
| 61 |
-
headers=request_headers,
|
| 62 |
proxy=http_proxy,
|
| 63 |
)
|
| 64 |
|
|
@@ -70,7 +78,6 @@ class ConversationConnector:
|
|
| 70 |
conversation_id=self.conversation_id,
|
| 71 |
invocation_id=self.invocation_id,
|
| 72 |
)
|
| 73 |
-
chathub_request_constructor.construct()
|
| 74 |
|
| 75 |
await self.wss_send(chathub_request_constructor.request_payload)
|
| 76 |
|
|
|
|
| 13 |
http_proxy = "http://localhost:11111" # Replace with yours
|
| 14 |
|
| 15 |
|
| 16 |
+
class ConversationConnectRequestHeadersConstructor:
|
| 17 |
+
def __init__(self):
|
| 18 |
+
self.construct()
|
| 19 |
+
|
| 20 |
+
def construct(self):
|
| 21 |
+
self.request_headers = {
|
| 22 |
+
"Accept-Encoding": " gzip, deflate, br",
|
| 23 |
+
"Accept-Language": "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7",
|
| 24 |
+
"Cache-Control": "no-cache",
|
| 25 |
+
"Connection": "Upgrade",
|
| 26 |
+
"Host": "sydney.bing.com",
|
| 27 |
+
"Origin": "https://www.bing.com",
|
| 28 |
+
"Pragma": "no-cache",
|
| 29 |
+
"Sec-Websocket-Extensions": "permessage-deflate; client_max_window_bits",
|
| 30 |
+
"Sec-Websocket-Version": "13",
|
| 31 |
+
"Upgrade": "websocket",
|
| 32 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
|
| 36 |
class ConversationConnector:
|
| 37 |
def __init__(
|
| 38 |
self,
|
|
|
|
| 63 |
|
| 64 |
async def stream_chat(self, prompt=""):
|
| 65 |
self.aiohttp_session = aiohttp.ClientSession(cookies=self.cookies)
|
| 66 |
+
request_headers_constructor = ConversationConnectRequestHeadersConstructor()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
self.wss = await self.aiohttp_session.ws_connect(
|
| 68 |
self.ws_url,
|
| 69 |
+
headers=request_headers_constructor.request_headers,
|
| 70 |
proxy=http_proxy,
|
| 71 |
)
|
| 72 |
|
|
|
|
| 78 |
conversation_id=self.conversation_id,
|
| 79 |
invocation_id=self.invocation_id,
|
| 80 |
)
|
|
|
|
| 81 |
|
| 82 |
await self.wss_send(chathub_request_constructor.request_payload)
|
| 83 |
|