{"id":33376334,"url":"https://github.com/star-173/llmsession","last_synced_at":"2025-11-23T00:02:36.178Z","repository":{"id":325658396,"uuid":"1101960760","full_name":"STAR-173/LLMSession","owner":"STAR-173","description":"    A zero-config tool to automate web-based LLMs (ChatGPT). Handles authentication, session persistence (cookies), and chained prompts across Python and Node.js.","archived":false,"fork":false,"pushed_at":"2025-11-22T15:21:58.000Z","size":30,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-22T17:18:37.175Z","etag":null,"topics":["ai-wrapper","automation","bot","browser-automation","chatgpt","cookies","llm","nodejs","playwright","python","session-management","web-scraping"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/STAR-173.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-22T15:04:29.000Z","updated_at":"2025-11-22T15:22:01.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/STAR-173/LLMSession","commit_stats":null,"previous_names":["star-173/llmsession"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/STAR-173/LLMSession","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STAR-173%2FLLMSession","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STAR-173%2FLLMSession/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STAR-173%2FLLMSession/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STAR-173%2FLLMSession/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/STAR-173","download_url":"https://codeload.github.com/STAR-173/LLMSession/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STAR-173%2FLLMSession/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":285879574,"owners_count":27247109,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-22T02:00:05.934Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-wrapper","automation","bot","browser-automation","chatgpt","cookies","llm","nodejs","playwright","python","session-management","web-scraping"],"created_at":"2025-11-23T00:01:00.070Z","updated_at":"2025-11-23T00:02:36.165Z","avatar_url":"https://github.com/STAR-173.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LLMSession\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)\n[![PyPI version](https://badge.fury.io/py/llm-session.svg)](https://pypi.org/project/llm-session/)\n[![npm version](https://badge.fury.io/js/llm-session.svg)](https://www.npmjs.com/package/llm-session)\n\nA zero-configuration tool to automate interactions with web-based LLM providers (currently ChatGPT). It handles authentication, session persistence, and chained prompt execution programmatically.\n\n## Features\n- **Zero-Config Setup**: Automatically handles browser binaries via Playwright.\n- **Session Persistence**: Reuses cookies/storage for subsequent runs (no need to login every time).\n- **Cross-Language Sharing**: Sessions are shared between Python and Node.js environments automatically.\n- **Smart OTP Handling**: Supports non-blocking callbacks for 2FA/OTP challenges.\n- **Resilient**: Allows custom CSS selectors to adapt to UI changes without updating the library.\n\n## Prerequisites\nYou must set the following environment variables, or pass them directly to the constructor:\n- `CHATGPT_EMAIL`\n- `CHATGPT_PASSWORD`\n- `CHATGPT_GOOGLE_LOGIN` (Optional: set to \"true\" if using Google Auth. *Note: Google Auth is experimental and may require manual intervention.*)\n\n## Disclaimer\n\u003e [!WARNING]\n\u003e **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.\n\nThis 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.\n\n---\n\n## Python Usage\n\n### Installation\n```bash\npip install llm-session\n```\n\n### Quick Start\n```python\nimport logging\nfrom llm_session import Automator\n\n# 1. Configure Standard Logging\nlogging.basicConfig(level=logging.INFO)\n\n# 2. Define OTP Callback (Optional, but recommended for headless envs)\ndef my_otp_handler():\n    # In production, you might fetch this from an email API\n    return input(\"Enter OTP Code sent to email: \")\n\n# 3. Initialize\nbot = Automator(\n    provider=\"chatgpt\",\n    headless=False,  # Set to True for production (CURRENTLY ONLY WORKS WITH headless=False)\n    credentials={\n        \"email\": \"your_email@example.com\", \n        \"password\": \"your_password\",\n        \"method\": \"email\" # or \"google\"\n    },\n    on_otp_required=my_otp_handler\n)\n\n# 4. Single Prompt\nprint(bot.process_prompt(\"Hello, world!\"))\n\n# 5. Chained Prompt (Inject previous response)\nchain = [\n    \"Write a haiku about Python.\",\n    \"Translate this haiku to Spanish: {{previous}}\"\n]\nresponses = bot.process_chain(chain)\nprint(responses)\n\nbot.close()\n```\n\n---\n\n## Node.js Usage\n\n### Installation\n```bash\nnpm install llm-session\n```\n\n### Quick Start\n```typescript\nimport { Automator } from 'llm-session';\n\nasync function main() {\n    // 1. Define OTP Callback\n    const onOtpRequired = async () =\u003e {\n        console.log(\"Please check your email for code.\");\n        // Return code from your logic here\n        return \"123456\"; \n    };\n\n    // 2. Initialize\n    const bot = new Automator(\n        \"chatgpt\", \n        false, // headless\n        {\n            email: \"your_email@example.com\",\n            password: \"your_password\"\n        },\n        undefined, // sessionPath (optional)\n        {\n            onOtpRequired: onOtpRequired,\n            // Optional: Inject your own logger (e.g., Winston, Pino)\n            // logger: myLoggerInstance \n        }\n    );\n    \n    try {\n        await bot.init();\n\n        const response = await bot.processPrompt(\"Hello from Node.js!\");\n        console.log(response);\n\n    } finally {\n        await bot.close();\n    }\n}\nmain();\n```\n\n---\n\n## Advanced Configuration (Resilience)\n\nWebsites 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.\n\n**Python:**\n```python\nbot = Automator(\n    provider=\"chatgpt\", \n    config={\n        \"selectors\": {\n            \"textarea\": \"#new-prompt-id\",\n            \"send_btn\": \".new-send-button-class\",\n            \"assistant_msg\": \".new-message-wrapper\"\n        }\n    }\n)\n```\n\n**Node.js:**\n```typescript\nconst bot = new Automator(\"chatgpt\", true, undefined, undefined, {\n    selectors: {\n        textarea: \"#new-prompt-id\",\n        send_btn: \".new-send-button-class\"\n    }\n});\n```\n\n## Session Management\nThis 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).\n\n*   **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).\n*   **Persistence:** Sessions persist across reboots.\n\n## Contributing\nWe welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on how to build the project locally.\n\n## License\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstar-173%2Fllmsession","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstar-173%2Fllmsession","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstar-173%2Fllmsession/lists"}