Skip to content

Commit

Permalink
document
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio committed May 28, 2023
1 parent 71b31b1 commit 6166adf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
7 changes: 4 additions & 3 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

# Bard

Reverse engineering of Google Bard

<a id="Bard.Chatbot"></a>

## Chatbot Objects
Expand All @@ -17,6 +15,10 @@ Parameters
session_id: str
The __Secure-1PSID cookie.
proxy: str
timeout: int
Request timeout in seconds.
session: requests.Session
Requests session object.

<a id="Bard.Chatbot.ask"></a>

Expand All @@ -35,4 +37,3 @@ Send a message to Google Bard and return the response.
**Returns**:

A dict containing the response from Google Bard.

20 changes: 12 additions & 8 deletions src/Bard.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
import os
import random
import re
import sys
import string
import sys
import time

import requests
from prompt_toolkit import prompt, PromptSession
from prompt_toolkit import prompt
from prompt_toolkit import PromptSession
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.history import InMemoryHistory
from prompt_toolkit.key_binding import KeyBindings
from rich.console import Console
from rich.markdown import Markdown
import time


def __create_session() -> PromptSession:
Expand Down Expand Up @@ -118,7 +120,7 @@ def load_conversations(self, file_path: str) -> list[dict]:
# Check if file exists
if not os.path.isfile(file_path):
return []
with open(file_path, "r", encoding="utf-8") as f:
with open(file_path, encoding="utf-8") as f:
return json.load(f)

def load_conversation(self, file_path: str, conversation_name: str) -> bool:
Expand All @@ -140,19 +142,21 @@ def __get_snlm0e(self):
# Find "SNlM0e":"<ID>"
if not self.session_id or self.session_id[-1] != ".":
raise Exception(
"__Secure-1PSID value must end with a single dot. Enter correct __Secure-1PSID value."
"__Secure-1PSID value must end with a single dot. Enter correct __Secure-1PSID value.",
)
resp = self.session.get(
"https://bard.google.com/", timeout=10, proxies=self.proxy
"https://bard.google.com/",
timeout=10,
proxies=self.proxy,
)
if resp.status_code != 200:
raise Exception(
f"Response code not 200. Response Status is {resp.status_code}"
f"Response code not 200. Response Status is {resp.status_code}",
)
SNlM0e = re.search(r"SNlM0e\":\"(.*?)\"", resp.text)
if not SNlM0e:
raise Exception(
"SNlM0e value not found in response. Check __Secure-1PSID value."
"SNlM0e value not found in response. Check __Secure-1PSID value.",
)
return SNlM0e.group(1)

Expand Down

0 comments on commit 6166adf

Please sign in to comment.