Skip to content

Commit

Permalink
feat: make cookies non-required
Browse files Browse the repository at this point in the history
  • Loading branch information
F33RNI committed May 14, 2024
1 parent 030396a commit a5bd47b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions configs/chatgpt.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"__comment01__": "ChatGPT module config file <https://github.com/F33RNI/LlM-Api-Open>",

"__comment02__": "File for loading and saving cookies. Install cookie editor extension, for example:",
"__comment02__": "File for loading and saving cookies. (Possibly not required anymore) Install editor extension:",
"__comment03__": "<https://chrome.google.com/webstore/detail/cookie-editor/hlkenndednhfkekhgcdicdfddnkalmdm>",
"__comment04__": "Go to <https://chat.openai.com/> and ask ChatGPT about something",
"__comment05__": "Open the extension, click Export on the bottom right, then Export as JSON",
Expand All @@ -16,7 +16,7 @@
"version_main_manual": null,

"__comment10__": "Path to driver executable to pass as driver_executable_path argument or empty for auto",
"__comment11__": "It's recommended ot leave this empty",
"__comment11__": "It's recommended to leave this empty",
"driver_executable_path": "",

"__comment12__": "Set to true to enable proxy",
Expand Down
4 changes: 2 additions & 2 deletions configs/ms_copilot.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"__comment01__": "Microsoft Copilot module config file <https://github.com/F33RNI/LlM-Api-Open>",

"__comment02__": "File for loading and saving cookies. Install cookie editor extension, for example:",
"__comment02__": "File for loading and saving cookies. (Possibly not required anymore) Install editor extension:",
"__comment03__": "<https://chrome.google.com/webstore/detail/cookie-editor/hlkenndednhfkekhgcdicdfddnkalmdm>",
"__comment04__": "Go to <https://copilot.microsoft.com/> log in and ask about something. Wait for response",
"__comment05__": "Open the extension, click Export on the bottom right, then Export as JSON",
Expand All @@ -16,7 +16,7 @@
"version_main_manual": null,

"__comment10__": "Path to driver executable to pass as driver_executable_path argument or empty for auto",
"__comment11__": "It's recommended ot leave this empty",
"__comment11__": "It's recommended to leave this empty",
"driver_executable_path": "",

"__comment12__": "Set to true to enable proxy",
Expand Down
13 changes: 7 additions & 6 deletions src/lmao/chatgpt/chatgpt_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,13 @@ def session_start(self, **kwargs) -> None:
try:
# Load cookies
cookies_file = self.config.get("cookies_file")
logging.info(f"Loading cookies from {cookies_file}")
with open(cookies_file, "r", encoding="utf-8") as file:
self._cookies = json.load(file)
if self._cookies is None or not isinstance(self._cookies, list) or len(self._cookies) == 0:
raise Exception("Empty or wrong cookies file")
logging.info(f"Loaded {len(self._cookies)} cookies")
if cookies_file and os.path.exists(cookies_file):
logging.info(f"Loading cookies from {cookies_file}")
with open(cookies_file, "r", encoding="utf-8") as file:
self._cookies = json.load(file)
if self._cookies is None or not isinstance(self._cookies, list) or len(self._cookies) == 0:
raise Exception("Empty or wrong cookies file")
logging.info(f"Loaded {len(self._cookies)} cookies")

# Set driver options
logging.info("Adding chrome options")
Expand Down
13 changes: 7 additions & 6 deletions src/lmao/ms_copilot/ms_copilot_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,13 @@ def session_start(self, **kwargs) -> None:
try:
# Load cookies
cookies_file = self.config.get("cookies_file")
logging.info(f"Loading cookies from {cookies_file}")
with open(cookies_file, "r", encoding="utf-8") as file:
self._cookies = json.load(file)
if self._cookies is None or not isinstance(self._cookies, list) or len(self._cookies) == 0:
raise Exception("Empty or wrong cookies file")
logging.info(f"Loaded {len(self._cookies)} cookies")
if cookies_file and os.path.exists(cookies_file):
logging.info(f"Loading cookies from {cookies_file}")
with open(cookies_file, "r", encoding="utf-8") as file:
self._cookies = json.load(file)
if self._cookies is None or not isinstance(self._cookies, list) or len(self._cookies) == 0:
raise Exception("Empty or wrong cookies file")
logging.info(f"Loaded {len(self._cookies)} cookies")

# Set driver options
logging.info("Adding chrome options")
Expand Down

0 comments on commit a5bd47b

Please sign in to comment.