Antonio Cheong commited on
Commit
345c2c6
·
1 Parent(s): da7eaeb
Files changed (2) hide show
  1. README.md +1 -1
  2. src/EdgeGPT.py +28 -14
README.md CHANGED
@@ -89,7 +89,7 @@ python3 -m pip install EdgeGPT --upgrade
89
 
90
  Type !exit to exit
91
  Enter twice to send message or set --enter-once to send one line message
92
-
93
  usage: EdgeGPT.py [-h] [--enter-once] [--no-stream] [--style {creative,balanced,precise}] --cookie-file COOKIE_FILE
94
 
95
  options:
 
89
 
90
  Type !exit to exit
91
  Enter twice to send message or set --enter-once to send one line message
92
+
93
  usage: EdgeGPT.py [-h] [--enter-once] [--no-stream] [--style {creative,balanced,precise}] --cookie-file COOKIE_FILE
94
 
95
  options:
src/EdgeGPT.py CHANGED
@@ -1,15 +1,18 @@
1
  """
2
  Main.py
3
  """
 
 
 
4
  import os
 
5
  import sys
6
- import json
7
  import uuid
8
- import random
9
- import asyncio
10
- import argparse
11
  from enum import Enum
12
- from typing import Generator, Optional, Union, Literal
 
 
 
13
 
14
  import requests
15
  import websockets.client as websockets
@@ -155,8 +158,8 @@ class Conversation:
155
  self.session = requests.Session()
156
  self.session.headers.update(
157
  {
158
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
159
- }
160
  )
161
  if cookies is not None:
162
  cookie_file = cookies
@@ -208,7 +211,9 @@ class ChatHub:
208
  )
209
 
210
  async def ask_stream(
211
- self, prompt: str, conversation_style: CONVERSATION_STYLE_TYPE = None
 
 
212
  ) -> Generator[str, None, None]:
213
  """
214
  Ask a question to the bot
@@ -263,26 +268,32 @@ class Chatbot:
263
  self.chat_hub: ChatHub = ChatHub(Conversation(self.cookiePath, self.cookies))
264
 
265
  async def ask(
266
- self, prompt: str, conversation_style: CONVERSATION_STYLE_TYPE = None
 
 
267
  ) -> dict:
268
  """
269
  Ask a question to the bot
270
  """
271
  async for final, response in self.chat_hub.ask_stream(
272
- prompt=prompt, conversation_style=conversation_style
 
273
  ):
274
  if final:
275
  return response
276
  self.chat_hub.wss.close()
277
 
278
  async def ask_stream(
279
- self, prompt: str, conversation_style: CONVERSATION_STYLE_TYPE = None
 
 
280
  ) -> Generator[str, None, None]:
281
  """
282
  Ask a question to the bot
283
  """
284
  async for response in self.chat_hub.ask_stream(
285
- prompt=prompt, conversation_style=conversation_style
 
286
  ):
287
  yield response
288
 
@@ -361,7 +372,8 @@ async def main():
361
  else:
362
  wrote = 0
363
  async for final, response in bot.ask_stream(
364
- prompt=prompt, conversation_style=args.style
 
365
  ):
366
  if not final:
367
  print(response[wrote:], end="")
@@ -389,7 +401,9 @@ if __name__ == "__main__":
389
  parser.add_argument("--enter-once", action="store_true")
390
  parser.add_argument("--no-stream", action="store_true")
391
  parser.add_argument(
392
- "--style", choices=["creative", "balanced", "precise"], default="balanced"
 
 
393
  )
394
  parser.add_argument(
395
  "--cookie-file",
 
1
  """
2
  Main.py
3
  """
4
+ import argparse
5
+ import asyncio
6
+ import json
7
  import os
8
+ import random
9
  import sys
 
10
  import uuid
 
 
 
11
  from enum import Enum
12
+ from typing import Generator
13
+ from typing import Literal
14
+ from typing import Optional
15
+ from typing import Union
16
 
17
  import requests
18
  import websockets.client as websockets
 
158
  self.session = requests.Session()
159
  self.session.headers.update(
160
  {
161
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
162
+ },
163
  )
164
  if cookies is not None:
165
  cookie_file = cookies
 
211
  )
212
 
213
  async def ask_stream(
214
+ self,
215
+ prompt: str,
216
+ conversation_style: CONVERSATION_STYLE_TYPE = None,
217
  ) -> Generator[str, None, None]:
218
  """
219
  Ask a question to the bot
 
268
  self.chat_hub: ChatHub = ChatHub(Conversation(self.cookiePath, self.cookies))
269
 
270
  async def ask(
271
+ self,
272
+ prompt: str,
273
+ conversation_style: CONVERSATION_STYLE_TYPE = None,
274
  ) -> dict:
275
  """
276
  Ask a question to the bot
277
  """
278
  async for final, response in self.chat_hub.ask_stream(
279
+ prompt=prompt,
280
+ conversation_style=conversation_style,
281
  ):
282
  if final:
283
  return response
284
  self.chat_hub.wss.close()
285
 
286
  async def ask_stream(
287
+ self,
288
+ prompt: str,
289
+ conversation_style: CONVERSATION_STYLE_TYPE = None,
290
  ) -> Generator[str, None, None]:
291
  """
292
  Ask a question to the bot
293
  """
294
  async for response in self.chat_hub.ask_stream(
295
+ prompt=prompt,
296
+ conversation_style=conversation_style,
297
  ):
298
  yield response
299
 
 
372
  else:
373
  wrote = 0
374
  async for final, response in bot.ask_stream(
375
+ prompt=prompt,
376
+ conversation_style=args.style,
377
  ):
378
  if not final:
379
  print(response[wrote:], end="")
 
401
  parser.add_argument("--enter-once", action="store_true")
402
  parser.add_argument("--no-stream", action="store_true")
403
  parser.add_argument(
404
+ "--style",
405
+ choices=["creative", "balanced", "precise"],
406
+ default="balanced",
407
  )
408
  parser.add_argument(
409
  "--cookie-file",