File size: 2,538 Bytes
7b2dfc5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/zsh
set -euo pipefail

script_dir=$(cd "$(dirname "$0")" && pwd)
repo_root=$(cd "$script_dir/../../.." && pwd)
model_name='Dolphin3.0-Llama3.2-3B-stateful-int4.mlpackage'
model_root="$script_dir/ModelAssets"
model_path="$model_root/$model_name"

if command -v hf >/dev/null 2>&1; then
  hf_command=(hf)
elif command -v uvx >/dev/null 2>&1; then
  hf_command=(uvx --from 'huggingface_hub[cli]' hf)
else
  print -u2 'Install the hf CLI or uv before preparing the model.'
  exit 1
fi

mkdir -p "$model_root"
"${hf_command[@]}" download ales27pm/Dolphin3.0-CoreML \
  --revision v2.0.0 \
  --include "$model_name/**" \
  --local-dir "$model_root"

verify_file() {
  local relative_path=$1
  local expected=$2
  local actual
  actual=$(shasum -a 256 "$model_path/$relative_path" | awk '{print $1}')
  if [[ "$actual" != "$expected" ]]; then
    print -u2 "Hash mismatch for $relative_path: $actual"
    exit 1
  fi
}

verify_file 'Data/com.apple.CoreML/model.mlmodel' \
  'a34a00a253c98153cf3b231105493edddde532086e224443e40b255b0f10a924'
verify_file 'Data/com.apple.CoreML/weights/weight.bin' \
  '6240edc377b1a0158812454c4bb6e3053d8e8a75a7eedb751b9740fffdfd3e15'
verify_file 'Manifest.json' \
  '5b8ac347a822f02ba3a6d9ccff60dd723f2649424c8e88570961f12b1c59afb6'

verify_repo_file() {
  local relative_path=$1
  local expected=$2
  local source_path="$repo_root/$relative_path"
  local actual
  if [[ ! -f "$source_path" ]]; then
    print -u2 "Missing bundled tokenizer resource: $source_path"
    exit 1
  fi
  actual=$(shasum -a 256 "$source_path" | awk '{print $1}')
  if [[ "$actual" != "$expected" ]]; then
    print -u2 "Hash mismatch for $relative_path: $actual"
    exit 1
  fi
}

verify_repo_file 'config.json' \
  'e21ff53ea39726f972362beba869807216775d5e308bc2f531784846c06a0249'
verify_repo_file 'generation_config.json' \
  'e627b5a8b2dc371f90388947ada64fa6e71de0f991c04c835f0c0bc97e305a4f'
verify_repo_file 'special_tokens_map.json' \
  '2df2c4620bb1a9eb877bc7c90c7fa04608bda9fa7c0cf2cdcc0a17b849649683'
verify_repo_file 'tokenizer.json' \
  'e40b93124a3e29f62d5f4ff41be56cb2af34ecacf9239acd9da53a98860380b5'
verify_repo_file 'tokenizer_config.json' \
  '51ad9580aba8d00016efda43357185a0d8ff9884584dcc82ab58ca552afd14e1'

if command -v xcodegen >/dev/null 2>&1; then
  xcodegen generate --spec "$script_dir/project.yml" --project "$script_dir"
else
  print 'Assets verified. Install XcodeGen and run xcodegen generate before opening the app.'
fi

print "Prepared and verified the model package and tokenizer resources."