diff --git a/bard/bard.py b/bard/bard.py index cc03b32..2b2687b 100644 --- a/bard/bard.py +++ b/bard/bard.py @@ -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: @@ -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", } diff --git a/bard/constants.py b/bard/constants.py index 121b14b..f7d6b02 100644 --- a/bard/constants.py +++ b/bard/constants.py @@ -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" diff --git a/bard/utils.py b/bard/utils.py index e9a9835..7780214 100644 --- a/bard/utils.py +++ b/bard/utils.py @@ -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))