Added Python script to extract and save code blocks from Open WebUI chat conversations to local disk using the REST API. Features: - Export code blocks from specific chats or all chats - Automatic language detection and proper file extensions - Organizes files by chat title with metadata - No Docker modifications needed - Remote access support via SSH tunnel or public URL Usage: python3 ai/webui-export.py --all --output-dir ./exports python3 ai/webui-export.py --chat-id <id> --output-dir ./code This replaces the complex SFTP integration with a simple API-based approach that's easier to maintain and use. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
3.2 KiB
3.2 KiB
Open WebUI Code Export
Simple Python script to export code blocks from Open WebUI chat conversations to your local disk using the REST API.
Features
- Export code blocks from specific chats or all chats
- Automatically detects language and saves with proper file extension
- Organizes files by chat title
- Saves metadata (timestamp, role, language) alongside code
- No Docker modifications needed - uses REST API
Requirements
pip install requests
Usage
Export specific chat
First, get your chat ID from the URL when viewing a chat in Open WebUI:
- URL format:
https://ai.pivoine.art/c/<chat_id> - Example:
https://ai.pivoine.art/c/abc123def456
# Export single chat
python ai/webui-export.py --chat-id abc123def456 --output-dir ./my-code
# Export from remote server
python ai/webui-export.py --base-url https://ai.pivoine.art --chat-id abc123def456 --output-dir ./my-code
Export all chats
# Export all chats
python ai/webui-export.py --all --output-dir ./all-code
# Export from remote server
python ai/webui-export.py --base-url https://ai.pivoine.art --all --output-dir ./all-code
With authentication (if needed)
# If API key authentication is required
python ai/webui-export.py --api-key your-api-key --all --output-dir ./my-code
Output Structure
webui-exports/
├── My Python Project/
│ ├── 000-00.py # First code block from first message
│ ├── 000-00.py.meta.json # Metadata
│ ├── 001-00.py # First code block from second message
│ └── 001-00.py.meta.json
└── Database Schema Design/
├── 000-00.sql
└── 000-00.sql.meta.json
Remote Usage (VPS)
To export code from Open WebUI running on your VPS:
# SSH tunnel to access the API
ssh -L 8080:localhost:8080 root@vps
# In another terminal, export chats
python ai/webui-export.py --all --output-dir ~/Projects/webui-exports
Or directly via the public URL:
python ai/webui-export.py --base-url https://ai.pivoine.art --all --output-dir ~/Projects/webui-exports
Supported Languages
The script automatically detects and saves with proper extensions:
- Python (.py)
- JavaScript/TypeScript (.js/.ts)
- Shell scripts (.sh)
- SQL (.sql)
- HTML/CSS (.html/.css)
- JSON/YAML (.json/.yaml)
- And many more...
Tips
- Find chat IDs: Look at the URL bar when viewing a conversation
- Regular exports: Run
--allperiodically to backup your code - Integration: Add to cron job for automatic backups
- Local testing: Run locally first with
--base-url http://localhost:8080
Example Workflow
# 1. Have a conversation with Claude in Open WebUI where code is generated
# 2. Note the chat ID from URL (or use --all)
# 3. Export the code
python ai/webui-export.py --chat-id abc123 --output-dir ~/Projects/new-feature
# 4. The code is now in ~/Projects/new-feature/Chat Title/000-00.py
# 5. Review, modify, and use as needed
Automation
Add to crontab for daily exports:
# Edit crontab
crontab -e
# Add daily export at 2 AM
0 2 * * * cd ~/Projects/docker-compose && python ai/webui-export.py --base-url https://ai.pivoine.art --all --output-dir ~/Projects/webui-exports