diff --git a/README.md b/README.md index ffdb6f0331..da9c312f06 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,11 @@ options: ----- ### Developer demo -Remember to set cookie file path: `export COOKIE_FILE=/path/to/cookies.json` +Remember to set cookie file path: `export COOKIE_FILE=/path/to/cookies.json`. You can also specify the path to `cookies.json` in the argument `cookiePath` like this: + +```python +bot = Chatbot(cookiePath='./cookie.json') +``` Use Async for the best experience diff --git a/src/EdgeGPT.py b/src/EdgeGPT.py index f8a4edf9c6..d2c1054138 100644 --- a/src/EdgeGPT.py +++ b/src/EdgeGPT.py @@ -103,7 +103,7 @@ class Conversation: Conversation API """ - def __init__(self) -> None: + def __init__(self, cookiePath: str = '') -> None: self.struct: dict = { "conversationId": None, "clientId": None, @@ -111,9 +111,11 @@ def __init__(self) -> None: "result": {"value": "Success", "message": None}, } self.session = tls_client.Session(client_identifier="chrome_108") - cookie_file = json.loads( - open(os.environ.get("COOKIE_FILE"), encoding="utf-8").read(), - ) + if cookiePath == '': + f = open(os.environ.get("COOKIE_FILE"), encoding="utf-8").read() + else: + f = open(cookiePath, encoding='utf8').read() + cookie_file = json.loads(f) for cookie in cookie_file: self.session.cookies.set(cookie["name"], cookie["value"]) url = "https://www.bing.com/turing/conversation/create" @@ -211,8 +213,8 @@ class Chatbot: Combines everything to make it seamless """ - def __init__(self) -> None: - self.chat_hub: ChatHub = ChatHub(Conversation()) + def __init__(self, cookiePath: str = '') -> None: + self.chat_hub: ChatHub = ChatHub(Conversation(cookiePath)) async def ask(self, prompt: str) -> dict: """