From 5de22a69e51cafbca7b43d039f7d276ff4e69ba9 Mon Sep 17 00:00:00 2001 From: vsakkas Date: Tue, 7 Nov 2023 20:17:23 +0200 Subject: [PATCH] Update Bard version (#7) * Update Bard version * Add util function for digits --- bard/bard.py | 8 ++++---- bard/constants.py | 2 ++ bard/utils.py | 5 +++++ 3 files changed, 11 insertions(+), 4 deletions(-) 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))