dsdanielpark / Bard-API

The unofficial python package that returns response of Google Bard through cookie value.
https://pypi.org/project/bardapi/
MIT License
5.33k stars 529 forks source link

Fix misc #273

Closed jjkoh95 closed 8 months ago

jjkoh95 commented 8 months ago

Fix misc async client issue

  1. Newer tokens don't necessarily end with token (it happened on me)
    • Understand that this is merely logging, happy to revert back if we need this message
  2. async_setup() should initialize client first
  3. Use back old regex for SNlM0e, the updated version throw me error, however by reverting to the old regex format, it works fine for me, sorry if this is a breaking thing, I guess we can check both if we want to be safe.

Description

Mentioned above.

Related Issue

Motivation and Context

I updated to the latest version and it was breaking.

How Has This Been Tested?

  1. installing bardapi

    poetry add --no-cache git+https://github.com/jjkoh95/Bard-API.git#fix-misc
    # or
    pip install git+https://github.com/jjkoh95/Bard-API.git#fix-misc
  2. my code snippet

        bard_client = BardAsync(bard_cfg.psid)
        if bard_cfg.psidts: bard_client.cookie_dict["__Secure-1PSIDTS"] = bard_cfg.psidts
        if bard_cfg.psidcc: bard_client.cookie_dict["__Secure-1PSIDCC"] = bard_cfg.psidcc
        await bard_client.async_setup()
    
        result = await bard_client.ask("Hello")
        print(i, result.drafts[0].text)
  3. result image

Screenshots (if appropriate):

Mentioned above

Thank you once again to all the contributors. Your efforts are greatly appreciated!

dsdanielpark commented 8 months ago

Thank you for your contributions. I will check and make some modifications.