Spaces:
Paused
Paused
:gem: [Feature] Support parse more message types, and format output
Browse files- conversation_creater.py +46 -13
conversation_creater.py
CHANGED
|
@@ -95,7 +95,7 @@ class ConversationChatter:
|
|
| 95 |
|
| 96 |
await self._init_handshake(wss)
|
| 97 |
chathub_request_construtor = ChathubRequestConstructor(
|
| 98 |
-
prompt=
|
| 99 |
conversation_style="precise",
|
| 100 |
client_id=self.client_id,
|
| 101 |
conversation_id=self.conversation_id,
|
|
@@ -122,27 +122,57 @@ class ConversationChatter:
|
|
| 122 |
arguments = data["arguments"][0]
|
| 123 |
if arguments.get("throttling"):
|
| 124 |
throttling = arguments.get("throttling")
|
| 125 |
-
pprint.pprint(throttling)
|
| 126 |
if arguments.get("messages"):
|
| 127 |
for message in arguments.get("messages"):
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
elif data.get("type") == 2:
|
| 136 |
if data.get("item"):
|
| 137 |
item = data.get("item")
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
elif data.get("type") == 3:
|
| 143 |
print("[Finished]")
|
| 144 |
await wss.close()
|
| 145 |
break
|
|
|
|
|
|
|
| 146 |
else:
|
| 147 |
# pprint.pprint(data)
|
| 148 |
continue
|
|
@@ -159,6 +189,9 @@ if __name__ == "__main__":
|
|
| 159 |
client_id=creator.response_content["clientId"],
|
| 160 |
conversation_id=creator.response_content["conversationId"],
|
| 161 |
)
|
|
|
|
|
|
|
|
|
|
| 162 |
loop = asyncio.get_event_loop()
|
| 163 |
-
loop.run_until_complete(chatter.stream_chat())
|
| 164 |
loop.close()
|
|
|
|
| 95 |
|
| 96 |
await self._init_handshake(wss)
|
| 97 |
chathub_request_construtor = ChathubRequestConstructor(
|
| 98 |
+
prompt=prompt,
|
| 99 |
conversation_style="precise",
|
| 100 |
client_id=self.client_id,
|
| 101 |
conversation_id=self.conversation_id,
|
|
|
|
| 122 |
arguments = data["arguments"][0]
|
| 123 |
if arguments.get("throttling"):
|
| 124 |
throttling = arguments.get("throttling")
|
| 125 |
+
# pprint.pprint(throttling)
|
| 126 |
if arguments.get("messages"):
|
| 127 |
for message in arguments.get("messages"):
|
| 128 |
+
message_type = message.get("messageType")
|
| 129 |
+
if message_type is None:
|
| 130 |
+
# Displayed message does not contain 'messageType'
|
| 131 |
+
message_html = message["adaptiveCards"][0]["body"][0][
|
| 132 |
+
"text"
|
| 133 |
+
]
|
| 134 |
+
delta_content = message_html[delta_content_pointer:]
|
| 135 |
+
print(delta_content, end="", flush=True)
|
| 136 |
+
delta_content_pointer = len(message_html)
|
| 137 |
+
|
| 138 |
+
if message.get("suggestedResponses"):
|
| 139 |
+
print("\nSuggested Questions: ", flush=True)
|
| 140 |
+
for suggestion in message.get("suggestedResponses"):
|
| 141 |
+
suggestion_text = suggestion.get("text")
|
| 142 |
+
print(f"- {suggestion_text}", flush=True)
|
| 143 |
+
|
| 144 |
+
elif message_type in ["InternalSearchQuery"]:
|
| 145 |
+
message_hidden_text = message["hiddenText"]
|
| 146 |
+
print(
|
| 147 |
+
f"\n[Searching: [{message_hidden_text}]]",
|
| 148 |
+
flush=True,
|
| 149 |
+
)
|
| 150 |
+
elif message_type in [
|
| 151 |
+
"InternalSearchResult",
|
| 152 |
+
]:
|
| 153 |
+
print("[Analyzing search results ...]", flush=True)
|
| 154 |
+
elif message_type in ["InternalLoaderMessage"]:
|
| 155 |
+
print("[Generating answers ...]\n", flush=True)
|
| 156 |
+
elif message_type in ["RenderCardRequest"]:
|
| 157 |
+
continue
|
| 158 |
+
else:
|
| 159 |
+
raise NotImplementedError(
|
| 160 |
+
f"Not Supported Message Type: {message_type}"
|
| 161 |
+
)
|
| 162 |
|
| 163 |
elif data.get("type") == 2:
|
| 164 |
if data.get("item"):
|
| 165 |
item = data.get("item")
|
| 166 |
+
print("\n[Saving chat messages ...]")
|
| 167 |
+
# for message in item.get("messages"):
|
| 168 |
+
# author = message["author"]
|
| 169 |
+
# message_text = message["text"]
|
| 170 |
elif data.get("type") == 3:
|
| 171 |
print("[Finished]")
|
| 172 |
await wss.close()
|
| 173 |
break
|
| 174 |
+
elif data.get("type") == 6:
|
| 175 |
+
continue
|
| 176 |
else:
|
| 177 |
# pprint.pprint(data)
|
| 178 |
continue
|
|
|
|
| 189 |
client_id=creator.response_content["clientId"],
|
| 190 |
conversation_id=creator.response_content["conversationId"],
|
| 191 |
)
|
| 192 |
+
prompt = "Today's weather of California"
|
| 193 |
+
print(f"\n[User]: {prompt}\n")
|
| 194 |
+
print(f"[Bing]:")
|
| 195 |
loop = asyncio.get_event_loop()
|
| 196 |
+
loop.run_until_complete(chatter.stream_chat(prompt=prompt))
|
| 197 |
loop.close()
|