feat: download Hugging Face GGUF models
This commit is contained in:
@@ -121,12 +121,48 @@ class ValidationHarnessTests(unittest.TestCase):
|
||||
with patch.object(api, "_search_ollama_catalog", return_value=ollama) as ollama_search, patch.object(
|
||||
api, "_search_huggingface", return_value=huggingface
|
||||
) as hf_search:
|
||||
response = api.catalog_search("Qwen3.8", limit=10)
|
||||
response = api.catalog_search("Qwen3.8", limit=10, include_huggingface=True)
|
||||
self.assertEqual(response["results"], ollama + huggingface)
|
||||
self.assertEqual(response["sources"], ["ollama", "huggingface"])
|
||||
ollama_search.assert_called_once_with("Qwen3.8", limit=10)
|
||||
hf_search.assert_called_once_with("Qwen3.8", limit=10)
|
||||
|
||||
def test_huggingface_groups_split_gguf_files_into_complete_sets(self):
|
||||
metadata = {
|
||||
"siblings": [
|
||||
{"rfilename": "Q4/Qwen-00001-of-00002.gguf"},
|
||||
{"rfilename": "Q4/Qwen-00002-of-00002.gguf"},
|
||||
{"rfilename": "Q8/Qwen.gguf"},
|
||||
{"rfilename": "Q8/README.md"},
|
||||
]
|
||||
}
|
||||
with patch.object(api, "_json_request", return_value=metadata):
|
||||
files = api._huggingface_repo_files("owner/repository")
|
||||
self.assertEqual(len(files), 2)
|
||||
split = next(item for item in files if item["split"])
|
||||
self.assertEqual(split["file_count"], 2)
|
||||
self.assertEqual(len(split["filenames"]), 2)
|
||||
single = next(item for item in files if not item["split"])
|
||||
self.assertEqual(single["filename"], "Q8/Qwen.gguf")
|
||||
|
||||
def test_huggingface_download_rejects_non_gguf_paths(self):
|
||||
with self.assertRaises(api.HTTPException):
|
||||
api._valid_huggingface_filename("../model.safetensors")
|
||||
with self.assertRaises(api.HTTPException):
|
||||
api._valid_huggingface_filename("model.bin")
|
||||
self.assertEqual(api._valid_huggingface_filename("Q4_K_M/model.gguf"), "Q4_K_M/model.gguf")
|
||||
|
||||
def test_huggingface_download_queues_validated_file(self):
|
||||
body = api.HuggingFaceDownloadRequest(repo_id="unsloth/Qwen3.8-Flash-Next-GGUF", filename="Q4_K_M/model.gguf")
|
||||
fake_thread = type("Thread", (), {"start": lambda self: None})
|
||||
with patch.object(api, "_huggingface_repo_files", return_value=[{"filename": body.filename, "size": 123}]), patch.object(
|
||||
api.threading, "Thread", return_value=fake_thread()
|
||||
) as thread:
|
||||
response = api.huggingface_download(body)
|
||||
self.assertTrue(response["ok"])
|
||||
self.assertEqual(response["filename"], body.filename)
|
||||
thread.assert_called_once()
|
||||
|
||||
def test_primary_draft_validators_and_primary_compilation_produce_one_answer(self):
|
||||
body = api.ChatRequest(
|
||||
primary_model="primary",
|
||||
|
||||
Reference in New Issue
Block a user