ollamaPackages.mkOllamaModel: sanity checks during development that you actually specify all the needed blobs

This commit is contained in:
2024-12-05 22:11:33 +00:00
parent ec1d573ddb
commit c3c212b6dd

View File

@@ -92,26 +92,46 @@ stdenv.mkDerivation {
echo "manifest:" echo "manifest:"
cat manifest cat manifest
printBlob() { mismatchedBlobs=()
checkBlob() {
local blobType="$1" local blobType="$1"
local expectedBlobHash="$2"
local blobHash=$(cat manifest | jq ".layers.[] | select(.mediaType == \"application/vnd.ollama.image.$blobType\") | .digest[7:]") local blobHash=$(cat manifest | jq ".layers.[] | select(.mediaType == \"application/vnd.ollama.image.$blobType\") | .digest[7:]")
if [ -n "$blobHash" ]; then if [ -n "$blobHash" ]; then
printf " %sBlob = %s;\n" "$blobType" "$blobHash" printf " %sBlob = %s;\n" "$blobType" "$blobHash"
fi fi
if [ "''${blobHash//\"/}" != "$expectedBlobHash" ]; then
mismatchedBlobs+=("$blobType")
fi
} }
echo "blobs:" echo "blobs:"
printBlob model checkBlob model "$modelBlob"
printBlob params checkBlob params "$paramsBlob"
printBlob system checkBlob system "$systemBlob"
printBlob ensureDoesntFailForNonExistentBlob checkBlob ensureDoesntFailForNonExistentBlob
if [ -n "$mismatchedBlobs" ]; then
echo "mismatched blobs:"
for b in "''${mismatchedBlobs[@]}"; do
echo "- $b"
done
false
fi
runHook postCheck runHook postCheck
''; '';
doCheck = true; doCheck = true;
env.blobDir = "share/ollama/models/blobs"; env = {
env.manifestDir = "share/ollama/models/manifests/registry.ollama.ai/library/${modelName}"; blobDir = "share/ollama/models/blobs";
env.variant = variant; manifestDir = "share/ollama/models/manifests/registry.ollama.ai/library/${modelName}";
inherit variant modelBlob paramsBlob systemBlob;
};
meta = {
homepage = "https://ollama.com/library/${modelName}";
};
} }