summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/Bard.py
diff options
context:
space:
mode:
authorHeiner Lohaus <heiner@lohaus.eu>2023-09-20 06:12:34 +0200
committerHeiner Lohaus <heiner@lohaus.eu>2023-09-20 06:12:34 +0200
commit82bd6f91808a383781807262c4ae1f3de9740531 (patch)
tree9a12306a3dda5e883bc21e13b2f50294892a2fc9 /g4f/Provider/Bard.py
parent~ | Merge pull request #914 from hlohaus/lesh (diff)
downloadgpt4free-82bd6f91808a383781807262c4ae1f3de9740531.tar
gpt4free-82bd6f91808a383781807262c4ae1f3de9740531.tar.gz
gpt4free-82bd6f91808a383781807262c4ae1f3de9740531.tar.bz2
gpt4free-82bd6f91808a383781807262c4ae1f3de9740531.tar.lz
gpt4free-82bd6f91808a383781807262c4ae1f3de9740531.tar.xz
gpt4free-82bd6f91808a383781807262c4ae1f3de9740531.tar.zst
gpt4free-82bd6f91808a383781807262c4ae1f3de9740531.zip
Diffstat (limited to 'g4f/Provider/Bard.py')
-rw-r--r--g4f/Provider/Bard.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/g4f/Provider/Bard.py b/g4f/Provider/Bard.py
index 2137d820..4e076378 100644
--- a/g4f/Provider/Bard.py
+++ b/g4f/Provider/Bard.py
@@ -13,6 +13,7 @@ class Bard(AsyncProvider):
url = "https://bard.google.com"
needs_auth = True
working = True
+ _snlm0e = None
@classmethod
async def create_async(
@@ -31,7 +32,6 @@ class Bard(AsyncProvider):
headers = {
'authority': 'bard.google.com',
- 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8',
'origin': 'https://bard.google.com',
'referer': 'https://bard.google.com/',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
@@ -42,13 +42,14 @@ class Bard(AsyncProvider):
cookies=cookies,
headers=headers
) as session:
- async with session.get(cls.url, proxy=proxy) as response:
- text = await response.text()
+ if not cls._snlm0e:
+ async with session.get(cls.url, proxy=proxy) as response:
+ text = await response.text()
- match = re.search(r'SNlM0e\":\"(.*?)\"', text)
- if not match:
- raise RuntimeError("No snlm0e value.")
- snlm0e = match.group(1)
+ match = re.search(r'SNlM0e\":\"(.*?)\"', text)
+ if not match:
+ raise RuntimeError("No snlm0e value.")
+ cls._snlm0e = match.group(1)
params = {
'bl': 'boq_assistant-bard-web-server_20230326.21_p0',
@@ -57,7 +58,7 @@ class Bard(AsyncProvider):
}
data = {
- 'at': snlm0e,
+ 'at': cls._snlm0e,
'f.req': json.dumps([None, json.dumps([[prompt]])])
}