Skip to content

Commit

Permalink
Merge pull request #56 from Integration-Automation/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
JE-Chen committed Nov 22, 2023
2 parents a66b8f5 + 7bcfb1a commit b2453bb
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 9 deletions.
Empty file added GPT_EXE/browser/__init__.py
Empty file.
30 changes: 30 additions & 0 deletions GPT_EXE/browser/browser_download_window.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from PySide6.QtCore import Qt
from PySide6.QtWebEngineCore import QWebEngineDownloadRequest
from PySide6.QtWidgets import QWidget, QBoxLayout, QPlainTextEdit


class BrowserDownloadWindow(QWidget):

def __init__(self, download_instance: QWebEngineDownloadRequest):
super().__init__()
self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
self.box_layout = QBoxLayout(QBoxLayout.Direction.TopToBottom)
self.show_download_detail_plaintext = QPlainTextEdit()
self.show_download_detail_plaintext.setReadOnly(True)
self.setWindowTitle("Download")
self.download_instance = download_instance
self.download_instance.isFinishedChanged.connect(self.print_finish)
self.download_instance.interruptReasonChanged.connect(self.print_interrupt)
self.download_instance.stateChanged.connect(self.print_state)
self.download_instance.accept()
self.box_layout.addWidget(self.show_download_detail_plaintext)
self.setLayout(self.box_layout)

def print_finish(self):
self.show_download_detail_plaintext.appendPlainText(str(self.download_instance.isFinished()))

def print_interrupt(self):
self.show_download_detail_plaintext.appendPlainText(str(self.download_instance.interruptReason()))

def print_state(self):
self.show_download_detail_plaintext.appendPlainText(str(self.download_instance.state()))
31 changes: 31 additions & 0 deletions GPT_EXE/browser/browser_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from typing import List

from PySide6.QtCore import Qt
from PySide6.QtWebEngineCore import QWebEngineDownloadRequest
from PySide6.QtWebEngineWidgets import QWebEngineView

from .browser_download_window import BrowserDownloadWindow


class BrowserView(QWebEngineView):

def __init__(self, start_url: str = "https://www.google.com/"):
super().__init__()
self.setUrl(start_url)
self.download_list: List[QWebEngineDownloadRequest] = list()
self.download_window_list: List[BrowserDownloadWindow] = list()
self.page().profile().downloadRequested.connect(self.download_file)
self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)

def download_file(self, download_instance: QWebEngineDownloadRequest):
self.download_list.append(download_instance)
download_detail_window = BrowserDownloadWindow(download_instance)
self.download_window_list.append(download_detail_window)
download_detail_window.show()

def closeEvent(self, event) -> None:
for download_instance in self.download_list:
download_instance.cancel()
for download_window in self.download_window_list:
download_window.close()
super().closeEvent(event)
30 changes: 30 additions & 0 deletions GPT_EXE/browser/browser_widget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from PySide6.QtGui import QAction, Qt
from PySide6.QtWidgets import QWidget, QGridLayout, QPushButton, QInputDialog

from .browser_view import BrowserView


class JEBrowser(QWidget):

def __init__(self, start_url: str = "https://www.bing.com/chat"):
super().__init__()
# Browser setting
self.browser = BrowserView(start_url)
self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
# Action
self.find_action = QAction()
self.find_action.setShortcut("Ctrl+f")
self.find_action.triggered.connect(self.find_text)
self.addAction(self.find_action)
# Layout
self.grid_layout = QGridLayout()
self.grid_layout.addWidget(self.browser, 0, 0, -1, -1)
self.setLayout(self.grid_layout)

def find_text(self):
search_box = QInputDialog(self)
search_text, press_ok = search_box.getText(self, "Find text", "Find text")
if press_ok:
self.browser.findText(search_text)
else:
self.browser.findText("")
25 changes: 25 additions & 0 deletions GPT_EXE/browser_that_open_bing_chat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import sys

from PySide6.QtCore import QCoreApplication
from PySide6.QtWidgets import QMainWindow, QApplication
from qt_material import apply_stylesheet

from GPT_EXE.browser.browser_widget import JEBrowser


class JustOpenGPTBrowser(QMainWindow):

def __init__(self):
super().__init__()
self.browser_widget = JEBrowser()
self.setCentralWidget(self.browser_widget)


if __name__ == "__main__":
new_editor = QCoreApplication.instance()
if new_editor is None:
new_editor = QApplication(sys.argv)
window = JustOpenGPTBrowser()
apply_stylesheet(new_editor, theme='dark_amber.xml')
window.showMaximized()
sys.exit(new_editor.exec())
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ if __name__ == "__main__":

<details open>

> * Q: Exception: Throttled: Request is throttled.
> * A: Bing's chat rate limit.
> * ![rate_limit.png](images/rate_limit.png)
> * Q: RuntimeError: This event loop is already running
> * A: If you are using Jupyter, pls use nest_asyncio.apply()
> * Like: https://github.com/Integration-Automation/ReEdgeGPT/issues/30
Expand All @@ -257,9 +260,3 @@ if __name__ == "__main__":
> * See https://github.com/Integration-Automation/ReEdgeGPT/issues/22
> * Q: UnauthorizedRequest: Token issued by https://sydney.bing.com/sydney is invalid
> * A: Bing block your connect, Try to use proxy or clear cookie.
</details>

---
> Origin repo (archived): https://github.com/acheong08/EdgeGPT
---
Binary file added images/rate_limit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ prompt_toolkit
requests
rich
re_edge_gpt
regex
regex
PySide6
qt-material
4 changes: 2 additions & 2 deletions test/unit_test/manual_test/test_bot_manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
async def test_ask() -> None:
bot = None
try:
cookies = json.loads(open(
cookies: list[dict] = json.loads(open(
str(Path(str(Path.cwd()) + "/bing_cookies.json")), encoding="utf-8").read())
bot = await Chatbot.create(cookies=cookies)
response = await bot.ask(
prompt="Deer soup",
prompt="How to get extract iron on mine",
conversation_style=ConversationStyle.balanced,
simplify_response=True
)
Expand Down

0 comments on commit b2453bb

Please sign in to comment.