"""Model import: telling what a model file is from its header (model_kind.py), finding the dropped file on this computer, and putting it into the models folder without replacing anything (api/model_import.py). No network; files go to temporary folders.""" import asyncio import json import os import struct import sys import tempfile import time import unittest from pathlib import Path from unittest import mock from aiohttp import web from aiohttp.test_utils import TestClient, TestServer PLUGIN = Path(__file__).resolve().parents[1] sys.path[:0] = [str(PLUGIN), str(PLUGIN.parents[1])] import model_identity # noqa: E402 import model_kind # noqa: E402 from api import model_import # noqa: E402 def tensors(*names, shapes=None, meta=None): header = {name: {"dtype": "F16", "shape": (shapes or {}).get(name, [4, 4]), "data_offsets": [0, 0]} for name in names} if meta: header["__metadata__"] = meta return header def safetensors_bytes(header): raw = json.dumps(header).encode("utf-8") return struct.pack("