Dan
commited on
Refactoring (#80)
Browse files- src/EdgeGPT.py +16 -27
src/EdgeGPT.py
CHANGED
@@ -77,19 +77,17 @@ class ChatHubRequest:
|
|
77 |
self.conversation_signature: str = conversation_signature
|
78 |
self.invocation_id: int = invocation_id
|
79 |
|
80 |
-
def update(
|
81 |
-
self,
|
82 |
-
prompt: str,
|
83 |
-
options: list = [
|
84 |
-
"deepleo",
|
85 |
-
"enable_debug_commands",
|
86 |
-
"disable_emoji_spoken_text",
|
87 |
-
"enablemm",
|
88 |
-
],
|
89 |
-
) -> None:
|
90 |
"""
|
91 |
Updates request object
|
92 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
self.struct = {
|
94 |
"arguments": [
|
95 |
{
|
@@ -132,11 +130,11 @@ class Conversation:
|
|
132 |
if cookies is not None:
|
133 |
cookie_file = cookies
|
134 |
else:
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
cookie_file = json.loads(f)
|
141 |
for cookie in cookie_file:
|
142 |
self.session.cookies.set(cookie["name"], cookie["value"])
|
@@ -183,15 +181,7 @@ class ChatHub:
|
|
183 |
Ask a question to the bot
|
184 |
"""
|
185 |
# Check if websocket is closed
|
186 |
-
if self.wss:
|
187 |
-
if self.wss.closed:
|
188 |
-
self.wss = await websockets.connect(
|
189 |
-
"wss://sydney.bing.com/sydney/ChatHub",
|
190 |
-
extra_headers=HEADERS,
|
191 |
-
max_size=None,
|
192 |
-
)
|
193 |
-
await self.__initial_handshake()
|
194 |
-
else:
|
195 |
self.wss = await websockets.connect(
|
196 |
"wss://sydney.bing.com/sydney/ChatHub",
|
197 |
extra_headers=HEADERS,
|
@@ -225,9 +215,8 @@ class ChatHub:
|
|
225 |
"""
|
226 |
Close the connection
|
227 |
"""
|
228 |
-
if self.wss:
|
229 |
-
|
230 |
-
await self.wss.close()
|
231 |
|
232 |
|
233 |
class Chatbot:
|
|
|
77 |
self.conversation_signature: str = conversation_signature
|
78 |
self.invocation_id: int = invocation_id
|
79 |
|
80 |
+
def update(self, prompt: str, options: list = None) -> None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
"""
|
82 |
Updates request object
|
83 |
"""
|
84 |
+
if options is None:
|
85 |
+
options = [
|
86 |
+
"deepleo",
|
87 |
+
"enable_debug_commands",
|
88 |
+
"disable_emoji_spoken_text",
|
89 |
+
"enablemm",
|
90 |
+
]
|
91 |
self.struct = {
|
92 |
"arguments": [
|
93 |
{
|
|
|
130 |
if cookies is not None:
|
131 |
cookie_file = cookies
|
132 |
else:
|
133 |
+
f = (
|
134 |
+
open(cookiePath, encoding="utf8").read()
|
135 |
+
if cookiePath
|
136 |
+
else open(os.environ.get("COOKIE_FILE"), encoding="utf-8").read()
|
137 |
+
)
|
138 |
cookie_file = json.loads(f)
|
139 |
for cookie in cookie_file:
|
140 |
self.session.cookies.set(cookie["name"], cookie["value"])
|
|
|
181 |
Ask a question to the bot
|
182 |
"""
|
183 |
# Check if websocket is closed
|
184 |
+
if self.wss and self.wss.closed or not self.wss:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
self.wss = await websockets.connect(
|
186 |
"wss://sydney.bing.com/sydney/ChatHub",
|
187 |
extra_headers=HEADERS,
|
|
|
215 |
"""
|
216 |
Close the connection
|
217 |
"""
|
218 |
+
if self.wss and not self.wss.closed:
|
219 |
+
await self.wss.close()
|
|
|
220 |
|
221 |
|
222 |
class Chatbot:
|