2026-03-09 21:42:17 +08:00
# 📦 Async Context Compression — Local Deployment Tools
## 🎯 Feature Overview
Added a complete local deployment toolchain for the `async_context_compression` Filter plugin, supporting fast iterative development without restarting OpenWebUI.
## 📋 New Files
### 1. **deploy_filter.py** — Filter Plugin Deployment Script
2026-03-11 23:32:00 +08:00
2026-03-09 21:42:17 +08:00
- **Location**: `scripts/deploy_filter.py`
- **Function**: Auto-deploy Filter-type plugins to local OpenWebUI instance
- **Features**:
- ✅ Auto-extract metadata from Python docstring
- ✅ Smart semantic version recognition
- ✅ Support multiple Filter plugin management
- ✅ Auto-update or create plugins
- ✅ Detailed error diagnostics and connection testing
- ✅ List command to view all available Filters
- **Code Lines**: ~300
### 2. **DEPLOYMENT_GUIDE.md** — Complete Deployment Guide
2026-03-11 23:32:00 +08:00
2026-03-09 21:42:17 +08:00
- **Location**: `scripts/DEPLOYMENT_GUIDE.md`
- **Contents**:
- Prerequisites and quick start
- Detailed script documentation
- API key retrieval method
- Troubleshooting guide
- Step-by-step workflow examples
### 3. **QUICK_START.md** — Quick Reference Card
2026-03-11 23:32:00 +08:00
2026-03-09 21:42:17 +08:00
- **Location**: `scripts/QUICK_START.md`
- **Contents**:
- One-line deployment command
- Setup steps
- Common commands table
- Troubleshooting quick-reference table
- CI/CD integration examples
### 4. **test_deploy_filter.py** — Unit Test Suite
2026-03-11 23:32:00 +08:00
2026-03-09 21:42:17 +08:00
- **Location**: `tests/scripts/test_deploy_filter.py`
- **Test Coverage**:
- ✅ Filter file discovery (3 tests)
- ✅ Metadata extraction (3 tests)
- ✅ API payload building (4 tests)
- **Pass Rate**: 10/10 ✅
## 🚀 Usage
### Basic Deploy (One-liner)
2026-03-09 20:31:25 +08:00
```bash
cd scripts
python deploy_filter.py
```
2026-03-09 21:42:17 +08:00
### List All Available Filters
2026-03-09 20:31:25 +08:00
```bash
python deploy_filter.py --list
```
2026-03-09 21:42:17 +08:00
### Deploy Specific Filter
2026-03-09 20:31:25 +08:00
```bash
python deploy_filter.py folder-memory
python deploy_filter.py context_enhancement_filter
```
2026-03-09 21:42:17 +08:00
## 🔧 How It Works
2026-03-09 20:31:25 +08:00
```
┌─────────────────────────────────────────────────────────────┐
2026-03-09 21:42:17 +08:00
│ 1. Load API key (.env) │
2026-03-09 20:31:25 +08:00
└──────────────────┬──────────────────────────────────────────┘
│
┌──────────────────▼──────────────────────────────────────────┐
2026-03-09 21:42:17 +08:00
│ 2. Find Filter plugin file │
│ - Infer file path from name │
│ - Support hyphen-case and snake_case lookup │
2026-03-09 20:31:25 +08:00
└──────────────────┬──────────────────────────────────────────┘
│
┌──────────────────▼──────────────────────────────────────────┐
2026-03-09 21:42:17 +08:00
│ 3. Read Python source code │
│ - Extract docstring metadata │
2026-03-09 20:31:25 +08:00
│ - title, version, author, description, openwebui_id │
└──────────────────┬──────────────────────────────────────────┘
│
┌──────────────────▼──────────────────────────────────────────┐
2026-03-09 21:42:17 +08:00
│ 4. Build API request payload │
│ - Assemble manifest and meta info │
│ - Include complete source code content │
2026-03-09 20:31:25 +08:00
└──────────────────┬──────────────────────────────────────────┘
│
┌──────────────────▼──────────────────────────────────────────┐
2026-03-09 21:42:17 +08:00
│ 5. Send request │
│ - POST /api/v1/functions/id/{id}/update (update) │
│ - POST /api/v1/functions/create (create fallback) │
2026-03-09 20:31:25 +08:00
└──────────────────┬──────────────────────────────────────────┘
│
┌──────────────────▼──────────────────────────────────────────┐
2026-03-09 21:42:17 +08:00
│ 6. Display results and diagnostics │
│ - ✅ Update/create success │
│ - ❌ Error messages and solutions │
2026-03-09 20:31:25 +08:00
└─────────────────────────────────────────────────────────────┘
```
2026-03-09 21:42:17 +08:00
## 📊 Supported Filters List
2026-03-09 20:31:25 +08:00
2026-03-09 21:42:17 +08:00
Script auto-discovers the following Filters:
2026-03-09 20:31:25 +08:00
2026-03-09 21:42:17 +08:00
| Filter Name | Python File | Version |
2026-03-09 20:31:25 +08:00
|-----------|-----------|------|
| async-context-compression | async_context_compression.py | 1.3.0+ |
| chat-session-mapping-filter | chat_session_mapping_filter.py | 0.1.0+ |
| context_enhancement_filter | context_enhancement_filter.py | 0.3+ |
| folder-memory | folder_memory.py | 0.1.0+ |
| github_copilot_sdk_files_filter | github_copilot_sdk_files_filter.py | 0.1.3+ |
| markdown_normalizer | markdown_normalizer.py | 1.2.8+ |
| web_gemini_multimodel_filter | web_gemini_multimodel_filter.py | 0.3.2+ |
2026-03-09 21:42:17 +08:00
## ⚙️ Technical Details
2026-03-09 20:31:25 +08:00
2026-03-09 21:42:17 +08:00
### Metadata Extraction
2026-03-09 20:31:25 +08:00
2026-03-09 21:42:17 +08:00
Script extracts metadata from the docstring at the top of Python file:
2026-03-09 20:31:25 +08:00
```python
"""
title: Async Context Compression
id: async_context_compression
author: Fu-Jie
author_url: https://github.com/Fu-Jie/openwebui-extensions
funding_url: https://github.com/open-webui
description: Reduces token consumption...
version: 1.3.0
openwebui_id: b1655bc8-6de9-4cad-8cb5-a6f7829a02ce
"""
```
2026-03-09 21:42:17 +08:00
**Supported Metadata Fields**:
2026-03-11 23:32:00 +08:00
2026-03-09 21:42:17 +08:00
- `title` — Filter display name ✅
- `id` — Unique identifier ✅
- `author` — Author name ✅
- `author_url` — Author homepage ✅
- `funding_url` — Project link ✅
- `description` — Feature description ✅
- `version` — Semantic version number ✅
- `openwebui_id` — OpenWebUI UUID (optional)
2026-03-09 20:31:25 +08:00
2026-03-09 21:42:17 +08:00
### API Integration
2026-03-09 20:31:25 +08:00
2026-03-09 21:42:17 +08:00
Script uses OpenWebUI REST API:
2026-03-09 20:31:25 +08:00
```
POST /api/v1/functions/id/{filter_id}/update
2026-03-09 21:42:17 +08:00
- Update existing Filter
- HTTP 200: Update success
- HTTP 404: Filter not found, auto-attempt create
2026-03-09 20:31:25 +08:00
POST /api/v1/functions/create
2026-03-09 21:42:17 +08:00
- Create new Filter
- HTTP 200: Creation success
2026-03-09 20:31:25 +08:00
```
2026-03-09 21:42:17 +08:00
**Authentication**: Bearer token (API key method)
2026-03-09 20:31:25 +08:00
2026-03-09 21:42:17 +08:00
## 🔐 Security
2026-03-09 20:31:25 +08:00
2026-03-09 21:42:17 +08:00
### API Key Management
2026-03-09 20:31:25 +08:00
```bash
2026-03-09 21:42:17 +08:00
# 1. Create .env file
2026-03-09 20:31:25 +08:00
echo "api_key=sk-your-key-here" > scripts/.env
2026-03-09 21:42:17 +08:00
# 2. Add .env to .gitignore
2026-03-09 20:31:25 +08:00
echo "scripts/.env" >> .gitignore
2026-03-09 21:42:17 +08:00
# 3. Don't commit API key
2026-03-09 20:31:25 +08:00
git add scripts/.gitignore
git commit -m "chore: add .env to gitignore"
```
2026-03-09 21:42:17 +08:00
### Best Practices
2026-03-09 20:31:25 +08:00
2026-03-09 21:42:17 +08:00
- ✅ Use long-term auth tokens (not short-term JWT)
- ✅ Rotate API keys periodically
- ✅ Limit key permission scope
- ✅ Use only on trusted networks
- ✅ Use CI/CD secret management in production
2026-03-09 20:31:25 +08:00
2026-03-09 21:42:17 +08:00
## 🧪 Test Verification
2026-03-09 20:31:25 +08:00
2026-03-09 21:42:17 +08:00
### Run Test Suite
2026-03-09 20:31:25 +08:00
```bash
pytest tests/scripts/test_deploy_filter.py -v
```
2026-03-09 21:42:17 +08:00
### Test Coverage
2026-03-09 20:31:25 +08:00
```
2026-03-09 21:42:17 +08:00
✅ TestFilterDiscovery (3 tests)
2026-03-09 20:31:25 +08:00
- test_find_async_context_compression
- test_find_nonexistent_filter
- test_find_filter_with_underscores
2026-03-09 21:42:17 +08:00
✅ TestMetadataExtraction (3 tests)
2026-03-09 20:31:25 +08:00
- test_extract_metadata_from_async_compression
- test_extract_metadata_empty_file
- test_extract_metadata_multiline_docstring
2026-03-09 21:42:17 +08:00
✅ TestPayloadBuilding (4 tests)
2026-03-09 20:31:25 +08:00
- test_build_filter_payload_basic
- test_payload_has_required_fields
- test_payload_with_openwebui_id
2026-03-09 21:42:17 +08:00
✅ TestVersionExtraction (1 test)
2026-03-09 20:31:25 +08:00
- test_extract_valid_version
2026-03-09 21:42:17 +08:00
Result: 10/10 PASSED ✅
2026-03-09 20:31:25 +08:00
```
2026-03-09 21:42:17 +08:00
## 💡 Common Use Cases
2026-03-09 20:31:25 +08:00
2026-03-09 21:42:17 +08:00
### Use Case 1: Quick Test After Bug Fix
2026-03-09 20:31:25 +08:00
```bash
2026-03-09 21:42:17 +08:00
# 1. Modify code
2026-03-09 20:31:25 +08:00
vim plugins/filters/async-context-compression/async_context_compression.py
2026-03-09 21:42:17 +08:00
# 2. Deploy immediately (no OpenWebUI restart needed)
2026-03-09 20:31:25 +08:00
cd scripts && python deploy_filter.py
2026-03-09 21:42:17 +08:00
# 3. Test fix in OpenWebUI
# 4. Iterate (return to step 1)
2026-03-09 20:31:25 +08:00
```
2026-03-09 21:42:17 +08:00
### Use Case 2: Develop New Filter
2026-03-09 20:31:25 +08:00
```bash
2026-03-09 21:42:17 +08:00
# 1. Create new Filter directory
2026-03-09 20:31:25 +08:00
mkdir plugins/filters/my-new-filter
2026-03-09 21:42:17 +08:00
# 2. Write code (include required docstring metadata)
2026-03-09 20:31:25 +08:00
cat > plugins/filters/my-new-filter/my_new_filter.py << 'EOF'
"""
title: My New Filter
author: Your Name
version: 1.0.0
description: Filter description
"""
class Filter:
# ... implementation ...
EOF
2026-03-09 21:42:17 +08:00
# 3. First deployment (create)
2026-03-09 20:31:25 +08:00
cd scripts && python deploy_filter.py my-new-filter
2026-03-09 21:42:17 +08:00
# 4. Test in OpenWebUI UI
# 5. Repeat updates
2026-03-09 20:31:25 +08:00
cd scripts && python deploy_filter.py my-new-filter
```
2026-03-09 21:42:17 +08:00
### Use Case 3: Version Update and Release
2026-03-09 20:31:25 +08:00
```bash
2026-03-09 21:42:17 +08:00
# 1. Update version number
2026-03-09 20:31:25 +08:00
vim plugins/filters/async-context-compression/async_context_compression.py
2026-03-09 21:42:17 +08:00
# Change: version: 1.3.0 → version: 1.4.0
2026-03-09 20:31:25 +08:00
2026-03-09 21:42:17 +08:00
# 2. Deploy new version
2026-03-09 20:31:25 +08:00
cd scripts && python deploy_filter.py
2026-03-09 21:42:17 +08:00
# 3. After testing, commit
2026-03-09 20:31:25 +08:00
git add plugins/filters/async-context-compression/
git commit -m "feat(filters): update async-context-compression to 1.4.0"
git push
```
2026-03-09 21:42:17 +08:00
## 🔄 CI/CD Integration
2026-03-09 20:31:25 +08:00
2026-03-09 21:42:17 +08:00
### GitHub Actions Example
2026-03-09 20:31:25 +08:00
```yaml
name: Deploy Filter on Release
on:
release:
types: [published]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Deploy Filter
run: |
cd scripts
python deploy_filter.py async-context-compression
env:
api_key: ${{ secrets.OPENWEBUI_API_KEY }}
```
2026-03-09 21:42:17 +08:00
## 📚 Reference Documentation
2026-03-09 20:31:25 +08:00
2026-03-09 21:42:17 +08:00
- [Complete Deployment Guide ](DEPLOYMENT_GUIDE.md )
- [Quick Reference Card ](QUICK_START.md )
- [Test Suite ](../tests/scripts/test_deploy_filter.py )
- [Plugin Development Guide ](../docs/development/plugin-guide.md )
- [OpenWebUI Documentation ](https://docs.openwebui.com/ )
2026-03-09 20:31:25 +08:00
2026-03-09 21:42:17 +08:00
## 🎓 Learning Resources
2026-03-09 20:31:25 +08:00
2026-03-09 21:42:17 +08:00
### Architecture Understanding
2026-03-09 20:31:25 +08:00
```
2026-03-09 21:42:17 +08:00
OpenWebUI System Design
2026-03-09 20:31:25 +08:00
↓
2026-03-09 21:42:17 +08:00
Filter Plugin Type Definition
2026-03-09 20:31:25 +08:00
↓
2026-03-09 21:42:17 +08:00
REST API Interface (/api/v1/functions)
2026-03-09 20:31:25 +08:00
↓
2026-03-09 21:42:17 +08:00
Local Deployment Script Implementation (deploy_filter.py)
2026-03-09 20:31:25 +08:00
↓
2026-03-09 21:42:17 +08:00
Metadata Extraction and Delivery
2026-03-09 20:31:25 +08:00
```
2026-03-09 21:42:17 +08:00
### Debugging Tips
2026-03-09 20:31:25 +08:00
2026-03-09 21:42:17 +08:00
1. **Enable Verbose Logging ** :
2026-03-11 23:32:00 +08:00
2026-03-09 20:31:25 +08:00
```bash
python deploy_filter.py 2>&1 | tee deploy.log
```
2026-03-09 21:42:17 +08:00
2. **Test API Connection ** :
2026-03-11 23:32:00 +08:00
2026-03-09 20:31:25 +08:00
```bash
2026-03-09 21:42:17 +08:00
curl -X GET http://localhost:3000/api/v1/functions \
2026-03-09 20:31:25 +08:00
-H "Authorization: Bearer $API_KEY"
```
2026-03-09 21:42:17 +08:00
3. **Verify .env File ** :
2026-03-11 23:32:00 +08:00
2026-03-09 20:31:25 +08:00
```bash
grep "api_key=" scripts/.env
```
2026-03-09 21:42:17 +08:00
## 📞 Troubleshooting
2026-03-09 20:31:25 +08:00
2026-03-09 21:42:17 +08:00
| Issue | Diagnosis | Solution |
|-------|-----------|----------|
| Connection error | Wrong OpenWebUI address/port | Check localhost:3000; modify URL if needed |
| .env not found | Config file not created | `echo "api_key=sk-..." > scripts/.env` |
| Filter not found | Wrong Plugin name | Run `python deploy_filter.py --list` |
| Status 401 | Invalid/expired API key | Update key in `.env` |
| Status 500 | Server error | Check OpenWebUI service logs |
2026-03-09 20:31:25 +08:00
2026-03-09 21:42:17 +08:00
## ✨ Highlight Features
2026-03-09 20:31:25 +08:00
2026-03-09 21:42:17 +08:00
| Feature | Description |
|---------|-------------|
| 🔍 Auto Discovery | Automatically find all Filter plugins |
| 📊 Metadata Extraction | Auto-extract version and metadata from code |
| ♻️ Auto-update | Smart handling of update or create |
| 🛡️ Error Handling | Detailed error messages and diagnostics |
| 🚀 Fast Iteration | Second-level deployment, no restart |
| 🧪 Complete Testing | 10 unit tests covering core functions |
2026-03-09 20:31:25 +08:00
---
2026-03-09 21:42:17 +08:00
**Last Updated**: 2026-03-09
**Author**: Fu-Jie
**Project**: [openwebui-extensions ](https://github.com/Fu-Jie/openwebui-extensions )