feat: reliable multi-source model delivery system
- Implements automatic fallback chain: CDN → GitHub → Hugging Face - Adds Soulcraft CDN as primary model source (models.soulcraft.com) - GitHub release tar.gz extraction as reliable backup - Zero configuration required - fully automatic - Guarantees same model (all-MiniLM-L6-v2) across all sources - 384-dimensional embeddings for data compatibility - Local caching after first download - Production-ready with multiple redundancy layers BREAKING CHANGE: Removed tar-stream dependency, now uses native tar command
This commit is contained in:
parent
7e243b6f2b
commit
39f8b96464
3 changed files with 265 additions and 98 deletions
60
scripts/create-models-release.sh
Executable file
60
scripts/create-models-release.sh
Executable file
|
|
@ -0,0 +1,60 @@
|
|||
#!/bin/bash
|
||||
# Create GitHub release with unarchived model files for direct serving
|
||||
# This allows transformers.js to download individual files directly
|
||||
|
||||
set -e
|
||||
|
||||
echo "🚀 Creating GitHub release with unarchived model files..."
|
||||
|
||||
# Create temporary directory
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
cd "$TEMP_DIR"
|
||||
|
||||
echo "📥 Downloading existing model archive..."
|
||||
curl -sL https://github.com/soulcraftlabs/brainy/releases/download/models-v1/all-MiniLM-L6-v2.tar.gz -o models.tar.gz
|
||||
|
||||
echo "📦 Extracting models..."
|
||||
tar -xzf models.tar.gz
|
||||
|
||||
echo "🔧 Preparing individual model files for release..."
|
||||
|
||||
# Create properly structured directory
|
||||
mkdir -p release-files/Xenova/all-MiniLM-L6-v2/onnx
|
||||
|
||||
# Copy files with correct naming for direct serving
|
||||
cp all-MiniLM-L6-v2/config.json release-files/Xenova/all-MiniLM-L6-v2/
|
||||
cp all-MiniLM-L6-v2/tokenizer.json release-files/Xenova/all-MiniLM-L6-v2/
|
||||
cp all-MiniLM-L6-v2/tokenizer_config.json release-files/Xenova/all-MiniLM-L6-v2/
|
||||
cp all-MiniLM-L6-v2/onnx/model.onnx release-files/Xenova/all-MiniLM-L6-v2/onnx/
|
||||
|
||||
# Also keep the tar.gz for backward compatibility
|
||||
cp models.tar.gz release-files/
|
||||
|
||||
echo "📋 Files to upload:"
|
||||
find release-files -type f -exec ls -lh {} \;
|
||||
|
||||
echo ""
|
||||
echo "✅ Files ready for release!"
|
||||
echo ""
|
||||
echo "To create the release with individual files:"
|
||||
echo ""
|
||||
echo "1. Go to: https://github.com/soulcraftlabs/brainy/releases/new"
|
||||
echo "2. Tag: models-v2"
|
||||
echo "3. Title: Model Files v2 - Unarchived"
|
||||
echo "4. Upload these files from $TEMP_DIR/release-files/:"
|
||||
echo " - Xenova/all-MiniLM-L6-v2/config.json"
|
||||
echo " - Xenova/all-MiniLM-L6-v2/tokenizer.json"
|
||||
echo " - Xenova/all-MiniLM-L6-v2/tokenizer_config.json"
|
||||
echo " - Xenova/all-MiniLM-L6-v2/onnx/model.onnx"
|
||||
echo " - all-MiniLM-L6-v2.tar.gz (for compatibility)"
|
||||
echo ""
|
||||
echo "Or use GitHub CLI:"
|
||||
echo " cd $TEMP_DIR/release-files"
|
||||
echo " gh release create models-v2 --repo soulcraftlabs/brainy \\"
|
||||
echo " --title 'Model Files v2 - Direct Serving' \\"
|
||||
echo " --notes 'Unarchived model files for direct HTTP serving' \\"
|
||||
echo " Xenova/all-MiniLM-L6-v2/config.json \\"
|
||||
echo " Xenova/all-MiniLM-L6-v2/tokenizer.json \\"
|
||||
echo " Xenova/all-MiniLM-L6-v2/tokenizer_config.json \\"
|
||||
echo " Xenova/all-MiniLM-L6-v2/onnx/model.onnx \\"
|
||||
echo " models.tar.gz"
|
||||
88
scripts/setup-github-models.sh
Normal file
88
scripts/setup-github-models.sh
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
#!/bin/bash
|
||||
# Setup GitHub branch with extracted model files for direct serving
|
||||
# This creates a 'models' branch with uncompressed files that transformers.js can use directly
|
||||
|
||||
set -e
|
||||
|
||||
echo "🚀 Setting up GitHub models branch for reliable model serving..."
|
||||
|
||||
# Create a temporary directory for our work
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
cd "$TEMP_DIR"
|
||||
|
||||
echo "📥 Downloading model tar.gz from release..."
|
||||
curl -sL https://github.com/soulcraftlabs/brainy/releases/download/models-v1/all-MiniLM-L6-v2.tar.gz -o models.tar.gz
|
||||
|
||||
echo "📦 Extracting models..."
|
||||
tar -xzf models.tar.gz
|
||||
|
||||
echo "🔧 Setting up models branch..."
|
||||
git clone https://github.com/soulcraftlabs/brainy.git --depth 1 -b main repo
|
||||
cd repo
|
||||
|
||||
# Create orphan branch for models (no history needed)
|
||||
git checkout --orphan models
|
||||
git rm -rf . 2>/dev/null || true
|
||||
|
||||
# Create the proper directory structure for transformers.js
|
||||
mkdir -p Xenova/all-MiniLM-L6-v2/onnx
|
||||
|
||||
# Copy model files with correct structure
|
||||
cp ../all-MiniLM-L6-v2/config.json Xenova/all-MiniLM-L6-v2/
|
||||
cp ../all-MiniLM-L6-v2/tokenizer.json Xenova/all-MiniLM-L6-v2/
|
||||
cp ../all-MiniLM-L6-v2/tokenizer_config.json Xenova/all-MiniLM-L6-v2/
|
||||
cp ../all-MiniLM-L6-v2/onnx/model.onnx Xenova/all-MiniLM-L6-v2/onnx/
|
||||
cp ../all-MiniLM-L6-v2/onnx/model_quantized.onnx Xenova/all-MiniLM-L6-v2/onnx/ 2>/dev/null || true
|
||||
|
||||
# Add README explaining this branch
|
||||
cat > README.md << 'EOF'
|
||||
# Brainy Model Files
|
||||
|
||||
This branch contains extracted model files for direct serving via raw.githubusercontent.com
|
||||
|
||||
## Structure
|
||||
```
|
||||
Xenova/
|
||||
all-MiniLM-L6-v2/
|
||||
config.json
|
||||
tokenizer.json
|
||||
tokenizer_config.json
|
||||
onnx/
|
||||
model.onnx
|
||||
model_quantized.onnx
|
||||
```
|
||||
|
||||
## Usage
|
||||
These files are automatically loaded by Brainy when models are needed.
|
||||
The URL pattern is:
|
||||
`https://raw.githubusercontent.com/soulcraftlabs/brainy/models/Xenova/all-MiniLM-L6-v2/{file}`
|
||||
|
||||
## DO NOT EDIT
|
||||
This branch is managed automatically. Do not edit files directly.
|
||||
EOF
|
||||
|
||||
# Create .gitattributes for LFS if needed (for large model files)
|
||||
cat > .gitattributes << 'EOF'
|
||||
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||
EOF
|
||||
|
||||
echo "📝 Creating commit..."
|
||||
git add .
|
||||
git commit -m "feat: extracted model files for direct GitHub serving
|
||||
|
||||
- Xenova/all-MiniLM-L6-v2 model files
|
||||
- Proper directory structure for transformers.js
|
||||
- Direct serving via raw.githubusercontent.com"
|
||||
|
||||
echo "✅ Models branch ready!"
|
||||
echo ""
|
||||
echo "To push this branch to GitHub, run:"
|
||||
echo " cd $TEMP_DIR/repo"
|
||||
echo " git push origin models"
|
||||
echo ""
|
||||
echo "Once pushed, models will be available at:"
|
||||
echo " https://raw.githubusercontent.com/soulcraftlabs/brainy/models/Xenova/all-MiniLM-L6-v2/config.json"
|
||||
echo " https://raw.githubusercontent.com/soulcraftlabs/brainy/models/Xenova/all-MiniLM-L6-v2/tokenizer.json"
|
||||
echo " etc..."
|
||||
Loading…
Add table
Add a link
Reference in a new issue