Antonio Cheong
commited on
Commit
·
6404fd6
1
Parent(s):
624f0f8
prompt_toolkit
Browse files- .github/workflows/PyPiChecking.yml +1 -1
- requirements.txt +1 -1
- setup.py +8 -1
- src/EdgeGPT.py +29 -35
- src/__init__.py +1 -1
.github/workflows/PyPiChecking.yml
CHANGED
@@ -21,4 +21,4 @@ jobs:
|
|
21 |
python -m pip install --upgrade pip
|
22 |
python -m pip install build
|
23 |
- name: Build package
|
24 |
-
run: python -m build
|
|
|
21 |
python -m pip install --upgrade pip
|
22 |
python -m pip install build
|
23 |
- name: Build package
|
24 |
+
run: python -m build
|
requirements.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
asyncio
|
2 |
requests
|
|
|
3 |
websockets
|
4 |
-
rich
|
|
|
1 |
asyncio
|
2 |
requests
|
3 |
+
rich
|
4 |
websockets
|
|
setup.py
CHANGED
@@ -12,7 +12,14 @@ setup(
|
|
12 |
package_dir={"": "src"},
|
13 |
url="https://github.com/acheong08/EdgeGPT",
|
14 |
project_urls={"Bug Report": "https://github.com/acheong08/EdgeGPT/issues/new"},
|
15 |
-
install_requires=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
long_description=open("README.md", encoding="utf-8").read(),
|
17 |
long_description_content_type="text/markdown",
|
18 |
py_modules=["EdgeGPT"],
|
|
|
12 |
package_dir={"": "src"},
|
13 |
url="https://github.com/acheong08/EdgeGPT",
|
14 |
project_urls={"Bug Report": "https://github.com/acheong08/EdgeGPT/issues/new"},
|
15 |
+
install_requires=[
|
16 |
+
"asyncio",
|
17 |
+
"httpx",
|
18 |
+
"websockets",
|
19 |
+
"rich",
|
20 |
+
"certifi",
|
21 |
+
"prompt_toolkit",
|
22 |
+
],
|
23 |
long_description=open("README.md", encoding="utf-8").read(),
|
24 |
long_description_content_type="text/markdown",
|
25 |
py_modules=["EdgeGPT"],
|
src/EdgeGPT.py
CHANGED
@@ -2,24 +2,29 @@
|
|
2 |
Main.py
|
3 |
"""
|
4 |
from __future__ import annotations
|
|
|
5 |
import argparse
|
6 |
import asyncio
|
7 |
import json
|
8 |
import os
|
9 |
import random
|
|
|
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 |
-
from rich.markdown import Markdown
|
17 |
-
from rich.live import Live
|
18 |
-
import ssl
|
19 |
-
import certifi
|
20 |
|
|
|
21 |
import httpx
|
22 |
import websockets.client as websockets
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
DELIMITER = "\x1e"
|
25 |
|
@@ -125,7 +130,7 @@ class ChatHubRequest:
|
|
125 |
self,
|
126 |
prompt: str,
|
127 |
conversation_style: CONVERSATION_STYLE_TYPE,
|
128 |
-
options:
|
129 |
) -> None:
|
130 |
"""
|
131 |
Updates request object
|
@@ -178,7 +183,7 @@ class Conversation:
|
|
178 |
Conversation API
|
179 |
"""
|
180 |
|
181 |
-
def __init__(self, cookiePath: str = "", cookies:
|
182 |
self.struct: dict = {
|
183 |
"conversationId": None,
|
184 |
"clientId": None,
|
@@ -229,7 +234,7 @@ class ChatHub:
|
|
229 |
"""
|
230 |
|
231 |
def __init__(self, conversation: Conversation) -> None:
|
232 |
-
self.wss:
|
233 |
self.request: ChatHubRequest
|
234 |
self.loop: bool
|
235 |
self.task: asyncio.Task
|
@@ -270,7 +275,7 @@ class ChatHub:
|
|
270 |
continue
|
271 |
response = json.loads(obj)
|
272 |
if response.get("type") == 1 and response["arguments"][0].get(
|
273 |
-
"messages"
|
274 |
):
|
275 |
yield False, response["arguments"][0]["messages"][0][
|
276 |
"adaptiveCards"
|
@@ -296,9 +301,9 @@ class Chatbot:
|
|
296 |
Combines everything to make it seamless
|
297 |
"""
|
298 |
|
299 |
-
def __init__(self, cookiePath: str = "", cookies:
|
300 |
self.cookiePath: str = cookiePath
|
301 |
-
self.cookies:
|
302 |
self.chat_hub: ChatHub = ChatHub(Conversation(self.cookiePath, self.cookies))
|
303 |
|
304 |
async def ask(
|
@@ -345,33 +350,22 @@ class Chatbot:
|
|
345 |
self.chat_hub = ChatHub(Conversation(self.cookiePath, self.cookies))
|
346 |
|
347 |
|
348 |
-
def get_input(
|
|
|
|
|
|
|
349 |
"""
|
350 |
-
|
351 |
"""
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
lines = []
|
362 |
-
|
363 |
-
# Read lines of input until the user enters an empty line
|
364 |
-
while True:
|
365 |
-
line = input()
|
366 |
-
if line == "":
|
367 |
-
break
|
368 |
-
lines.append(line)
|
369 |
-
|
370 |
-
# Join the lines, separated by newlines, and store the result
|
371 |
-
user_input = "\n".join(lines)
|
372 |
-
|
373 |
-
# Return the input
|
374 |
-
return user_input
|
375 |
|
376 |
|
377 |
async def main():
|
|
|
2 |
Main.py
|
3 |
"""
|
4 |
from __future__ import annotations
|
5 |
+
|
6 |
import argparse
|
7 |
import asyncio
|
8 |
import json
|
9 |
import os
|
10 |
import random
|
11 |
+
import ssl
|
12 |
import uuid
|
13 |
from enum import Enum
|
14 |
from typing import Generator
|
15 |
from typing import Literal
|
16 |
from typing import Optional
|
17 |
from typing import Union
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
import certifi
|
20 |
import httpx
|
21 |
import websockets.client as websockets
|
22 |
+
from prompt_toolkit import prompt
|
23 |
+
from prompt_toolkit import PromptSession
|
24 |
+
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
|
25 |
+
from prompt_toolkit.completion import WordCompleter
|
26 |
+
from rich.live import Live
|
27 |
+
from rich.markdown import Markdown
|
28 |
|
29 |
DELIMITER = "\x1e"
|
30 |
|
|
|
130 |
self,
|
131 |
prompt: str,
|
132 |
conversation_style: CONVERSATION_STYLE_TYPE,
|
133 |
+
options: list | None = None,
|
134 |
) -> None:
|
135 |
"""
|
136 |
Updates request object
|
|
|
183 |
Conversation API
|
184 |
"""
|
185 |
|
186 |
+
def __init__(self, cookiePath: str = "", cookies: dict | None = None) -> None:
|
187 |
self.struct: dict = {
|
188 |
"conversationId": None,
|
189 |
"clientId": None,
|
|
|
234 |
"""
|
235 |
|
236 |
def __init__(self, conversation: Conversation) -> None:
|
237 |
+
self.wss: websockets.WebSocketClientProtocol | None = None
|
238 |
self.request: ChatHubRequest
|
239 |
self.loop: bool
|
240 |
self.task: asyncio.Task
|
|
|
275 |
continue
|
276 |
response = json.loads(obj)
|
277 |
if response.get("type") == 1 and response["arguments"][0].get(
|
278 |
+
"messages",
|
279 |
):
|
280 |
yield False, response["arguments"][0]["messages"][0][
|
281 |
"adaptiveCards"
|
|
|
301 |
Combines everything to make it seamless
|
302 |
"""
|
303 |
|
304 |
+
def __init__(self, cookiePath: str = "", cookies: dict | None = None) -> None:
|
305 |
self.cookiePath: str = cookiePath
|
306 |
+
self.cookies: dict | None = cookies
|
307 |
self.chat_hub: ChatHub = ChatHub(Conversation(self.cookiePath, self.cookies))
|
308 |
|
309 |
async def ask(
|
|
|
350 |
self.chat_hub = ChatHub(Conversation(self.cookiePath, self.cookies))
|
351 |
|
352 |
|
353 |
+
async def get_input(
|
354 |
+
session: PromptSession = None,
|
355 |
+
completer: WordCompleter = None,
|
356 |
+
) -> str:
|
357 |
"""
|
358 |
+
Multiline input function.
|
359 |
"""
|
360 |
+
return (
|
361 |
+
await session.prompt_async(
|
362 |
+
completer=completer,
|
363 |
+
multiline=True,
|
364 |
+
auto_suggest=AutoSuggestFromHistory(),
|
365 |
+
)
|
366 |
+
if session
|
367 |
+
else prompt(multiline=True)
|
368 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
369 |
|
370 |
|
371 |
async def main():
|
src/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1 |
-
from . import *
|
|
|
1 |
+
from . import *
|