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

Commit

Permalink
Update Bard version (#7)
Browse files Browse the repository at this point in the history
* Update Bard version

* Add util function for digits
  • Loading branch information
vsakkas authored Nov 7, 2023
1 parent 4be0528 commit 5de22a6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions bard/bard.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from aiohttp import ClientSession

from bard.constants import BARD_STREAM_GENERATE_URL, BARD_URL, HEADERS
from bard.constants import BARD_STREAM_GENERATE_URL, BARD_URL, BARD_VERSION, HEADERS
from bard.exceptions import AskException, CreateConversationException
from bard.utils import double_json_stringify
from bard.utils import double_json_stringify, random_digit_as_string


class BardClient:
Expand Down Expand Up @@ -54,8 +54,8 @@ async def _get_session(self, force_close: bool = False) -> ClientSession:

def _build_ask_parameters(self) -> dict:
return {
"bl": "boq_assistant-bard-web-server_20231031.09_p7",
"_reqid": "".join(str(random.randint(0, 9)) for _ in range(7)),
"bl": BARD_VERSION,
"_reqid": random_digit_as_string(7),
"rt": "c",
}

Expand Down
2 changes: 2 additions & 0 deletions bard/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@
"X-Same-Domain": "1",
}

BARD_VERSION = "boq_assistant-bard-web-server_20231105.14_p0"

BARD_URL = "https://bard.google.com/chat"
BARD_STREAM_GENERATE_URL = "https://bard.google.com/_/BardChatUi/data/assistant.lamda.BardFrontendService/StreamGenerate"
5 changes: 5 additions & 0 deletions bard/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import json
import random


def double_json_stringify(data) -> str:
return json.dumps([None, json.dumps(data)])


def random_digit_as_string(length: int) -> str:
return "".join(str(random.randint(0, 9)) for _ in range(length))

0 comments on commit 5de22a6

Please sign in to comment.