Skip to content

Commit b585dba

Browse files
committed
Fix Bard. Resolves #23.
1 parent 5f8a02b commit b585dba

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ clipman==3.1.0
55
pyperclip==1.8.2
66
appdirs==1.4.4
77
webchatgpt==0.2.7
8-
GoogleBard==1.4.0
8+
GooglBard1==2.1.1
99
colorama==0.4.6
1010
g4f>=0.2.0.6
1111
pyyaml==6.0.1

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@
4444
"pyperclip==1.8.2",
4545
"appdirs==1.4.4",
4646
"webchatgpt==0.2.7",
47-
"GoogleBard==1.4.0",
47+
"GoogleBard1==2.1.1",
4848
"colorama==0.4.6",
4949
"g4f>=0.2.0.6",
50-
"pyyaml==6.0.1",
5150
],
5251
python_requires=">=3.9",
5352
keywords=[

src/pytgpt/bard/main.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,40 @@
1616
class BARD(Provider):
1717
def __init__(
1818
self,
19-
auth: str,
19+
cookie_file: str,
2020
proxy: dict = {},
2121
timeout: int = 30,
2222
):
2323
"""Initializes BARD
2424
2525
Args:
26-
auth (str): `__Secure-1PSID` cookie value (session id) or path to `bard.google.com.cookies.json` file
26+
cookie_file (str): Path to `bard.google.com.cookies.json` file
2727
proxy (dict, optional): Http request proxy. Defaults to {}.
2828
timeout (int, optional): Http request timeout. Defaults to 30.
2929
"""
3030
self.conversation = Conversation(False)
31-
self.session_auth = None
32-
assert isinstance(auth, str), f"auth should be of {str} only not '{type(auth)}'"
33-
if path.isfile(auth):
31+
self.session_auth1 = None
32+
self.session_auth2 = None
33+
assert isinstance(cookie_file, str), f"cookie_file should be of {str} only not '{type(cookie_file)}'"
34+
if path.isfile(cookie_file):
3435
# let's assume auth is a path to exported .json cookie-file
35-
with open(auth) as fh:
36+
with open(cookie_file) as fh:
3637
entries = load(fh)
3738
for entry in entries:
3839
if entry["name"] == "__Secure-1PSID":
39-
self.session_auth = entry["value"]
40-
assert bool(
41-
self.session_auth
42-
), f"Failed to extract the required cookie value from file '{auth}'"
40+
self.session_auth1 = entry["value"]
41+
elif entry['name']=="__Secure-1PAPISID":
42+
self.session_auth2 = entry["value"]
43+
44+
assert all(
45+
[
46+
self.session_auth1, self.session_auth2
47+
]
48+
), f"Failed to extract the required cookie value from file '{cookie_file}'"
4349
else:
44-
# Assume auth is the targeted cookie value
45-
self.session_auth = auth
46-
47-
self.session = Chatbot(self.session_auth, proxy, timeout)
50+
raise Exception(f'{cookie_file} is not a valid file path')
51+
52+
self.session = Chatbot(self.session_auth1,self.session_auth2, proxy, timeout)
4853
self.last_response = {}
4954
self.__available_optimizers = (
5055
method

src/pytgpt/console.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,9 @@ def __init__(
442442

443443
assert (
444444
auth
445-
), f"Bard's session-id or path to bard.google.com.cookies.json file is required"
445+
), f"Path to bard.google.com.cookie.json file is required. Use the flag `--key` or `-k`"
446446
self.bot = BARD(
447-
auth=auth,
447+
cookie_file=auth,
448448
proxy=proxies,
449449
timeout=timeout,
450450
)

0 commit comments

Comments
 (0)