Antonio Cheong
commited on
Commit
·
f71f123
1
Parent(s):
4332868
Formatting
Browse files- README.md +1 -1
- src/EdgeGPT.py +12 -6
README.md
CHANGED
@@ -40,7 +40,7 @@ Completely optional, but recommended if you have beta access to Bing Chat
|
|
40 |
|
41 |
Type !exit to exit
|
42 |
Enter twice to send message
|
43 |
-
|
44 |
usage: EdgeGPT.py [-h] [--stream] [--bing-cookie BING_COOKIE]
|
45 |
|
46 |
options:
|
|
|
40 |
|
41 |
Type !exit to exit
|
42 |
Enter twice to send message
|
43 |
+
|
44 |
usage: EdgeGPT.py [-h] [--stream] [--bing-cookie BING_COOKIE]
|
45 |
|
46 |
options:
|
src/EdgeGPT.py
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
"""
|
2 |
Main.py
|
3 |
"""
|
|
|
4 |
import asyncio
|
5 |
import json
|
6 |
import os
|
7 |
import sys
|
8 |
import uuid
|
9 |
-
import argparse
|
10 |
|
11 |
import requests
|
12 |
import websockets.client as websockets
|
@@ -138,7 +138,7 @@ class Conversation:
|
|
138 |
self.struct = response.json()
|
139 |
except json.decoder.JSONDecodeError as exc:
|
140 |
raise Exception(
|
141 |
-
"Authentication failed. You have not been accepted into the beta."
|
142 |
) from exc
|
143 |
|
144 |
|
@@ -166,7 +166,7 @@ class ChatHub:
|
|
166 |
if self.wss:
|
167 |
if self.wss.closed:
|
168 |
self.wss = await websockets.connect(
|
169 |
-
"wss://sydney.bing.com/sydney/ChatHub"
|
170 |
)
|
171 |
await self.__initial_handshake()
|
172 |
else:
|
@@ -184,7 +184,9 @@ class ChatHub:
|
|
184 |
continue
|
185 |
response = json.loads(obj)
|
186 |
if response.get("type") == 1:
|
187 |
-
yield False, response["arguments"][0]["messages"][0][
|
|
|
|
|
188 |
elif response.get("type") == 2:
|
189 |
final = True
|
190 |
yield True, response
|
@@ -217,7 +219,7 @@ class Chatbot:
|
|
217 |
async for final, response in self.chat_hub.ask_stream(prompt=prompt):
|
218 |
if final:
|
219 |
return response
|
220 |
-
|
221 |
async def ask_stream(self, prompt: str) -> str:
|
222 |
"""
|
223 |
Ask a question to the bot
|
@@ -287,7 +289,11 @@ async def main():
|
|
287 |
continue
|
288 |
print("Bot:")
|
289 |
if not args.stream:
|
290 |
-
print(
|
|
|
|
|
|
|
|
|
291 |
else:
|
292 |
wrote = 0
|
293 |
async for final, response in bot.ask_stream(prompt=prompt):
|
|
|
1 |
"""
|
2 |
Main.py
|
3 |
"""
|
4 |
+
import argparse
|
5 |
import asyncio
|
6 |
import json
|
7 |
import os
|
8 |
import sys
|
9 |
import uuid
|
|
|
10 |
|
11 |
import requests
|
12 |
import websockets.client as websockets
|
|
|
138 |
self.struct = response.json()
|
139 |
except json.decoder.JSONDecodeError as exc:
|
140 |
raise Exception(
|
141 |
+
"Authentication failed. You have not been accepted into the beta.",
|
142 |
) from exc
|
143 |
|
144 |
|
|
|
166 |
if self.wss:
|
167 |
if self.wss.closed:
|
168 |
self.wss = await websockets.connect(
|
169 |
+
"wss://sydney.bing.com/sydney/ChatHub",
|
170 |
)
|
171 |
await self.__initial_handshake()
|
172 |
else:
|
|
|
184 |
continue
|
185 |
response = json.loads(obj)
|
186 |
if response.get("type") == 1:
|
187 |
+
yield False, response["arguments"][0]["messages"][0][
|
188 |
+
"adaptiveCards"
|
189 |
+
][0]["body"][0]["text"]
|
190 |
elif response.get("type") == 2:
|
191 |
final = True
|
192 |
yield True, response
|
|
|
219 |
async for final, response in self.chat_hub.ask_stream(prompt=prompt):
|
220 |
if final:
|
221 |
return response
|
222 |
+
|
223 |
async def ask_stream(self, prompt: str) -> str:
|
224 |
"""
|
225 |
Ask a question to the bot
|
|
|
289 |
continue
|
290 |
print("Bot:")
|
291 |
if not args.stream:
|
292 |
+
print(
|
293 |
+
(await bot.ask(prompt=prompt))["item"]["messages"][1]["adaptiveCards"][
|
294 |
+
0
|
295 |
+
]["body"][0]["text"]
|
296 |
+
)
|
297 |
else:
|
298 |
wrote = 0
|
299 |
async for final, response in bot.ask_stream(prompt=prompt):
|