Skip to content

Commit 1c2bdc5

Browse files
committed
feat: added user defined session_path and minor fixes
1 parent 223a881 commit 1c2bdc5

File tree

5 files changed

+94
-221
lines changed

5 files changed

+94
-221
lines changed

README.md

Lines changed: 41 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
# LLMSession
22

33
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
4-
[![Build and Publish](https://github.com/star-173/llm_session/actions/workflows/publish.yml/badge.svg)](https://github.com/star-173/llm_session/actions/workflows/publish.yml)
54
[![PyPI version](https://badge.fury.io/py/llm-session.svg)](https://pypi.org/project/llm-session/)
65
[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
76

8-
A zero-configuration tool to automate interactions with web-based LLM providers (currently ChatGPT). It handles authentication, session persistence, and chained prompt execution programmatically.
7+
A zero-configuration tool to automate interactions with web-based LLM providers (**ChatGPT** and **Claude**). It handles authentication, session persistence, and chained prompt execution programmatically.
98

109
## Features
10+
- **Multi-Provider Support**: Automate interactions with all ChatGPT, AIStudio and Claude (Anthropic).
1111
- **Zero-Config Setup**: Automatically handles browser binaries via Playwright.
1212
- **Session Persistence**: Reuses cookies/storage for subsequent runs (no need to login every time).
13-
- **Smart OTP Handling**: Supports non-blocking callbacks for 2FA/OTP challenges.
1413
- **Resilient**: Allows custom CSS selectors to adapt to UI changes without updating the library.
1514

1615
## Prerequisites
17-
You must set the following environment variables, or pass them directly to the constructor:
18-
- `CHATGPT_EMAIL`
19-
- `CHATGPT_PASSWORD`
20-
- `CHATGPT_GOOGLE_LOGIN` (Optional: set to "true" if using Google Auth. *Note: Google Auth is experimental and may require manual intervention.*)
16+
You must set the following environment variables, or pass them directly to the constructor via the `credentials` dictionary.(Currently, Use google account only in order to login)
17+
18+
**Google Login:**
19+
- `LLM_EMAIL`
20+
- `LLM_PASSWORD`
2121

2222
## Disclaimer
2323
> [!WARNING]
24-
> **Cloudflare/Bot Detection**: Automated interactions with ChatGPT are subject to high-security bot detection (Cloudflare). This library uses standard browser automation and may be blocked. For production reliability, please use the Official OpenAI API.
24+
> **Cloudflare/Bot Detection**: Automated interactions with web providers are subject to high-security bot detection. This library uses standard browser automation and may be blocked. For production reliability, please use the Official OpenAI or Anthropic APIs.
2525
2626
This tool automates a third-party web interface. It is subject to breakage if the target website changes its DOM structure. Use responsibly and in accordance with the provider's Terms of Service.
2727

@@ -44,19 +44,18 @@ from llm_session import Automator
4444
# 1. Configure Standard Logging
4545
logging.basicConfig(level=logging.INFO)
4646

47-
# 2. Define OTP Callback (Optional, but recommended for headless envs)
47+
# 2. Define OTP Callback (Optional)
4848
def my_otp_handler():
49-
# In production, you might fetch this from an email API
5049
return input("Enter OTP Code sent to email: ")
5150

52-
# 3. Initialize
51+
# 3. Initialize (Select 'chatgpt' or 'claude')
5352
bot = Automator(
54-
provider="chatgpt",
55-
headless=False, # Set to True for production (CURRENTLY ONLY WORKS WITH headless=False)
53+
provider="claude", # Options: "chatgpt", "claude"
54+
headless=False, # Set to True for headless mode (may increase detection risk)
5655
credentials={
5756
"email": "your_email@example.com",
5857
"password": "your_password",
59-
"method": "email" # or "google"
58+
"method": "google" # Claude provider defaults to Google Auth flows
6059
},
6160
on_otp_required=my_otp_handler
6261
)
@@ -81,7 +80,7 @@ bot.close()
8180

8281
### Custom Selectors
8382

84-
Websites change their layout often. If ChatGPT updates their CSS class names, you don't need to wait for a package update. You can inject your own selectors during initialization.
83+
Websites change their layout often. If a provider updates their CSS class names, you don't need to wait for a package update. You can inject your own selectors during initialization.
8584

8685
```python
8786
bot = Automator(
@@ -103,25 +102,26 @@ Instead of passing credentials directly, you can use environment variables:
103102
```python
104103
import os
105104

106-
os.environ["CHATGPT_EMAIL"] = "your_email@example.com"
107-
os.environ["CHATGPT_PASSWORD"] = "your_password"
105+
os.environ["LLM_EMAIL"] = "your_email@example.com"
106+
# The library will detect these automatically
108107

109-
bot = Automator(provider="chatgpt", headless=False)
108+
bot = Automator(provider="claude", headless=False)
110109
```
111110

112111
---
113112

114113
## Session Management
115114

116-
This library stores browser cookies and local storage in your OS's standard user data directory:
115+
This library stores browser cookies and local storage in your OS's standard user data directory. This allows the browser to maintain a "Logged In" state between script executions.
116+
117117
- **Windows**: `%LOCALAPPDATA%\LLMSession`
118118
- **Linux**: `~/.local/share/LLMSession`
119119
- **macOS**: `~/Library/Application Support/LLMSession`
120120

121121
**Key Features:**
122-
- **Persistence**: Sessions persist across reboots—no need to login every time
123-
- **Security**: Sensitive data is stored locally and never transmitted
124-
- **Reusable**: Once authenticated, subsequent runs will skip the login process
122+
- **Persistence**: Sessions persist across reboots.
123+
- **Context Isolation**: Each session runs in a persistent browser context.
124+
- **Security**: Sensitive data is stored locally and never transmitted.
125125

126126
---
127127

@@ -145,15 +145,15 @@ Automator(
145145
```
146146

147147
**Parameters:**
148-
- `provider` (str): The LLM provider to use (currently only "chatgpt" is supported)
149-
- `headless` (bool): Whether to run browser in headless mode. Default: `False`
148+
- `provider` (str): The LLM provider to use. Supported: `"chatgpt"`, `"claude"`.
149+
- `headless` (bool): Whether to run browser in headless mode. Default: `False`.
150150
- `credentials` (dict): Dictionary containing login credentials:
151-
- `email` (str): Login email
152-
- `password` (str): Login password
153-
- `method` (str): Authentication method - "email" or "google". Default: "email"
154-
- `session_path` (str, optional): Custom path for session storage. If not provided, uses OS default
155-
- `config` (dict, optional): Configuration options including custom selectors
156-
- `on_otp_required` (callable, optional): Callback function to handle OTP/2FA challenges
151+
- `email` (str): Login email.
152+
- `password` (str): Login password.
153+
- `method` (str): "email" or "google".
154+
- `session_path` (str, optional): Custom path for session storage. If not provided, uses OS default.
155+
- `config` (dict, optional): Configuration options including custom selectors.
156+
- `on_otp_required` (callable, optional): Callback function to handle OTP/2FA challenges.
157157

158158
#### Methods
159159

@@ -188,102 +188,27 @@ bot.close()
188188

189189
---
190190

191-
## Examples
192-
193-
### Example 1: Basic Usage
194-
195-
```python
196-
from llm_session import Automator
197-
198-
bot = Automator(
199-
provider="chatgpt",
200-
headless=False,
201-
credentials={
202-
"email": "user@example.com",
203-
"password": "password123"
204-
}
205-
)
206-
207-
response = bot.process_prompt("Explain quantum computing in simple terms.")
208-
print(response)
209-
210-
bot.close()
211-
```
212-
213-
### Example 2: Chained Prompts
214-
215-
```python
216-
from llm_session import Automator
217-
218-
bot = Automator(provider="chatgpt", headless=False)
219-
220-
# Create a story step by step
221-
chain = [
222-
"Write the first paragraph of a sci-fi story.",
223-
"Continue this story: {{previous}}",
224-
"Write a dramatic ending for: {{previous}}"
225-
]
226-
227-
story_parts = bot.process_chain(chain)
228-
full_story = "\n\n".join(story_parts)
229-
print(full_story)
230-
231-
bot.close()
232-
```
233-
234-
### Example 3: With OTP Handler
235-
236-
```python
237-
from llm_session import Automator
238-
239-
def handle_otp():
240-
"""Fetch OTP from email or user input"""
241-
code = input("Enter the OTP sent to your email: ")
242-
return code
243-
244-
bot = Automator(
245-
provider="chatgpt",
246-
headless=False,
247-
credentials={
248-
"email": "user@example.com",
249-
"password": "password123"
250-
},
251-
on_otp_required=handle_otp
252-
)
253-
254-
response = bot.process_prompt("Hello!")
255-
print(response)
256-
257-
bot.close()
258-
```
259-
260-
---
261-
262191
## Troubleshooting
263192

264193
### Issue: Login fails with "Invalid credentials"
265194
**Solution**:
266-
- Verify your email and password are correct
267-
- Check if you have 2FA enabled (provide `on_otp_required` callback)
268-
- Try logging in manually in a browser first to ensure your account is accessible
195+
- Verify your email and password.
196+
- Check if you have 2FA enabled (provide `on_otp_required` callback).
197+
- **Claude Users**: If using Google Auth, ensure the browser window (non-headless) allows you to click through any security prompts initially.
269198

270199
### Issue: "Cloudflare challenge detected"
271200
**Solution**:
272-
- This library uses standard browser automation which may be detected
273-
- Try running with `headless=False` to solve CAPTCHA manually
274-
- For production use, consider using the official OpenAI API instead
201+
- This library uses standard browser automation which may be detected.
202+
- Try running with `headless=False` to solve CAPTCHA manually.
275203

276-
### Issue: Selectors not working after ChatGPT update
277-
**Solution**:
278-
- Use the custom selectors feature to update CSS selectors
279-
- Or wait for a library update with fixed selectors
280-
- Check GitHub issues for community-reported solutions
204+
### Issue: Popup not closing (Claude/Google Auth)
205+
**Solution**:
206+
- The library attempts to handle Google's "Continue" interstitial screens. If it gets stuck, manual intervention in `headless=False` mode usually fixes the session for future headless runs.
281207

282208
### Issue: Session not persisting
283209
**Solution**:
284-
- Ensure the session directory has write permissions
285-
- Check if antivirus is blocking file writes
286-
- Try specifying a custom `session_path` with known write access
210+
- Ensure the session directory has write permissions.
211+
- Check if antivirus is blocking file writes.
287212

288213
---
289214

@@ -299,12 +224,4 @@ We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guid
299224

300225
## License
301226

302-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
303-
304-
---
305-
306-
## Support
307-
308-
- **Issues**: [GitHub Issues](https://github.com/star-173/llm_session/issues)
309-
- **Discussions**: [GitHub Discussions](https://github.com/star-173/llm_session/discussions)
310-
227+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "llm_session"
7-
version = "0.1.4"
7+
version = "0.1.5"
88
description = "A zero-configuration tool to automate web-based LLM interactions."
99
readme = "README.md"
1010
authors = [{ name = "LLM_Session", email = "shoaib.star.a@gmail.com" }]

0 commit comments

Comments
 (0)