Antonio Cheong
commited on
Commit
·
af09b23
1
Parent(s):
d2d6b76
Better command line
Browse files- src/BingGPT.py +37 -2
src/BingGPT.py
CHANGED
|
@@ -219,15 +219,50 @@ class Chatbot:
|
|
| 219 |
await self.chat_hub.close()
|
| 220 |
|
| 221 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
async def main():
|
|
|
|
|
|
|
|
|
|
| 223 |
print("Initializing...")
|
| 224 |
bot = Chatbot()
|
| 225 |
await bot.a_start()
|
| 226 |
while True:
|
| 227 |
-
prompt =
|
| 228 |
if prompt == "!exit":
|
| 229 |
break
|
| 230 |
-
print(
|
| 231 |
await bot.a_close()
|
|
|
|
| 232 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
asyncio.run(main())
|
|
|
|
| 219 |
await self.chat_hub.close()
|
| 220 |
|
| 221 |
|
| 222 |
+
def get_input(prompt):
|
| 223 |
+
"""
|
| 224 |
+
Multi-line input function
|
| 225 |
+
"""
|
| 226 |
+
# Display the prompt
|
| 227 |
+
print(prompt, end="")
|
| 228 |
+
|
| 229 |
+
# Initialize an empty list to store the input lines
|
| 230 |
+
lines = []
|
| 231 |
+
|
| 232 |
+
# Read lines of input until the user enters an empty line
|
| 233 |
+
while True:
|
| 234 |
+
line = input()
|
| 235 |
+
if line == "":
|
| 236 |
+
break
|
| 237 |
+
lines.append(line)
|
| 238 |
+
|
| 239 |
+
# Join the lines, separated by newlines, and store the result
|
| 240 |
+
user_input = "\n".join(lines)
|
| 241 |
+
|
| 242 |
+
# Return the input
|
| 243 |
+
return user_input
|
| 244 |
+
|
| 245 |
async def main():
|
| 246 |
+
"""
|
| 247 |
+
Main function
|
| 248 |
+
"""
|
| 249 |
print("Initializing...")
|
| 250 |
bot = Chatbot()
|
| 251 |
await bot.a_start()
|
| 252 |
while True:
|
| 253 |
+
prompt = get_input("\nYou:\n")
|
| 254 |
if prompt == "!exit":
|
| 255 |
break
|
| 256 |
+
print(f'Bot:\n{(await bot.a_ask(prompt=prompt))["item"]["messages"][1]["text"]}\n')
|
| 257 |
await bot.a_close()
|
| 258 |
+
|
| 259 |
if __name__ == "__main__":
|
| 260 |
+
print("""
|
| 261 |
+
BingGPT - A demo of reverse engineering the Bing GPT chatbot
|
| 262 |
+
Repo: github.com/acheong08/BingGPT
|
| 263 |
+
By: Antonio Cheong
|
| 264 |
+
|
| 265 |
+
Type !exit to exit
|
| 266 |
+
Enter twice to send message
|
| 267 |
+
""")
|
| 268 |
asyncio.run(main())
|