A zero-configuration tool to automate web-based LLM interactions.
Project description
LLMSession
A zero-configuration tool to automate interactions with web-based LLM providers (currently ChatGPT). It handles authentication, session persistence, and chained prompt execution programmatically.
Features
- Zero-Config Setup: Automatically handles browser binaries via Playwright.
- Session Persistence: Reuses cookies/storage for subsequent runs (no need to login every time).
- Cross-Language Sharing: Sessions are shared between Python and Node.js environments automatically.
- Smart OTP Handling: Supports non-blocking callbacks for 2FA/OTP challenges.
- Resilient: Allows custom CSS selectors to adapt to UI changes without updating the library.
Prerequisites
You must set the following environment variables, or pass them directly to the constructor:
CHATGPT_EMAILCHATGPT_PASSWORDCHATGPT_GOOGLE_LOGIN(Optional: set to "true" if using Google Auth. Note: Google Auth is experimental and may require manual intervention.)
Disclaimer
[!WARNING] 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.
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.
Python Usage
Installation
pip install llm-session
Quick Start
import logging
from llm_session import Automator
# 1. Configure Standard Logging
logging.basicConfig(level=logging.INFO)
# 2. Define OTP Callback (Optional, but recommended for headless envs)
def my_otp_handler():
# In production, you might fetch this from an email API
return input("Enter OTP Code sent to email: ")
# 3. Initialize
bot = Automator(
provider="chatgpt",
headless=False, # Set to True for production (CURRENTLY ONLY WORKS WITH headless=False)
credentials={
"email": "your_email@example.com",
"password": "your_password",
"method": "email" # or "google"
},
on_otp_required=my_otp_handler
)
# 4. Single Prompt
print(bot.process_prompt("Hello, world!"))
# 5. Chained Prompt (Inject previous response)
chain = [
"Write a haiku about Python.",
"Translate this haiku to Spanish: {{previous}}"
]
responses = bot.process_chain(chain)
print(responses)
bot.close()
Node.js Usage
Installation
npm install llm-session
Quick Start
import { Automator } from 'llm-session';
async function main() {
// 1. Define OTP Callback
const onOtpRequired = async () => {
console.log("Please check your email for code.");
// Return code from your logic here
return "123456";
};
// 2. Initialize
const bot = new Automator(
"chatgpt",
false, // headless
{
email: "your_email@example.com",
password: "your_password"
},
undefined, // sessionPath (optional)
{
onOtpRequired: onOtpRequired,
// Optional: Inject your own logger (e.g., Winston, Pino)
// logger: myLoggerInstance
}
);
try {
await bot.init();
const response = await bot.processPrompt("Hello from Node.js!");
console.log(response);
} finally {
await bot.close();
}
}
main();
Advanced Configuration (Resilience)
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.
Python:
bot = Automator(
provider="chatgpt",
config={
"selectors": {
"textarea": "#new-prompt-id",
"send_btn": ".new-send-button-class",
"assistant_msg": ".new-message-wrapper"
}
}
)
Node.js:
const bot = new Automator("chatgpt", true, undefined, undefined, {
selectors: {
textarea: "#new-prompt-id",
send_btn: ".new-send-button-class"
}
});
Session Management
This library stores browser cookies and local storage in your OS's standard user data directory (e.g., %LOCALAPPDATA%/LLMSession on Windows, ~/.local/share/LLMSession on Linux).
- Cross-Language: If you login using the Python script, the Node.js script will automatically detect the existing session and skip login (and vice-versa).
- Persistence: Sessions persist across reboots.
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines on how to build the project locally.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llm_session-0.1.1.tar.gz.
File metadata
- Download URL: llm_session-0.1.1.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
875d52ba9bd1c0d98f39253b67b6f21122a158e04688ca4e655ebc2668332444
|
|
| MD5 |
bc837f7d9270e57620c23df65278c42a
|
|
| BLAKE2b-256 |
c57f9bf9767fd0c32e4399f844edeadae93c967730deebe5a4affe08afe3b7dd
|
File details
Details for the file llm_session-0.1.1-py3-none-any.whl.
File metadata
- Download URL: llm_session-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ce11795d32670e0cfdc56f319b0b74b87f1f0a301284785059042d77d59ac28
|
|
| MD5 |
804c430e00d29fd0625ddf59e48c910d
|
|
| BLAKE2b-256 |
af14154397f1372b53823d39ea42f50038237bbd8b82c2975ae98aa6c881dd17
|