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

fix a mistake #71

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions src/Bard.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Chatbot:
def __init__(
self,
secure_1psid: str,
secure_1psidts: str,
secure_1psidts : str,
proxy: dict = None,
timeout: int = 20,
):
Expand Down Expand Up @@ -112,7 +112,7 @@ class AsyncChatbot:
def __init__(
self,
secure_1psid: str,
secure_1psidts: str,
secure_1psidts : str,
proxy: dict = None,
timeout: int = 20,
):
Expand All @@ -134,22 +134,21 @@ def __init__(
self.session = httpx.AsyncClient(proxies=self.proxy)
self.session.headers = headers
self.session.cookies.set("__Secure-1PSID", secure_1psid)
if secure_1psidts:
self.session.cookies.set("__Secure-1PSIDTS", secure_1psidts)
self.session.cookies.set("__Secure-1PSIDTS", secure_1psidts)
self.timeout = timeout

@classmethod
async def create(
cls,
secure_1psid: str,
secure_1psidts: str,
secure_1psidts:str,
proxy: dict = None,
timeout: int = 20,
) -> "AsyncChatbot":
"""
Async constructor.
"""
instance = cls(secure_1psid, secure_1psidts, proxy, timeout)
instance = cls(secure_1psid,secure_1psidts, proxy, timeout)
instance.SNlM0e = await instance.__get_snlm0e()
return instance

Expand Down Expand Up @@ -218,10 +217,7 @@ async def load_conversation(self, file_path: str, conversation_name: str) -> boo

async def __get_snlm0e(self):
# Find "SNlM0e":"<ID>"
if (
not (self.secure_1psid and self.secure_1psidts)
or self.secure_1psid[-1] != "."
):
if not (self.secure_1psid and self.secure_1psidts) or self.secure_1psid[-1] != ".":
raise Exception(
"Enter correct __Secure-1PSID and __Secure-1PSIDTS value. __Secure-1PSID value must end with a single dot. ",
)
Expand Down Expand Up @@ -310,11 +306,9 @@ async def ask(self, message: str) -> dict:
Secure_1PSID = os.getenv("BARD___Secure-1PSID")
Secure_1PSIDTS = os.getenv("BARD__Secure-1PSIDTS")
if not (Secure_1PSID and Secure_1PSIDTS):
print(
"BARD___Secure-1PSID or BARD__Secure-1PSIDTS environment variable not set."
)
print("BARD___Secure-1PSID or BARD__Secure-1PSIDTS environment variable not set.")
sys.exit(1)
chatbot = Chatbot(Secure_1PSID, Secure_1PSIDTS)
chatbot = Chatbot(Secure_1PSID,Secure_1PSIDTS)
# Join arguments into a single string
MESSAGE = " ".join(sys.argv[1:])
response = chatbot.ask(MESSAGE)
Expand All @@ -332,7 +326,7 @@ async def ask(self, message: str) -> dict:
"--session_ts",
help="__Secure_1PSIDTS cookie.",
type=str,
required=True,
required=True
)
args = parser.parse_args()

Expand Down