Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #273 from jjkoh95/fix-misc
Browse files Browse the repository at this point in the history
fix: misc
  • Loading branch information
dsdanielpark authored Feb 6, 2024
2 parents 7f45bcb + 6fa5a83 commit bba3c05
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
13 changes: 5 additions & 8 deletions bardapi/core_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
"""
Expand All @@ -129,19 +131,14 @@ 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
)
if resp.status_code != 200:
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."
Expand Down Expand Up @@ -840,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:
Expand Down
8 changes: 5 additions & 3 deletions bardapi/models/tools/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
]

Expand Down

0 comments on commit bba3c05

Please sign in to comment.