Spaces:
Paused
Paused
:zap: [Enhance] Print response content in stream with pointer
Browse files- conversation_creater.py +14 -10
conversation_creater.py
CHANGED
@@ -62,9 +62,8 @@ class ConversationChatter:
|
|
62 |
"wss://sydney.bing.com/sydney/ChatHub"
|
63 |
+ f"?sec_access_token={urllib.parse.quote(self.sec_access_token)}"
|
64 |
)
|
65 |
-
# print(f"sec_access_token: {self.sec_access_token}")
|
66 |
|
67 |
-
async def
|
68 |
await wss.send_str(
|
69 |
serialize_websockets_message({"protocol": "json", "version": 1})
|
70 |
)
|
@@ -94,8 +93,9 @@ class ConversationChatter:
|
|
94 |
proxy=http_proxy,
|
95 |
)
|
96 |
|
97 |
-
await self.
|
98 |
chathub_request_construtor = ChathubRequestConstructor(
|
|
|
99 |
conversation_style="precise",
|
100 |
client_id=self.client_id,
|
101 |
conversation_id=self.conversation_id,
|
@@ -106,6 +106,8 @@ class ConversationChatter:
|
|
106 |
await wss.send_str(
|
107 |
serialize_websockets_message(chathub_request_construtor.request_message)
|
108 |
)
|
|
|
|
|
109 |
while not wss.closed:
|
110 |
response_lines_str = await wss.receive_str()
|
111 |
if isinstance(response_lines_str, str):
|
@@ -122,16 +124,21 @@ class ConversationChatter:
|
|
122 |
throttling = arguments.get("throttling")
|
123 |
pprint.pprint(throttling)
|
124 |
if arguments.get("messages"):
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
128 |
elif data.get("type") == 2:
|
129 |
if data.get("item"):
|
130 |
item = data.get("item")
|
131 |
for message in item.get("messages"):
|
132 |
author = message["author"]
|
133 |
message_text = message["text"]
|
134 |
-
print(f"[{author}]: {message_text}")
|
135 |
elif data.get("type") == 3:
|
136 |
print("[Finished]")
|
137 |
await wss.close()
|
@@ -142,9 +149,6 @@ class ConversationChatter:
|
|
142 |
|
143 |
|
144 |
if __name__ == "__main__":
|
145 |
-
# cookies_constructor = CookiesConstructor()
|
146 |
-
# cookies_constructor.construct()
|
147 |
-
|
148 |
creator = ConversationCreator()
|
149 |
creator.create()
|
150 |
|
|
|
62 |
"wss://sydney.bing.com/sydney/ChatHub"
|
63 |
+ f"?sec_access_token={urllib.parse.quote(self.sec_access_token)}"
|
64 |
)
|
|
|
65 |
|
66 |
+
async def _init_handshake(self, wss):
|
67 |
await wss.send_str(
|
68 |
serialize_websockets_message({"protocol": "json", "version": 1})
|
69 |
)
|
|
|
93 |
proxy=http_proxy,
|
94 |
)
|
95 |
|
96 |
+
await self._init_handshake(wss)
|
97 |
chathub_request_construtor = ChathubRequestConstructor(
|
98 |
+
prompt="Hello, tell me your name. No more than 3 words.",
|
99 |
conversation_style="precise",
|
100 |
client_id=self.client_id,
|
101 |
conversation_id=self.conversation_id,
|
|
|
106 |
await wss.send_str(
|
107 |
serialize_websockets_message(chathub_request_construtor.request_message)
|
108 |
)
|
109 |
+
|
110 |
+
delta_content_pointer = 0
|
111 |
while not wss.closed:
|
112 |
response_lines_str = await wss.receive_str()
|
113 |
if isinstance(response_lines_str, str):
|
|
|
124 |
throttling = arguments.get("throttling")
|
125 |
pprint.pprint(throttling)
|
126 |
if arguments.get("messages"):
|
127 |
+
for message in arguments.get("messages"):
|
128 |
+
# html_str = messages["adaptiveCards"][0]["body"][0]["text"]
|
129 |
+
message_text = message["text"]
|
130 |
+
print(
|
131 |
+
message_text[delta_content_pointer:], end="", flush=True
|
132 |
+
)
|
133 |
+
delta_content_pointer = len(message_text)
|
134 |
+
|
135 |
elif data.get("type") == 2:
|
136 |
if data.get("item"):
|
137 |
item = data.get("item")
|
138 |
for message in item.get("messages"):
|
139 |
author = message["author"]
|
140 |
message_text = message["text"]
|
141 |
+
# print(f"[{author}]: {message_text}")
|
142 |
elif data.get("type") == 3:
|
143 |
print("[Finished]")
|
144 |
await wss.close()
|
|
|
149 |
|
150 |
|
151 |
if __name__ == "__main__":
|
|
|
|
|
|
|
152 |
creator = ConversationCreator()
|
153 |
creator.create()
|
154 |
|