Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions .cnb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,47 @@ main:
stages:
- name: download models
script: |
set -e
mkdir -p models-enzh/enzh
base_url="https://github.com/mozilla/firefox-translations-models/raw/refs/heads/main/models/base/enzh"
models_json_url="https://storage.googleapis.com/moz-fx-translations-data--303e-prod-translations-data/db/models.json"
echo "Fetching models.json from $models_json_url"
curl -fsSL "$models_json_url" -o models.json || { echo "Failed to download models.json"; exit 1; }
base_url=$(jq -r '.baseUrl' models.json)
if [ -z "$base_url" ] || [ "$base_url" = "null" ]; then
echo "Failed to extract baseUrl from models.json"
Comment thread
Aalivexy marked this conversation as resolved.
exit 1
fi
echo "Base URL: $base_url"
# Get the first en-zh model (architecture: base)
model_data=$(jq -r '.models."en-zh"[0]' models.json)
if [ -z "$model_data" ] || [ "$model_data" = "null" ]; then
echo "No en-zh model found in models.json"
Comment on lines +20 to +23

Copilot AI Jan 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Selecting the en-zh model via .models."en-zh"[0] is order-dependent, but the manifest contains multiple en-zh entries (e.g., different architectures/release statuses). Filter explicitly (e.g., by architecture == "base" and/or releaseStatus) so the pipeline consistently downloads the intended model even if the array order changes.

Suggested change
# Get the first en-zh model (architecture: base)
model_data=$(jq -r '.models."en-zh"[0]' models.json)
if [ -z "$model_data" ] || [ "$model_data" = "null" ]; then
echo "No en-zh model found in models.json"
# Select the en-zh model with architecture "base" and releaseStatus "released"
model_data=$(jq -r '.models["en-zh"] | map(select(.architecture == "base" and .releaseStatus == "released")) | .[0]' models.json)
if [ -z "$model_data" ] || [ "$model_data" = "null" ]; then
echo "No matching en-zh model (architecture=base, releaseStatus=released) found in models.json"

Copilot uses AI. Check for mistakes.
exit 1
fi
# Extract file paths
lex_path=$(echo "$model_data" | jq -r '.files.lexicalShortlist.path')
model_path=$(echo "$model_data" | jq -r '.files.model.path')
src_vocab_path=$(echo "$model_data" | jq -r '.files.srcVocab.path')
trg_vocab_path=$(echo "$model_data" | jq -r '.files.trgVocab.path')
Comment on lines +27 to +30

Copilot AI Jan 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

echo "$model_data" | jq ... can be unsafe because echo behavior is shell-dependent (it may interpret backslashes or -n/-e sequences), which can corrupt JSON before it reaches jq. Prefer extracting fields directly with jq from models.json (or use printf '%s' "$model_data").

Suggested change
lex_path=$(echo "$model_data" | jq -r '.files.lexicalShortlist.path')
model_path=$(echo "$model_data" | jq -r '.files.model.path')
src_vocab_path=$(echo "$model_data" | jq -r '.files.srcVocab.path')
trg_vocab_path=$(echo "$model_data" | jq -r '.files.trgVocab.path')
lex_path=$(printf '%s' "$model_data" | jq -r '.files.lexicalShortlist.path')
model_path=$(printf '%s' "$model_data" | jq -r '.files.model.path')
src_vocab_path=$(printf '%s' "$model_data" | jq -r '.files.srcVocab.path')
trg_vocab_path=$(printf '%s' "$model_data" | jq -r '.files.trgVocab.path')

Copilot uses AI. Check for mistakes.
files=(
"lex.50.50.enzh.s2t.bin.gz"
"model.enzh.intgemm.alphas.bin.gz"
"srcvocab.enzh.spm.gz"
"trgvocab.enzh.spm.gz"
"$lex_path"
"$model_path"
"$src_vocab_path"
"$trg_vocab_path"
)
for file in "${files[@]}"; do
echo "Downloading $file"
curl -sL "$base_url/$file" -o "models-enzh/enzh/$file"
for file_path in "${files[@]}"; do
if [ -z "$file_path" ] || [ "$file_path" = "null" ]; then
echo "Invalid file path in model data"
exit 1
fi
file=$(basename "$file_path")
echo "Downloading $file from $base_url/$file_path"
curl -fsSL "$base_url/$file_path" -o "models-enzh/enzh/$file" || { echo "Failed to download $file"; exit 1; }
gunzip -f "models-enzh/enzh/$file"
extracted_file="${file%.gz}"
echo "$extracted_file downloaded and extracted"
done
rm -f models.json
echo "Download completed. Model structure:"
pwd
ls -R models-enzh
Expand Down