Files
docker-compose/ai/README-export.md

125 lines
3.2 KiB
Markdown
Raw Normal View History

# 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
```bash
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`
```bash
# 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
```bash
# 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)
```bash
# 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:
```bash
# 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:
```bash
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
1. **Find chat IDs**: Look at the URL bar when viewing a conversation
2. **Regular exports**: Run `--all` periodically to backup your code
3. **Integration**: Add to cron job for automatic backups
4. **Local testing**: Run locally first with `--base-url http://localhost:8080`
## Example Workflow
```bash
# 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:
```bash
# 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
```