Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Updated to latest EdgeGPT version and BingImageCreator. Bot can be ru…
Browse files Browse the repository at this point in the history
…n without cookies except if image creation needed
  • Loading branch information
scmanjarrez committed May 28, 2023
1 parent 0f1d5a6 commit f5bcaa3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
37 changes: 19 additions & 18 deletions src/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import asyncio
import html
import io
import json
import logging
import re
import subprocess
Expand Down Expand Up @@ -252,25 +251,27 @@ def __exit__(self):

def run(self):
sys.stdout = open("/dev/null", "w")
with open(ut.path("cookies")) as f:
data = json.load(f)
auth = None
for ck in data:
if ck["name"] == "_U":
auth = ck["value"]
break
msg = "Invalid cookies"
if auth is not None:
image_gen = ImageGen(auth)
images = None
try:
images = image_gen.get_images(self.prompt)
except Exception as e: # noqa
logging.getLogger("BingImageCreator").error(msg)
msg = e.args[0]
self.queue.put((images, msg))
if ut.DATA["cookies"] is not None:
for ck in ut.DATA["cookies"]:
if ck["name"] == "_U":
auth = ck["value"]
break
msg = "Invalid cookies"
if auth is not None:
image_gen = ImageGen(auth)
images = None
try:
images = image_gen.get_images(self.prompt)
except Exception as e: # noqa
logging.getLogger("BingImageCreator").error(msg)
msg = e.args[0]
self.queue.put((images, msg))
else:
self.queue.put((None, msg))
else:
self.queue.put((None, msg))
self.queue.put((None,
"Cookies required to use this functionality."))


async def automatic_speech_recognition(
Expand Down
2 changes: 1 addition & 1 deletion src/edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def setup_parser() -> None:

setup_parser()

if ut.exists("config") and ut.exists("cookies"):
if ut.exists("config"):
ut.set_up()
application = (
ApplicationBuilder()
Expand Down
10 changes: 8 additions & 2 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@


PATH = {}
DATA = {"config": None, "tts": None, "msg": {}}
DATA = {"config": None, "cookies": None, "tts": None, "msg": {}}
CONV = {"all": {}, "current": {}}
LOG_FILT = ["Removed job", "Added job", "Job", "Running job", "message="]
DEBUG = False
Expand Down Expand Up @@ -78,6 +78,9 @@ def set_up() -> None:
rename_files()
with open(path("config")) as f:
DATA["config"] = json.load(f)
if exists("cookies"):
with open(path("cookies")) as f:
DATA["cookies"] = json.load(f)
try:
logging.getLogger().setLevel(settings("log_level").upper())
except KeyError:
Expand Down Expand Up @@ -297,7 +300,10 @@ async def create_conversation(
if chat_id is None:
chat_id = cid(update)
try:
tmp = Chatbot(cookie_path=str(path("cookies")))
if DATA["cookies"] is not None:
tmp = Chatbot(cookies=DATA["cookies"])
else:
tmp = Chatbot()
except Exception as e:
logging.getLogger("EdgeGPT").error(e)
await send(update, f"EdgeGPT error: {e.args[0]}")
Expand Down

0 comments on commit f5bcaa3

Please sign in to comment.