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

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dsdanielpark committed Sep 28, 2023
2 parents 78bcbab + 2ffd33f commit 104905d
Show file tree
Hide file tree
Showing 24 changed files with 1,034 additions and 234 deletions.
2 changes: 2 additions & 0 deletions bardapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
SEPARATOR_LINE,
USER_PROMPT,
IMG_UPLOAD_HEADERS,
Tool
)
from bardapi.utils import (
extract_links,
Expand Down Expand Up @@ -41,6 +42,7 @@
"extract_bard_cookie",
"max_token",
"max_sentence",
"Tool",
]
__version__ = "0.1.34"
__author__ = "daniel park <parkminwoo1991@gmail.com>"
12 changes: 8 additions & 4 deletions bardapi/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ def __init__(
# Chat history
self.chat_history = []

def _init_session(self, token):
@staticmethod
def _init_session(token):
session = requests.Session()
session.headers = SESSION_HEADERS
session.cookies.set("__Secure-1PSID", token)
return session

def _get_api_key(self):
@staticmethod
def _get_api_key():
key = input("Enter the Bard API Key(__Secure-1PSID): ")
if not key:
print("Bard API(__Secure-1PSID) Key must be entered.")
Expand Down Expand Up @@ -149,7 +151,8 @@ def display_chat_history(self) -> None:

print(SEPARATOR_LINE)

def _is_valid_input(self, user_input: str) -> bool:
@staticmethod
def _is_valid_input(user_input: str) -> bool:
"""
Checks if the user input is valid.
Expand All @@ -167,7 +170,8 @@ def _is_valid_input(self, user_input: str) -> bool:
return False
return True

def _display_response(self, response: dict) -> None:
@staticmethod
def _display_response(response: dict) -> None:
"""
Displays the chatbot's response.
Expand Down
13 changes: 12 additions & 1 deletion bardapi/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from enum import Enum

from colorama import Fore

ALLOWED_LANGUAGES = {"en", "ko", "ja", "english", "korean", "japanese"}
Expand All @@ -6,7 +8,6 @@
USER_PROMPT = Fore.BLUE + "You: " + Fore.RESET
TEXT_GENERATION_WEB_SERVER_PARAM = "boq_assistant-bard-web-server_20230912.07_p1"


SESSION_HEADERS = {
"Host": "bard.google.com",
"X-Same-Domain": "1",
Expand Down Expand Up @@ -54,3 +55,13 @@
"rust": "main.rs",
"perl": "main.pl",
}


class Tool(Enum):
GMAIL = ["workspace_tool", "Gmail"]
GOOGLE_DOCS = ["workspace_tool", "Google Docs"]
GOOGLE_DRIVE = ["workspace_tool", "Google Drive"]
GOOGLE_FLIGHTS = ["google_flights_tool"]
GOOGLE_HOTELS = ["google_hotels_tool"]
GOOGLE_MAPS = ["google_map_tool"]
YOUTUBE = ["youtube_tool"]
Loading

0 comments on commit 104905d

Please sign in to comment.