Skip to content

Commit

Permalink
Add: specify cookie file by parameter (Chanzhaoyu#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
arielherself authored Feb 15, 2023
1 parent 0db0b7b commit bf93dd7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 8 additions & 6 deletions src/EdgeGPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,19 @@ class Conversation:
Conversation API
"""

def __init__(self) -> None:
def __init__(self, cookiePath: str = '') -> None:
self.struct: dict = {
"conversationId": None,
"clientId": None,
"conversationSignature": 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"
Expand Down Expand Up @@ -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:
"""
Expand Down

0 comments on commit bf93dd7

Please sign in to comment.