Spaces:
Paused
Paused
:gem: [Feature] ConversationSession: Encapsulate creator, connector and chatter
Browse files- conversation_connector.py +0 -25
- conversation_session.py +51 -0
conversation_connector.py
CHANGED
|
@@ -125,28 +125,3 @@ class ConversationConnector:
|
|
| 125 |
# Stream: Not Monitored
|
| 126 |
else:
|
| 127 |
continue
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
if __name__ == "__main__":
|
| 131 |
-
creator = ConversationCreator()
|
| 132 |
-
creator.create()
|
| 133 |
-
|
| 134 |
-
connector = ConversationConnector(
|
| 135 |
-
sec_access_token=creator.response_headers[
|
| 136 |
-
"x-sydney-encryptedconversationsignature"
|
| 137 |
-
],
|
| 138 |
-
client_id=creator.response_content["clientId"],
|
| 139 |
-
conversation_id=creator.response_content["conversationId"],
|
| 140 |
-
)
|
| 141 |
-
|
| 142 |
-
prompts = [
|
| 143 |
-
"Today's weather of California",
|
| 144 |
-
"Please summarize your previous answer in table format",
|
| 145 |
-
]
|
| 146 |
-
loop = asyncio.get_event_loop()
|
| 147 |
-
for prompt in prompts:
|
| 148 |
-
logger.success(f"\n[User]: ", end="")
|
| 149 |
-
logger.mesg(f"{prompt}")
|
| 150 |
-
logger.success(f"[Bing]:")
|
| 151 |
-
loop.run_until_complete(connector.stream_chat(prompt=prompt))
|
| 152 |
-
loop.close()
|
|
|
|
| 125 |
# Stream: Not Monitored
|
| 126 |
else:
|
| 127 |
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
conversation_session.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
from conversation_creator import ConversationCreator
|
| 3 |
+
from conversation_connector import ConversationConnector
|
| 4 |
+
from logger.logger import logger
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class ConversationSession:
|
| 8 |
+
def __init__(self) -> None:
|
| 9 |
+
pass
|
| 10 |
+
|
| 11 |
+
def run(self):
|
| 12 |
+
self.create()
|
| 13 |
+
self.connect()
|
| 14 |
+
|
| 15 |
+
def create(self):
|
| 16 |
+
self.creator = ConversationCreator()
|
| 17 |
+
self.creator.create()
|
| 18 |
+
|
| 19 |
+
def connect(self):
|
| 20 |
+
self.connector = ConversationConnector(
|
| 21 |
+
sec_access_token=self.creator.response_headers[
|
| 22 |
+
"x-sydney-encryptedconversationsignature"
|
| 23 |
+
],
|
| 24 |
+
client_id=self.creator.response_content["clientId"],
|
| 25 |
+
conversation_id=self.creator.response_content["conversationId"],
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
def open(self):
|
| 29 |
+
self.event_loop = asyncio.get_event_loop()
|
| 30 |
+
|
| 31 |
+
def close(self):
|
| 32 |
+
self.event_loop.close()
|
| 33 |
+
|
| 34 |
+
def chat(self, prompt):
|
| 35 |
+
logger.success(f"\n[User]: ", end="")
|
| 36 |
+
logger.mesg(f"{prompt}")
|
| 37 |
+
logger.success(f"[Bing]:")
|
| 38 |
+
self.event_loop.run_until_complete(self.connector.stream_chat(prompt=prompt))
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
if __name__ == "__main__":
|
| 42 |
+
session = ConversationSession()
|
| 43 |
+
session.run()
|
| 44 |
+
session.open()
|
| 45 |
+
prompts = [
|
| 46 |
+
"Today's weather of California",
|
| 47 |
+
"Please summarize your previous answer in table format",
|
| 48 |
+
]
|
| 49 |
+
for prompt in prompts:
|
| 50 |
+
session.chat(prompt)
|
| 51 |
+
session.close()
|