Spaces:
Paused
Paused
:gem: [Feature] ConversationSession: Support syntax
Browse files- conversation_session.py +14 -11
conversation_session.py
CHANGED
@@ -5,12 +5,15 @@ from logger.logger import logger
|
|
5 |
|
6 |
|
7 |
class ConversationSession:
|
8 |
-
def __init__(self)
|
9 |
-
|
10 |
|
11 |
-
def
|
12 |
-
self.
|
13 |
-
self
|
|
|
|
|
|
|
14 |
|
15 |
def create(self):
|
16 |
self.creator = ConversationCreator()
|
@@ -18,6 +21,7 @@ class ConversationSession:
|
|
18 |
|
19 |
def connect(self):
|
20 |
self.connector = ConversationConnector(
|
|
|
21 |
sec_access_token=self.creator.response_headers[
|
22 |
"x-sydney-encryptedconversationsignature"
|
23 |
],
|
@@ -26,6 +30,8 @@ class ConversationSession:
|
|
26 |
)
|
27 |
|
28 |
def open(self):
|
|
|
|
|
29 |
self.event_loop = asyncio.get_event_loop()
|
30 |
|
31 |
def close(self):
|
@@ -39,13 +45,10 @@ class ConversationSession:
|
|
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 |
-
|
50 |
-
|
51 |
-
|
|
|
5 |
|
6 |
|
7 |
class ConversationSession:
|
8 |
+
def __init__(self, conversation_style="precise"):
|
9 |
+
self.conversation_style = conversation_style
|
10 |
|
11 |
+
def __enter__(self):
|
12 |
+
self.open()
|
13 |
+
return self
|
14 |
+
|
15 |
+
def __exit__(self, exc_type, exc_value, exc_traceback):
|
16 |
+
self.close()
|
17 |
|
18 |
def create(self):
|
19 |
self.creator = ConversationCreator()
|
|
|
21 |
|
22 |
def connect(self):
|
23 |
self.connector = ConversationConnector(
|
24 |
+
conversation_style=self.conversation_style,
|
25 |
sec_access_token=self.creator.response_headers[
|
26 |
"x-sydney-encryptedconversationsignature"
|
27 |
],
|
|
|
30 |
)
|
31 |
|
32 |
def open(self):
|
33 |
+
self.create()
|
34 |
+
self.connect()
|
35 |
self.event_loop = asyncio.get_event_loop()
|
36 |
|
37 |
def close(self):
|
|
|
45 |
|
46 |
|
47 |
if __name__ == "__main__":
|
|
|
|
|
|
|
48 |
prompts = [
|
49 |
"Today's weather of California",
|
50 |
"Please summarize your previous answer in table format",
|
51 |
]
|
52 |
+
with ConversationSession("precise") as session:
|
53 |
+
for prompt in prompts:
|
54 |
+
session.chat(prompt)
|