### Install Pre-commit Hooks Source: https://github.com/anirbanbasu/ollama-downloader/blob/master/README.md Installs the pre-commit framework and enables its hooks for the project. This ensures code quality and consistency before committing changes. It requires the 'prek' tool to be installed separately. ```bash just install-pre-commit-hooks ``` -------------------------------- ### Install Ollama Downloader using Homebrew Source: https://github.com/anirbanbasu/ollama-downloader/blob/master/README.md Installs the Ollama Downloader package on macOS and Linux systems using Homebrew. This command assumes that the 'anirbanbasu/tap' repository has already been added. ```bash brew install ollama-downloader ``` -------------------------------- ### Build Native Executable with Nuitka Source: https://github.com/anirbanbasu/ollama-downloader/blob/master/README.md Compiles the Ollama Downloader project into a single executable binary named 'od-native' using Nuitka. This process requires the 'dev' group dependencies to be installed and is an experimental feature. ```bash just build-native-nuitka ``` -------------------------------- ### System Information and Auto-Configuration for Ollama Source: https://context7.com/anirbanbasu/ollama-downloader/llms.txt The OllamaSystemInfo class programmatically detects Ollama installation details, including whether it's running, its process ID, listening address, and models directory. It can also determine if Ollama is running as a daemon and infer user/group information. This information can be used to build configuration for the downloader. Requires the ollama-downloader library. ```python from ollama_downloader.sysinfo import OllamaSystemInfo import json # Create system info instance (singleton) sysinfo = OllamaSystemInfo() # Check if Ollama is running if sysinfo.is_running(): print(f"Ollama is running with PID: {sysinfo.process_id}") # Get listening address listening_address = sysinfo.infer_listening_on() print(f"Ollama listening on: {listening_address}") # Get models directory path models_path = sysinfo.infer_models_dir_path() print(f"Models directory: {models_path}") # Check if running as daemon/service if sysinfo.is_likely_daemon(): owner = sysinfo.get_process_owner() print(f"Running as daemon with owner: {owner[0]} (group: {owner[2]})") # Build configuration config = { "ollama_server": { "url": listening_address, "api_key": None, "remove_downloaded_on_error": True }, "ollama_library": { "models_path": models_path, "user_group": [owner[0], owner[2]] if sysinfo.is_likely_daemon() else None } } print(json.dumps(config, indent=2)) else: print("Ollama is not running") # Platform detection if sysinfo.is_linux(): print("Running on Linux") elif sysinfo.is_macos(): print("Running on macOS") elif sysinfo.is_windows(): print("Running on Windows") ``` -------------------------------- ### Add Homebrew Tap for Ollama Downloader Source: https://github.com/anirbanbasu/ollama-downloader/blob/master/README.md Adds a custom Homebrew tap to your system, allowing you to install the Ollama Downloader package. This command registers the tap repository for future package installations. ```bash brew tap anirbanbasu/tap ``` -------------------------------- ### Configure Ollama Downloader Settings Source: https://context7.com/anirbanbasu/ollama-downloader/llms.txt Demonstrates how to manage application settings using a JSON configuration file and Python code. It covers accessing and modifying server and library configurations, and saving the settings. ```python from ollama_downloader.data.data_models import AppSettings # Load or create default settings settings = AppSettings.load_or_create_default() # Access server configuration server_url = settings.ollama_server.url # "http://localhost:11434" api_key = settings.ollama_server.api_key # None by default remove_on_error = settings.ollama_server.remove_downloaded_on_error # True # Access library configuration models_path = settings.ollama_library.models_path # "~/.ollama/models" registry_url = settings.ollama_library.registry_base_url verify_ssl = settings.ollama_library.verify_ssl # True timeout = settings.ollama_library.timeout # 120.0 seconds user_group = settings.ollama_library.user_group # None or ("user", "group") # Save modified settings AppSettings.save_settings(settings, "conf/settings.json") # Manual settings file example (conf/settings.json): # { # "ollama_server": { # "url": "http://192.168.1.100:11434", # "api_key": null, # "remove_downloaded_on_error": true # }, # "ollama_library": { # "models_path": "/usr/share/ollama/.ollama/models", # "registry_base_url": "https://registry.ollama.ai/v2/library/", # "library_base_url": "https://ollama.com/library", # "verify_ssl": true, # "timeout": 120.0, # "user_group": ["ollama", "ollama"] # } # } ``` -------------------------------- ### Custom HTTPX Client with SSL Configuration Source: https://context7.com/anirbanbasu/ollama-downloader/llms.txt Demonstrates how to create a custom downloader that utilizes a pre-configured HTTPX client for network operations. This custom client can be set up with specific SSL verification settings, HTTP/2 support, proxy trust, custom headers, and redirect policies. It's useful for advanced network configurations. Requires the ollama-downloader library. ```python from ollama_downloader.downloader.model_downloader import ModelDownloader, ModelSource import httpx class CustomDownloader(ModelDownloader): def list_available_models(self, page=None, page_size=None): # Use the configured HTTPX client with self.get_httpx_client( verify=self.settings.ollama_library.verify_ssl, timeout=self.settings.ollama_library.timeout ) as client: # Client is configured with: # - Custom SSL certificates (from env vars) # - HTTP/2 support # - Trust environment proxy settings # - Custom User-Agent header # - Follow redirects enabled response = client.get("https://example.com/api/models") response.raise_for_status() return response.json() # Required abstract methods (simplified) def download_model(self, model_identifier): pass def list_model_tags(self, model_identifier): pass ``` -------------------------------- ### Configure Ollama Downloader via Environment Variables Source: https://context7.com/anirbanbasu/ollama-downloader/llms.txt Explains how to configure the Ollama Downloader application using environment variables for various deployment scenarios, including logging, custom settings files, user agents, and SSL certificates. ```bash # Set logging level (NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL) export OD_LOG_LEVEL="DEBUG" # Specify custom settings file location export OD_SETTINGS_FILE="/etc/ollama-downloader/settings.json" # Set custom user agent for HTTP requests export OD_UA_NAME_VER="my-app/1.0.0" # Use custom SSL certificates export SSL_CERT_FILE="/path/to/custom/ca-bundle.crt" export SSL_CERT_DIR="/path/to/certs" # Run with environment variables OD_LOG_LEVEL=DEBUG uv run od model-download llama3.2:1b # For HTTPS proxy with self-signed certificates export HTTPS_PROXY="https://proxy.example.com:8080" export SSL_CERT_FILE="/path/to/proxy-ca.crt" uv run od model-download all-minilm ``` -------------------------------- ### Configure Proxy and Custom Certificates for Ollama Downloader (Python) Source: https://context7.com/anirbanbasu/ollama-downloader/llms.txt This snippet demonstrates how to configure environment variables for HTTPS proxy and custom SSL certificates when using the Ollama Downloader. The `httpx` client, used internally by the downloader, will automatically pick up these settings for secure and proxied connections. Ensure the provided paths for proxies and certificates are correct for your environment. ```python import os os.environ['HTTPS_PROXY'] = 'https://proxy.corp.com:8080' os.environ['SSL_CERT_FILE'] = '/path/to/corporate-ca.pem' downloader = CustomDownloader() # HTTPX client will automatically use proxy and custom certificates ``` -------------------------------- ### List Quantizations for Hugging Face Model Source: https://context7.com/anirbanbasu/ollama-downloader/llms.txt Lists available quantizations as tags for a specific Hugging Face model compatible with Ollama. The output includes the model name followed by its quantization tag. ```bash # List quantizations for a specific model uv run od hf-list-tags bartowski/Llama-3.2-1B-Instruct-GGUF # List quantizations for another model uv run od hf-list-tags unsloth/gemma-3-270m-it-GGUF # Example output: # Model tags: (15): ['bartowski/Llama-3.2-1B-Instruct-GGUF:Q2_K', # 'bartowski/Llama-3.2-1B-Instruct-GGUF:Q3_K_L', # 'bartowski/Llama-3.2-1B-Instruct-GGUF:Q3_K_M', # 'bartowski/Llama-3.2-1B-Instruct-GGUF:Q4_K_M', ...] ``` -------------------------------- ### Run Profiling with Just Source: https://github.com/anirbanbasu/ollama-downloader/blob/master/README.md Initiates the execution of tests with profiling enabled using the 'just' command runner. This generates profile information saved in the './prof' directory and allows for the creation of an SVG visualization of the profile data. ```bash just test-with-profiling ``` -------------------------------- ### Download Hugging Face Model Programmatically Source: https://context7.com/anirbanbasu/ollama-downloader/llms.txt Enables programmatic downloading of GGUF models from Hugging Face using the HuggingFaceModelDownloader class. It supports listing available Ollama-compatible models, their quantizations, and downloading specific model versions. Error handling is included for pagination and runtime issues. Requires the ollama-downloader library. ```python import logging from ollama_downloader.downloader.hf_model_downloader import HuggingFaceModelDownloader logging.basicConfig(level=logging.INFO) try: # Initialize Hugging Face downloader hf_downloader = HuggingFaceModelDownloader() # List available Ollama-compatible models from Hugging Face hf_models = hf_downloader.list_available_models(page=1, page_size=25) print(f"Hugging Face models: {hf_models}") # List quantizations for a specific repository quantizations = hf_downloader.list_model_tags("unsloth/gemma-3-270m-it-GGUF") print(f"Available quantizations: {quantizations}") # Download specific quantization success = hf_downloader.download_model("unsloth/gemma-3-270m-it-GGUF:Q4_K_M") if success: print("Hugging Face model downloaded successfully!") except ValueError as e: # Handle pagination limits print(f"Pagination error: {e}") except RuntimeError as e: # Handle model not found or incompatible print(f"Runtime error: {e}") finally: hf_downloader.cleanup_unnecessary_files() ``` -------------------------------- ### Download Hugging Face Model - ollama-downloader Source: https://github.com/anirbanbasu/ollama-downloader/blob/master/README.md Downloads a specified Hugging Face model for use with Ollama. It validates the model's manifest and BLOB SHA256 hash, then confirms availability with the Ollama server. The command requires a user repository and quantisation identifier as input. ```bash uv run od hf-model-download unsloth/gemma-3-270m-it-GGUF:Q4_K_M ``` -------------------------------- ### List Ollama Models with Pagination Source: https://github.com/anirbanbasu/ollama-downloader/blob/master/README.md The `list-models` command fetches all models from the Ollama library and applies pagination locally. It accepts options for page number and the number of models per page. This is useful for browsing the available models in a structured manner. ```bash uv run od list-models --help Usage: od list-models [OPTIONS] Lists all available models in the Ollama library. If pagination options are not provided, all models will be listed. ╭─ Options ──────────────────────────────────────────────────────────────────────────────────╮ │ --page INTEGER RANGE [x>=1] The page number to retrieve (1-indexed). │ │ --page-size INTEGER RANGE [1<=x<=100] The number of models to retrieve per page. │ │ --help Show this message and exit. │ ╰────────────────────────────────────────────────────────────────────────────────────────────╯ ``` -------------------------------- ### Download Hugging Face Model for Ollama Source: https://context7.com/anirbanbasu/ollama-downloader/llms.txt Downloads a specific Hugging Face model with a chosen quantization into Ollama. The process involves downloading and validating the manifest and BLOBs, copying to the Ollama models directory, and verifying registration. ```bash # Download with specific quantization uv run od hf-model-download unsloth/gemma-3-270m-it-GGUF:Q4_K_M # Download another quantization uv run od hf-model-download bartowski/Llama-3.2-1B-Instruct-GGUF:Q4_K_M # Process includes: # 1. Downloading manifest from Hugging Face registry # 2. Validating manifest structure # 3. Downloading and validating all BLOBs # 4. Copying to Ollama models directory # 5. Verifying registration in Ollama server # # Example output: # Downloading Hugging Face model gemma-3-270m-it-GGUF from unsloth with Q4_K_M quantisation # Downloading manifest from https://hf.co/v2/unsloth/gemma-3-270m-it-GGUF/manifests/Q4_K_M # Validating manifest for unsloth/gemma-3-270m-it-GGUF:Q4_K_M # Model hf.co/unsloth/gemma-3-270m-it-GGUF:Q4_K_M successfully downloaded and saved on December 25 2024 at 15:45:22. ``` -------------------------------- ### Download Ollama Model with Tag Source: https://github.com/anirbanbasu/ollama-downloader/blob/master/README.md The `model-download` command downloads a specified model and its tag from the Ollama library. It performs manifest validation, BLOB SHA256 hash validation, and post-download verification with the Ollama server. If no tag is specified, it defaults to 'latest'. ```bash uv run od model-download --help Usage: od model-download [OPTIONS] MODEL_TAG Downloads a specific Ollama model with the given tag. ╭─ Arguments ──────────────────────────────────────────────────╮ │ * model_tag TEXT The name of the model and a │ │ specific to download, specified as │ │ :, e.g., │ │ llama3.1:8b. If no tag is │ │ specified, 'latest' will be │ │ assumed. │ │ [default: None] │ │ [required] │ ╰──────────────────────────────────────────────────────────────╯ ╭─ Options ────────────────────────────────────────────────────╮ │ --help Show this message and exit. │ ╰──────────────────────────────────────────────────────────────╯ ``` ```bash # Example: Download the 'all-minilm:latest' embedding model uv run od model-download all-minilm # Example: Download the 'llama3.2' model with the '3b' tag uv run od model-download llama3.2:3b # Example using sudo (as shown in screencast) sudo .venv/bin/od model-download all-minilm ``` -------------------------------- ### List Hugging Face Models for Ollama Source: https://context7.com/anirbanbasu/ollama-downloader/llms.txt Lists available Ollama-compatible models from Hugging Face. Supports pagination and custom page sizes, but results are limited to the first 1000 models due to Hugging Face API limitations. ```bash # List first page (default: 25 models per page) uv run od hf-list-models # List specific page with custom size uv run od hf-list-models --page 2 --page-size 50 # List maximum models per page uv run od hf-list-models --page 1 --page-size 100 # Note: Due to Hugging Face API limitations, results are limited to first 1000 models # Example output: # Model identifiers: (25, page 1): ['bartowski/Llama-3.2-1B-Instruct-GGUF', # 'bartowski/gemma-2-2b-it-GGUF', # 'unsloth/gemma-3-270m-it-GGUF', ...] ``` -------------------------------- ### List Downloadable Hugging Face Models - ollama-downloader Source: https://github.com/anirbanbasu/ollama-downloader/blob/master/README.md Lists available Hugging Face models that are compatible with Ollama downloads. Supports pagination to retrieve models in batches. Note that due to API limitations, results may be capped, and a warning log may provide a link to the full list. ```bash uv run od hf-list-models --page 1 --page-size 25 ``` -------------------------------- ### Download Ollama Library Model Programmatically Source: https://context7.com/anirbanbasu/ollama-downloader/llms.txt Utilizes the OllamaModelDownloader class to programmatically download models from the Ollama library. It allows listing available models and their tags, and downloading specific model versions. Logging is configured to display progress. Requires the ollama-downloader library. ```python import logging from ollama_downloader.downloader.ollama_model_downloader import OllamaModelDownloader # Set up logging to see progress logging.basicConfig(level=logging.INFO) try: # Initialize downloader (loads configuration automatically) downloader = OllamaModelDownloader() # List available models available_models = downloader.list_available_models(page=1, page_size=10) print(f"First 10 models: {available_models}") # List tags for a specific model tags = downloader.list_model_tags("llama3.2") print(f"Available tags for llama3.2: {tags}") # Download a model with specific tag success = downloader.download_model("llama3.2:1b") if success: print("Model downloaded and verified successfully!") else: print("Model download failed") except Exception as e: print(f"Error: {e}") finally: # Clean up temporary files downloader.cleanup_unnecessary_files() ``` -------------------------------- ### Run Tests and Coverage with Pytest and Coverage Source: https://github.com/anirbanbasu/ollama-downloader/blob/master/README.md Executes the project's test suite using pytest and generates code coverage reports. It relies on the 'just' command runner and produces a summary of test coverage, indicating statements executed and missed. ```bash just test-coverage ``` -------------------------------- ### hf-list-models Source: https://github.com/anirbanbasu/ollama-downloader/blob/master/README.md Lists available Hugging Face models that can be downloaded into Ollama. Supports pagination for retrieving models. ```APIDOC ## GET /hf-list-models ### Description Lists available Hugging Face models that are compatible with Ollama downloads. This endpoint supports pagination to retrieve models in batches. ### Method GET ### Endpoint /hf-list-models ### Parameters #### Path Parameters None #### Query Parameters - **page** (integer) - Optional - The page number to retrieve (1-indexed). Defaults to 1. - **page_size** (integer) - Optional - The number of models to retrieve per page. Must be between 1 and 100. Defaults to 25. ### Request Example ```json { "page": 1, "page_size": 50 } ``` ### Response #### Success Response (200) - **models** (array) - A list of available Hugging Face models. - **model_name** (string) - The name of the Hugging Face model. - **next_page** (string) - A URL to the next page of results, if available. #### Response Example ```json { "models": [ { "model_name": "unsloth/gemma-3-270m-it-GGUF:Q4_K_M" }, { "model_name": "bartowski/Llama-3.2-1B-Instruct-GGUF:Q4_K_M" } ], "next_page": "/hf-list-models?page=2&page_size=50" } ``` ``` -------------------------------- ### hf-model-download Source: https://github.com/anirbanbasu/ollama-downloader/blob/master/README.md Downloads a specified model from Hugging Face. It validates the model manifest, checks SHA256 hashes of downloaded BLOBs, and verifies the model with the Ollama server. ```APIDOC ## POST /hf-model-download ### Description Downloads a specified model from Hugging Face. It performs validation of the model manifest, checks SHA256 hashes of downloaded BLOBs, and verifies the downloaded model with the Ollama server. ### Method POST ### Endpoint /hf-model-download ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **user_repo_quant** (string) - Required - The name of the specific Hugging Face model to download, specified as `/:`, e.g., `bartowski/Llama-3.2-1B-Instruct-GGUF:Q4_K_M`. ### Request Example ```json { "user_repo_quant": "unsloth/gemma-3-270m-it-GGUF:Q4_K_M" } ``` ### Response #### Success Response (200) - **message** (string) - A confirmation message indicating the download was successful. #### Response Example ```json { "message": "Model unsloth/gemma-3-270m-it-GGUF:Q4_K_M downloaded successfully." } ``` ``` -------------------------------- ### hf-list-tags Source: https://github.com/anirbanbasu/ollama-downloader/blob/master/README.md Lists available quantisations (tags) for a specified Hugging Face model that can be downloaded into Ollama. ```APIDOC ## GET /hf-list-tags/{model_identifier} ### Description Lists all available quantisations (tags) for a specified Hugging Face model that can be downloaded into Ollama. Note that these are NOT the same as Hugging Face model tags. ### Method GET ### Endpoint /hf-list-tags/{model_identifier} ### Parameters #### Path Parameters - **model_identifier** (string) - Required - The name of the model to list tags for, e.g., `bartowski/Llama-3.2-1B-Instruct-GGUF`. #### Query Parameters None #### Request Body None ### Request Example ```json { "model_identifier": "unsloth/gemma-3-270m-it-GGUF" } ``` ### Response #### Success Response (200) - **tags** (array) - A list of available quantisation tags for the specified model. - **tag_name** (string) - The name of the quantisation tag. #### Response Example ```json { "tags": [ { "tag_name": "Q4_K_M" }, { "tag_name": "Q5_K_M" } ] } ``` ``` -------------------------------- ### List Models API Source: https://github.com/anirbanbasu/ollama-downloader/blob/master/README.md Retrieves a list of all available models in the Ollama library. Supports local pagination. ```APIDOC ## GET /api/models ### Description Retrieves a list of all available models in the Ollama library. This endpoint fetches the entire model list from the Ollama library and applies pagination locally. ### Method GET ### Endpoint /api/models ### Parameters #### Query Parameters - **page** (integer) - Optional - The page number to retrieve (1-indexed). - **page-size** (integer) - Optional - The number of models to retrieve per page (1-100). ### Response #### Success Response (200) - **models** (array) - A list of available models. - **name** (string) - The name of the model. - **digest** (string) - The digest of the model. - **size** (integer) - The size of the model in bytes. - **details** (object) - Additional details about the model. #### Response Example ```json { "models": [ { "name": "llama3", "digest": "sha256:a04504f3830985c995b264a2878e559f4254489b8c0f53978242e468255f699d", "size": 4716754872, "details": { "parent_model": "", "format": "gguf", "modified_at": "2024-04-09T13:17:27.477408114Z", "sha256": "a04504f3830985c995b264a2878e559f4254489b8c0f53978242e468255f699d" } } ], "total": 1, "page": 1, "page_size": 10 } ``` ``` -------------------------------- ### List Tags for a Specific Ollama Model Source: https://github.com/anirbanbasu/ollama-downloader/blob/master/README.md The `list-tags` command displays all available tags for a given model identifier in the Ollama library. This command requires a `model_identifier` as an argument and is essential for identifying specific versions of a model. ```bash uv run od list-tags --help Usage: od list-tags [OPTIONS] MODEL_IDENTIFIER Lists all tags for a specific model. ╭─ Arguments ─────────────────────────────────────────────────╮ │ * model_identifier TEXT The name of the model to list tags for, │ │ e.g., llama3.1. │ │ [default: None] │ │ [required] │ ╰─────────────────────────────────────────────────────────────╯ ╭─ Options ───────────────────────────────────────────────────────────────────╮ │ --help Show this message and exit. │ ╰─────────────────────────────────────────────────────────────────────────────╯ ``` -------------------------------- ### Run Filtered Profile Data Script with UV Source: https://github.com/anirbanbasu/ollama-downloader/blob/master/README.md Executes a Python script to filter profile data and generate an SVG visualization. This script is intended for use with the 'uv' package runner and requires the 'tests/filter_profile_data.py' script to be present. ```bash uv run tests/filter_profile_data.py ``` -------------------------------- ### Download Model API Source: https://github.com/anirbanbasu/ollama-downloader/blob/master/README.md Downloads a specified model and its tag from the Ollama library. Performs manifest and BLOB validation, and post-download verification. ```APIDOC ## POST /api/models/download ### Description Downloads a specific Ollama model with the given tag. The process includes validation of the model manifest and BLOBs, followed by a post-download verification with the Ollama server. ### Method POST ### Endpoint /api/models/download ### Parameters #### Request Body - **model_tag** (string) - Required - The name of the model and tag to download, specified as `:` (e.g., `llama3.2:3b`). If no tag is specified, `latest` will be assumed. ### Request Example ```json { "model_tag": "llama3.2:3b" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the download operation. - **digest** (string) - The digest of the downloaded model. #### Response Example ```json { "status": "downloaded", "digest": "sha256:1c71f8d6f6431f527634206179d116b08650e494957190a7b21e7851a02c5c84" } ``` ``` -------------------------------- ### List Model Tags API Source: https://github.com/anirbanbasu/ollama-downloader/blob/master/README.md Retrieves a list of tags for a specified model in the Ollama library. ```APIDOC ## GET /api/tags/{model_identifier} ### Description Retrieves all available tags for a specific model in the Ollama library. ### Method GET ### Endpoint /api/tags/{model_identifier} ### Parameters #### Path Parameters - **model_identifier** (string) - Required - The name of the model to list tags for (e.g., `llama3.1`). ### Response #### Success Response (200) - **tags** (array) - A list of tags available for the specified model. - **name** (string) - The name of the tag. - **digest** (string) - The digest of the tag. - **size** (integer) - The size of the model associated with the tag in bytes. #### Response Example ```json { "tags": [ { "name": "latest", "digest": "sha256:a04504f3830985c995b264a2878e559f4254489b8c0f53978242e468255f699d", "size": 4716754872 }, { "name": "8b", "digest": "sha256:1c71f8d6f6431f527634206179d116b08650e494957190a7b21e7851a02c5c84", "size": 4716754872 } ] } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.