From e83610d49a70d98ed9aeb24231c5fc3559d4642c Mon Sep 17 00:00:00 2001 From: Jia Jun Koh Date: Mon, 5 Feb 2024 17:07:20 +0800 Subject: [PATCH 1/4] Newer tokens don't necessarily end with dot --- bardapi/core_async.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/bardapi/core_async.py b/bardapi/core_async.py index 31fe88fad..159deb5ec 100644 --- a/bardapi/core_async.py +++ b/bardapi/core_async.py @@ -129,11 +129,6 @@ async def _get_snim0e(self) -> Optional[str]: if isinstance(self.SNlM0e, str): return self.SNlM0e - if not self.token or self.token[-1] != ".": - print( - "__Secure-1PSID value should end with a single dot. Enter correct __Secure-1PSID value." - ) - resp = await self.client.get( "https://bard.google.com/", timeout=self.timeout, follow_redirects=True ) From cab2a5514ac618d68f191b08543078999fa4605d Mon Sep 17 00:00:00 2001 From: Jia Jun Koh Date: Mon, 5 Feb 2024 17:15:18 +0800 Subject: [PATCH 2/4] Fix initialize client first --- bardapi/core_async.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bardapi/core_async.py b/bardapi/core_async.py index 159deb5ec..96f1b3c48 100644 --- a/bardapi/core_async.py +++ b/bardapi/core_async.py @@ -115,9 +115,11 @@ async def async_setup(self) -> None: """ Set up the BardAsync instance asynchronously. """ - self.SNlM0e = await self._get_snim0e() + # Note: + # we have to initialize client first, since _get_snim0e requires client if not self.client: self.client = await self._initialize_client() # Ensure this is awaited + self.SNlM0e = await self._get_snim0e() async def _get_snim0e(self) -> Optional[str]: """ @@ -835,7 +837,7 @@ async def ask( image_name: Optional[str] = None, tool: Optional[Tool] = None, ) -> BardResult: - if not isinstance(self.SNlM0e, str): + if not isinstance(self.SNlM0e, str) and self.SNlM0e is not None: self.SNlM0e = await self.SNlM0e if image is not None: From 8eb8d5161aabf36a909fa86f4ddf09767e2c60fa Mon Sep 17 00:00:00 2001 From: Jia Jun Koh Date: Mon, 5 Feb 2024 17:25:02 +0800 Subject: [PATCH 3/4] Revert back to old regex format --- bardapi/core_async.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bardapi/core_async.py b/bardapi/core_async.py index 96f1b3c48..709c6cdb8 100644 --- a/bardapi/core_async.py +++ b/bardapi/core_async.py @@ -138,7 +138,7 @@ async def _get_snim0e(self) -> Optional[str]: raise ConnectionError( f"Failed to fetch SNlM0e. Response status: {resp.status_code}" ) - snim0e_match = re.search(r'\\?*"SNlM0e\\?*":"(.*?)"', resp.text) + snim0e_match = re.search(r"SNlM0e\":\"(.*?)\"", resp.text) if not snim0e_match: raise LookupError( "SNlM0e value not found in response. Check __Secure-1PSID value." From 6fa5a8318080cc093a4cecfe2e0283950e692a65 Mon Sep 17 00:00:00 2001 From: Jia Jun Koh Date: Mon, 5 Feb 2024 17:47:19 +0800 Subject: [PATCH 4/4] Apply `black bardapi` --- bardapi/models/tools/youtube.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bardapi/models/tools/youtube.py b/bardapi/models/tools/youtube.py index c5a26cad2..feee25ea4 100644 --- a/bardapi/models/tools/youtube.py +++ b/bardapi/models/tools/youtube.py @@ -73,9 +73,11 @@ def __str__(self) -> str: @property def markdown_text(self) -> str: videos = [ - f"1. [{video.title}]({video.url}) by {video.author}\n\n - {video.text}" - if video.text - else f"1. [{video.title}]({video.url}) by {video.author}" + ( + f"1. [{video.title}]({video.url}) by {video.author}\n\n - {video.text}" + if video.text + else f"1. [{video.title}]({video.url}) by {video.author}" + ) for video in self.videos ]