Comments (9)
I am currently working on implementing multi-cookies to the Bard object due to the issue with multiple inheritance.
Additionally, I will also be conducting some overall code refactoring. This change will be updated in version 0.1.40 and documented to accommodate the inclusion of multi-cookies within the Bard object.
from bard-api.
I will check this issue and see all code again. Thank you!
from bard-api.
Another issue is here:
Line 110 in 9345c2c
cookies=False
means that only __Secure-1PSID
is used.
But that does not work for my case, I need all 3 cookies.
And there is no way to achieve with ChatBard
.
from bard-api.
As you know, this package was initially very simple, anticipating its obsolescence with the launch of the official Bard API.
However, as Bard expanded to offer various services, the structure became more complex, and diverse features were added in response to developers' requests. Consequently, I couldn't neatly organize all use cases within a single Bard structure, and although Async seemed of limited utility, it was updated as needed.
For Multi Cookie Bard, a new structure, BardCookies, inheriting from Bard, was placed in a new Python file.
In ChatBard, implementing multicookies in Bard via token_from_browser in core.py called for further modifications, so I've made the following changes:
https://github.com/dsdanielpark/Bard-API/blob/main/bardapi/chat.py#L209
ChatBard has been modified to inherit from BardCookies, which in turn has been adjusted to fetch three cookie values via token_from_browser.
After reinstalling from the GitHub version (after a clean uninstallation),
$ pip install git+https://github.com/dsdanielpark/Bard-API.git
please try it out and let us know if any errors occur. As I only need a single cookie, I couldn't debug this directly.
In progress
If there are no errors, I will update to version 0.1.40 along with the documentation.
Thank you for reporting.
from bard-api.
from bardapi import ChatBard
chat = ChatBard(token_from_browser=True)
chat.start()
Traceback (most recent call last):
File "D:\AI\Bard-API\main1.py", line 1, in <module>
from bardapi import ChatBard
File "D:\AI\Bard-API\bardapi\__init__.py", line 5, in <module>
from bardapi.chat import ChatBard, ChatBardCookise
File "D:\AI\Bard-API\bardapi\chat.py", line 7, in <module>
from bardapi import BardCookies
ImportError: cannot import name 'BardCookies' from partially initialized module 'bardapi' (most likely due to a circular import) (D:\AI\Bard-API\bardapi\__init__.py)
Note Cookise
. Perhaps typo, but it is not the cause of the error: after my correction nothing changed.
diff --git a/bardapi/__init__.py b/bardapi/__init__.py
index 6595aa8..877fbab 100644
--- a/bardapi/__init__.py
+++ b/bardapi/__init__.py
@@ -2,7 +2,7 @@
from os import environ
from bardapi.core import Bard
-from bardapi.chat import ChatBard, ChatBardCookise
+from bardapi.chat import ChatBard, ChatBardCookies
from bardapi.core_async import BardAsync
from bardapi.core_cookies import BardCookies, BardAsyncCookies
from bardapi.constants import (
@@ -28,7 +28,7 @@ bard_api_key = environ.get("_BARD_API_KEY")
__all__ = [
"Bard",
"ChatBard",
- "ChatBardCookise",
+ "ChatBardCookies",
"BardAsync",
"BardCookies",
"BardAsyncCookies",
diff --git a/bardapi/chat.py b/bardapi/chat.py
index b7697f0..ff46fb7 100644
--- a/bardapi/chat.py
+++ b/bardapi/chat.py
@@ -207,18 +207,18 @@ class ChatBard(Bard):
self.chat_history.append({"User": user_input, "Chatbot": chatbot_response})
-class ChatBardCookise(BardCookies):
+class ChatBardCookies(BardCookies):
"""
A class representing a chatbot powered by the Bard API.
Usage:
- chat = ChatBardCookise()
+ chat = ChatBardCookies()
chat.start()
Example:
- from bardapi import ChatBardCookise
+ from bardapi import ChatBardCookies
- chat = ChatBardCookise()
+ chat = ChatBardCookies()
chat.start()
"""
from bard-api.
I have just finished but QA process will be needed.
from bard-api.
In https://github.com/dsdanielpark/Bard-API/blob/main/documents/README_DEV.md#multi-cookie-bard described 3 ways, but there are some errors/mistypes in description.
So here what I have exactly tried:
(only 1 case is successful)
BardCookies + cookie_dict
from bardapi import BardCookies
cookie_dict = {
# Any cookie values you want to pass session object.
}
bard = BardCookies(cookie_dict=cookie_dict)
print(bard.get_answer("こんにちは")['content'])
This works!
BardCookies + session
import requests
from bardapi import BardCookies, SESSION_HEADERS
session = requests.Session()
#session.cookies.set("__Secure-1PSID",
#...
session.headers = SESSION_HEADERS
bard = BardCookies(session=session)
bard.get_answer("How is the weather today in seoul?")
The BardCookies class is no longer in use.
Please use the Bard class with the 'cookie_dict' and 'multi_cookies_bool' arguments in the Bard constructor.
Traceback (most recent call last):
File "D:\AI\Bard-API\main02.py", line 11, in <module>
bard = BardCookies(session=session)
File "D:\AI\Bard-API\bardapi\core_cookies.py", line 50, in __init__
self.cookie_dict = cookie_dict or self._get_token(token_from_browser)
File "D:\AI\Bard-API\bardapi\core_cookies.py", line 81, in _get_token
raise Exception(
Exception: Bard API Key must be provided as token argument or extracted from browser.
Bard + session
import requests
from bardapi import Bard, SESSION_HEADERS
session = requests.Session()
#session.cookies.set("__Secure-1PSID",
#...
session.headers = SESSION_HEADERS
bard = Bard(session=session)
bard.get_answer("How is the weather today in seoul?")
Traceback (most recent call last):
File "D:\AI\Bard-API\main021.py", line 11, in <module>
bard = Bard(session=session, multi_cookies_bool=True)
File "D:\AI\Bard-API\bardapi\core.py", line 74, in __init__
self.token = self._get_token(token, token_from_browser, multi_cookies_bool)
File "D:\AI\Bard-API\bardapi\core.py", line 136, in _get_token
raise Exception(
Exception: Bard API Key must be provided as the 'token' argument or extracted from the browser.
Bard +token_from_browser + multi_cookies_bool
from bardapi import Bard
bard = Bard(token_from_browser=True, multi_cookies_bool=True)
bard.get_answer("How is the weather today in seoul?")
Traceback (most recent call last):
File "D:\AI\Bard-API\main03.py", line 3, in <module>
bard = Bard(token_from_browser=True, multi_cookies_bool=True)
File "D:\AI\Bard-API\bardapi\core.py", line 82, in __init__
self.SNlM0e = self._get_snim0e()
File "D:\AI\Bard-API\bardapi\core.py", line 181, in _get_snim0e
raise Exception(
Exception: Response status code is not 200. Response Status is 404
from bard-api.
I used this code after updating the core.py, core.cookies, constant.py, for the new Gemini formerly Bard. Refer to the issue created by me "Google renames its chatbot Bard to Gemini"
I have provided the solution here using browser_cookie3 for extracting the values of cookies each time when the program gets executed. I have only tested for firefox. So you may install firefox, and sign in Gemini through your google account credentials, and run this code.
from bardapi import SESSION_HEADERS, BardCookies
import browser_cookie3
import requests
domain = '.google.com'
firefox_cookies = browser_cookie3.firefox(domain_name=domain)
psid = '__Secure-1PSID'
dts = '__Secure-1PSIDTS'
dcc = '__Secure-1PSIDCC'
nid = 'NID'
psid_value = None
dts_value = None
dcc_value = None
nid_value = None
for cookie in firefox_cookies:
if cookie.name == psid:
psid_value = cookie.value
elif cookie.name == dts:
dts_value = cookie.value
elif cookie.name == dcc:
dcc_value = cookie.value
elif cookie.name == nid:
nid_value = cookie.value
cookie_dict = {
"__Secure-1PSID": psid_value,
"__Secure-1PSIDTS": dts_value,
"__Secure-1PSIDCC": dcc_value,
}
session = requests.Session()
session.cookies.set("__Secure-1PSID", psid_value)
session.cookies.set( "__Secure-1PSIDCC", dcc_value)
session.cookies.set("__Secure-1PSIDTS", dts_value)
session.cookies.set("NID",nid_value)
session.headers = SESSION_HEADERS
bard = BardCookies(session=session,cookie_dict=cookie_dict)
while True:
question = input("Enter your prompt to Gemini: ")
response = bard.get_answer(question)['content']
data = str(response).replace("*", "")
print(data)
from bard-api.
[NOTICE] Please, go to Gemini-API https://github.com/dsdanielpark/Gemini-API
Google - Gemini API
A unofficial Python wrapper, python-gemini-api, operates through reverse-engineering, utilizing cookie values to interact with Google Gemini for users struggling with frequent authentication problems or unable to authenticate via Google Authentication.
Collaborated competently with Antonio Cheong.
What is Gemini?
[Paper] [Official Website] [Official API] [API Documents]
Gemini is a family of generative AI models developed by Google DeepMind that is designed for multimodal use cases. The Gemini API gives you access to the Gemini Pro and Gemini Pro Vision models. In February 2024, Google's Bard service was changed to Gemini.
Installation
pip install python-gemini-api
pip install git+https://github.com/dsdanielpark/Gemini-API.git
For the updated version, use as follows:
pip install -q -U python-gemini-api
from bard-api.
Related Issues (20)
- ImportError: cannot import name 'BardCookies' from partially initialized module 'bardapi' (most likely due to a circular import) HOT 6
- Some code errors in README examples , os module import HOT 4
- Bard __SECURE-1PSID does not match HOT 2
- Exception: SNlM0e value not found. Double-check __Secure-1PSID value or pass it as Bard(token='xxxxx') HOT 1
- Google changed the the way "__Secure-1PSID" looks, how to use this package effectively,the cookie values does not end in '.' period now HOT 8
- Multiple-Cookies has been changed. HOT 15
- Image generation HOT 4
- Google renames its chatbot Bard to Gemini HOT 41
- Gemini Ultra? HOT 4
- TooManyRedirects: Exceeded 30 redirects. HOT 1
- Check out this Bard/Gemini project. HOT 2
- Google changed their __Secure-1PSID value stracture HOT 2
- ask_about_image Not working HOT 2
- Cookies refreshing very often and getting 429 all the time HOT 2
- How can automaticly get cookies value in no gui servers? HOT 2
- Please, go to Gemini-API `https://github.com/dsdanielpark/Gemini-API`
- a conversation towards getting advance AI HOT 1
- Reflection on the Bard API Project
- Connecting Geminei to Ads HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bard-api.