Hansimov commited on
Commit
a2e9c80
1 Parent(s): c05a7fe

:zap: [Comment] Descriptions for stream and message types

Browse files
Files changed (1) hide show
  1. conversation_connector.py +19 -12
conversation_connector.py CHANGED
@@ -81,14 +81,18 @@ class ConversationConnector:
81
  delta_content_pointer = 0
82
  while not self.wss.closed:
83
  response_lines_str = await self.wss.receive_str()
 
84
  if isinstance(response_lines_str, str):
85
  response_lines = response_lines_str.split("\x1e")
86
  else:
87
  continue
 
88
  for line in response_lines:
89
  if not line:
90
  continue
91
  data = json.loads(line)
 
 
92
  if data.get("type") == 1:
93
  arguments = data["arguments"][0]
94
  if arguments.get("throttling"):
@@ -97,37 +101,37 @@ class ConversationConnector:
97
  if arguments.get("messages"):
98
  for message in arguments.get("messages"):
99
  message_type = message.get("messageType")
 
100
  if message_type is None:
101
- # Displayed message does not contain 'messageType'
102
- message_html = message["adaptiveCards"][0]["body"][0][
103
- "text"
104
- ]
105
- delta_content = message_html[delta_content_pointer:]
106
  logger.mesg(delta_content, end="")
107
- delta_content_pointer = len(message_html)
108
-
109
  if message.get("suggestedResponses"):
110
  logger.note("\n\nSuggested Questions: ")
111
  for suggestion in message.get("suggestedResponses"):
112
  suggestion_text = suggestion.get("text")
113
  logger.file(f"- {suggestion_text}")
114
-
115
  elif message_type in ["InternalSearchQuery"]:
116
  message_hidden_text = message["hiddenText"]
117
  logger.note(f"\n[Searching: [{message_hidden_text}]]")
118
- elif message_type in [
119
- "InternalSearchResult",
120
- ]:
121
  logger.note("[Analyzing search results ...]")
 
122
  elif message_type in ["InternalLoaderMessage"]:
123
  logger.note("[Generating answers ...]\n")
 
124
  elif message_type in ["RenderCardRequest"]:
125
  continue
 
126
  else:
127
  raise NotImplementedError(
128
  f"Not Supported Message Type: {message_type}"
129
  )
130
-
131
  elif data.get("type") == 2:
132
  if data.get("item"):
133
  item = data.get("item")
@@ -135,14 +139,17 @@ class ConversationConnector:
135
  # for message in item.get("messages"):
136
  # author = message["author"]
137
  # message_text = message["text"]
 
138
  elif data.get("type") == 3:
139
  logger.success("[Finished]")
140
  self.invocation_id += 1
141
  await self.wss.close()
142
  await self.aiohttp_session.close()
143
  break
 
144
  elif data.get("type") == 6:
145
  continue
 
146
  else:
147
  # pprint.pprint(data)
148
  continue
 
81
  delta_content_pointer = 0
82
  while not self.wss.closed:
83
  response_lines_str = await self.wss.receive_str()
84
+
85
  if isinstance(response_lines_str, str):
86
  response_lines = response_lines_str.split("\x1e")
87
  else:
88
  continue
89
+
90
  for line in response_lines:
91
  if not line:
92
  continue
93
  data = json.loads(line)
94
+
95
+ # Stream: Meaningful Messages
96
  if data.get("type") == 1:
97
  arguments = data["arguments"][0]
98
  if arguments.get("throttling"):
 
101
  if arguments.get("messages"):
102
  for message in arguments.get("messages"):
103
  message_type = message.get("messageType")
104
+ # Message: Displayed answer
105
  if message_type is None:
106
+ content = message["adaptiveCards"][0]["body"][0]["text"]
107
+ delta_content = content[delta_content_pointer:]
 
 
 
108
  logger.mesg(delta_content, end="")
109
+ delta_content_pointer = len(content)
110
+ # Message: Suggested Questions
111
  if message.get("suggestedResponses"):
112
  logger.note("\n\nSuggested Questions: ")
113
  for suggestion in message.get("suggestedResponses"):
114
  suggestion_text = suggestion.get("text")
115
  logger.file(f"- {suggestion_text}")
116
+ # Message: Search Query
117
  elif message_type in ["InternalSearchQuery"]:
118
  message_hidden_text = message["hiddenText"]
119
  logger.note(f"\n[Searching: [{message_hidden_text}]]")
120
+ # Message: Internal Search Results
121
+ elif message_type in ["InternalSearchResult"]:
 
122
  logger.note("[Analyzing search results ...]")
123
+ # Message: Loader status, such as "Generating Answers"
124
  elif message_type in ["InternalLoaderMessage"]:
125
  logger.note("[Generating answers ...]\n")
126
+ # Message: Render Cards for Webpages
127
  elif message_type in ["RenderCardRequest"]:
128
  continue
129
+ # Message: Not Implemented
130
  else:
131
  raise NotImplementedError(
132
  f"Not Supported Message Type: {message_type}"
133
  )
134
+ # Stream: List of whole conversation messages
135
  elif data.get("type") == 2:
136
  if data.get("item"):
137
  item = data.get("item")
 
139
  # for message in item.get("messages"):
140
  # author = message["author"]
141
  # message_text = message["text"]
142
+ # Stream: End of Conversation
143
  elif data.get("type") == 3:
144
  logger.success("[Finished]")
145
  self.invocation_id += 1
146
  await self.wss.close()
147
  await self.aiohttp_session.close()
148
  break
149
+ # Stream: Signal
150
  elif data.get("type") == 6:
151
  continue
152
+ # Stream: Not Monitored
153
  else:
154
  # pprint.pprint(data)
155
  continue