My personal text generation hub for connecting to web-based LLMs in an automated manner. The package is available for both Python and Node.js environments, allowing flexible integration into various projects.
It consists of:
- Node.js backend – handles direct interactions with LLMs using Puppeteer and related tools.
- Python wrapper – allows seamless integration into Python applications and agents.
- ChatGPT - OpenAI's ChatGPT via web interface
- DeepSeek - DeepSeek Chat via web interface (https://chat-deep.ai/deepseek-chat/)
- Perplexity - Perplexity AI via web interface (https://www.perplexity.ai/)
- Grok - Grok (X.com) via web interface (https://grok.com/)
⚠️ Important: This project maintains twopackage.jsonfiles:
./package.json- For npm package installation./src/textgenhub/package.json- For Python package dependenciesWhen modifying Node.js dependencies or version numbers, please ensure to update both files to keep them synchronized.
# Using pip
pip install textgenhub
# Using poetry
poetry add textgenhub# Using npm
npm install textgenhub
# Using yarn
yarn add textgenhubAll providers now support a unified ask() interface for consistency:
from textgenhub import chatgpt, deepseek, perplexity
# Unified interface - all providers support ask()
# By default, prompts are pasted instantly (typing_speed=None)
response = chatgpt.ask("What is Python?", headless=True)
response = deepseek.ask("What is Python?", headless=True)
response = perplexity.ask("What is Python?", headless=True)
# For character-by-character typing, set typing_speed (in seconds per character)
response = chatgpt.ask("What is Python?", typing_speed=0.05)from textgenhub import chatgpt
# Use the unified ask() interface
response = chatgpt.ask("What day is it today?", headless=True)
print(response)from textgenhub import deepseek
# Use the unified ask() interface
response = deepseek.ask("What day is it today?", headless=True)
print(response)from textgenhub import perplexity
# Use the unified ask() interface
response = perplexity.ask("What day is it today?", headless=True)
print(response)const { ChatGPT } = require('textgenhub');
// Create a ChatGPT instance
const chatgpt = new ChatGPT();
// Use it in your code
chatgpt.chat("What day is it today?", { headless: true })
.then(response => console.log(response));const { DeepSeek } = require('textgenhub');
// Create a DeepSeek instance
const deepseek = new DeepSeek();
// Use it in your code
deepseek.chat("What day is it today?", { headless: true })
.then(response => console.log(response));const { Perplexity } = require('textgenhub');
// Create a Perplexity instance
const perplexity = new Perplexity();
// Use it in your code
perplexity.chat("What day is it today?", { headless: true })
.then(response => console.log(response));TextGenHub now provides a unified CLI interface for all providers:
# Install and use the unified CLI
poetry install
poetry run textgenhub --help
# ChatGPT
poetry run textgenhub chatgpt --prompt "What day is it today?"
# DeepSeek (headless browser method)
poetry run textgenhub deepseek --prompt "What day is it today?"
# Perplexity (headless browser method)
poetry run textgenhub perplexity --prompt "What day is it today?"
# Grok (headless browser method)
poetry run textgenhub grok --prompt "What day is it today?"--prompt: The text prompt to send to the LLM (required for most providers)--headless: Run browser in headless mode (default: true)--output-format: Output format -json(default),html, orraw(ChatGPT: json/html/raw; others: json/html)--timeout: Timeout in seconds for extension mode (ChatGPT only, default: 120)--typing-speed: Typing speed in seconds per character (default: None for instant paste, > 0 for character-by-character typing)--session: Explicit session index to use (ChatGPT only, seesessions listcommand)--close: Close browser session after completion (ChatGPT only, default: keep open)
# List all available ChatGPT sessions
poetry run textgenhub sessions list
# Show the path to the central sessions.json file
poetry run textgenhub sessions path
# Create a new ChatGPT session with auto-assigned index (opens browser for login)
poetry run textgenhub sessions init
# Create or regenerate a specific session index (opens browser for login)
poetry run textgenhub sessions init --index 0
poetry run textgenhub sessions init --index 2
# Get help on available session commands
poetry run textgenhub sessions --help
poetry run textgenhub sessions init --helpThe ChatGPT provider supports browser profile isolation with intelligent session management. Sessions maintain conversation continuity and can be explicitly targeted with --session INDEX.
If you lose your sessions, move to a new device, or need to recreate your environment, follow these steps to rebuild your session library:
-
(Optional) Clear existing corrupted sessions: If your sessions are in a bad state, you can start fresh by removing the central sessions file:
# On Windows (PowerShell) powershell -Command "Remove-Item (poetry run textgenhub sessions path)" # On Linux/macOS rm $(poetry run textgenhub sessions path)
-
Re-initialize specific sessions: Run the
initcommand for each session index you wish to restore. This will open a browser window for you to log in:# Initialize session 0 (the default session) poetry run textgenhub sessions init --index 0 # Initialize additional sessions if needed poetry run textgenhub sessions init --index 1 poetry run textgenhub sessions init --index 2
-
Verify the rebuild:
poetry run textgenhub sessions list
Session Storage Policy: sessions.json is stored centrally on your system to ensure consistency across all projects using textgenhub: %LOCALAPPDATA%\textgenhub\sessions.json.
This central location prevents the need to copy sessions.json between projects or virtual environments. If a local sessions.json exists in your project directory, it will be automatically migrated to the central location on first use.
# ChatGPT - JSON output (default)
poetry run textgenhub chatgpt --prompt "Explain quantum computing"
# ChatGPT with session-based provider - HTML output
poetry run textgenhub chatgpt --prompt "Explain quantum computing" --output-format html
# ChatGPT with session-based provider - Raw text output
poetry run textgenhub chatgpt --prompt "Explain quantum computing" --output-format raw
# ChatGPT with character-by-character typing (0.05 seconds per character)
poetry run textgenhub chatgpt --prompt "Explain quantum computing" --typing-speed 0.05
# ChatGPT using specific session (session index 1)
poetry run textgenhub chatgpt --prompt "Explain quantum computing" --session 1
# Regenerate session 0 if it's broken
poetry run textgenhub sessions init --index 0
# ChatGPT with automatic closing after receiving the response
poetry run textgenhub chatgpt --prompt "Explain quantum computing" --close
# Closing doesn't necessarily need a prompt, we can close a specific session as well
poetry run textgenhub chatgpt --close --session 0
# DeepSeek - JSON output
poetry run textgenhub deepseek --prompt "What is machine learning?"
# Perplexity - JSON output
poetry run textgenhub perplexity --prompt "What is the capital of France?"
# Grok - JSON output
poetry run textgenhub grok --prompt "Tell me a joke"When using --output-format json (default), the CLI returns structured JSON:
{
"provider": "chatgpt",
"method": "headless",
"timestamp": "2025-11-13T20:14:44.465890",
"prompt": "What is 2 + 2?",
"response": "2 + 2 equals 4.",
"html": ""
}When using --output-format html, the CLI returns raw HTML content directly, perfect for downstream processing:
# Get HTML content for further processing
HTML_CONTENT=$(poetry run textgenhub chatgpt --prompt "Generate a report" --output-format html)When using --output-format raw (ChatGPT session-based provider only), the CLI returns plain text content without any formatting or metadata:
# Get plain text response only
poetry run textgenhub chatgpt --prompt "Summarize the Ukraine crisis" --output-format raw