Hansimov commited on
Commit
e85c831
1 Parent(s): 6ad10eb

:recycle: [Refactor] Prettify names and comments

Browse files
Files changed (1) hide show
  1. conversation_connector.py +9 -9
conversation_connector.py CHANGED
@@ -37,20 +37,23 @@ class ConversationConnectRequestHeadersConstructor:
37
  class ConversationConnector:
38
  def __init__(
39
  self,
 
40
  sec_access_token=None,
41
  client_id=None,
42
  conversation_id=None,
43
  invocation_id=0,
44
  cookies={},
45
  ):
 
46
  self.sec_access_token = sec_access_token
 
47
  self.client_id = client_id
48
  self.conversation_id = conversation_id
49
  self.invocation_id = invocation_id
50
  self.cookies = cookies
51
  self.ws_url = (
52
- "wss://sydney.bing.com/sydney/ChatHub"
53
- + f"?sec_access_token={urllib.parse.quote(self.sec_access_token)}"
54
  )
55
 
56
  async def wss_send(self, message):
@@ -75,7 +78,7 @@ class ConversationConnector:
75
  async def send_chathub_request(self, prompt):
76
  chathub_request_constructor = ChathubRequestConstructor(
77
  prompt=prompt,
78
- conversation_style="precise",
79
  client_id=self.client_id,
80
  conversation_id=self.conversation_id,
81
  invocation_id=self.invocation_id,
@@ -99,19 +102,17 @@ class ConversationConnector:
99
  for line in response_lines:
100
  if not line:
101
  continue
 
102
  data = json.loads(line)
103
 
104
  # Stream: Meaningful Messages
105
  if data.get("type") == 1:
106
  message_parser.parse(data)
107
- # Stream: List of whole conversation messages
108
  elif data.get("type") == 2:
109
  if data.get("item"):
110
  item = data.get("item")
111
  logger.note("\n[Saving chat messages ...]")
112
- # for message in item.get("messages"):
113
- # author = message["author"]
114
- # message_text = message["text"]
115
  # Stream: End of Conversation
116
  elif data.get("type") == 3:
117
  logger.success("[Finished]")
@@ -119,12 +120,11 @@ class ConversationConnector:
119
  await self.wss.close()
120
  await self.aiohttp_session.close()
121
  break
122
- # Stream: Signal
123
  elif data.get("type") == 6:
124
  continue
125
  # Stream: Not Monitored
126
  else:
127
- # pprint.pprint(data)
128
  continue
129
 
130
 
 
37
  class ConversationConnector:
38
  def __init__(
39
  self,
40
+ conversation_style="pecise",
41
  sec_access_token=None,
42
  client_id=None,
43
  conversation_id=None,
44
  invocation_id=0,
45
  cookies={},
46
  ):
47
+ self.conversation_style = conversation_style
48
  self.sec_access_token = sec_access_token
49
+ self.quotelized_sec_access_token = urllib.parse.quote(self.sec_access_token)
50
  self.client_id = client_id
51
  self.conversation_id = conversation_id
52
  self.invocation_id = invocation_id
53
  self.cookies = cookies
54
  self.ws_url = (
55
+ f"wss://sydney.bing.com/sydney/ChatHub"
56
+ f"?sec_access_token={self.quotelized_sec_access_token}"
57
  )
58
 
59
  async def wss_send(self, message):
 
78
  async def send_chathub_request(self, prompt):
79
  chathub_request_constructor = ChathubRequestConstructor(
80
  prompt=prompt,
81
+ conversation_style=self.conversation_style,
82
  client_id=self.client_id,
83
  conversation_id=self.conversation_id,
84
  invocation_id=self.invocation_id,
 
102
  for line in response_lines:
103
  if not line:
104
  continue
105
+
106
  data = json.loads(line)
107
 
108
  # Stream: Meaningful Messages
109
  if data.get("type") == 1:
110
  message_parser.parse(data)
111
+ # Stream: List of all messages in the whole conversation
112
  elif data.get("type") == 2:
113
  if data.get("item"):
114
  item = data.get("item")
115
  logger.note("\n[Saving chat messages ...]")
 
 
 
116
  # Stream: End of Conversation
117
  elif data.get("type") == 3:
118
  logger.success("[Finished]")
 
120
  await self.wss.close()
121
  await self.aiohttp_session.close()
122
  break
123
+ # Stream: Heartbeat Signal
124
  elif data.get("type") == 6:
125
  continue
126
  # Stream: Not Monitored
127
  else:
 
128
  continue
129
 
130