Commit a49d1d88 authored by Your Name's avatar Your Name

Add --download-model CLI argument to download models to cache and exit

- Add --download-model argument to download a model (URL or HuggingFace ID) to cache
- Add --download-file-pattern argument to specify file pattern for HF downloads
- Use download_model from codai.models.cache module
- Model downloads to appropriate cache and exits without starting server
parent 8512c7db
...@@ -365,6 +365,18 @@ def parse_args(): ...@@ -365,6 +365,18 @@ def parse_args():
default=None, default=None,
help="Remove a specific cached model by name or hash (partial match)", help="Remove a specific cached model by name or hash (partial match)",
) )
parser.add_argument(
"--download-model",
type=str,
default=None,
help="Download a model to cache (URL or HuggingFace model ID) and exit. Example: --download-model Qwen/Qwen3-8B-Instruct-2507-Q3_K_S",
)
parser.add_argument(
"--download-file-pattern",
type=str,
default=None,
help="File pattern for HuggingFace model downloads (e.g., .gguf, .safetensors). Default: .gguf for text models",
)
parser.add_argument( parser.add_argument(
"--debug", "--debug",
action="store_true", action="store_true",
......
...@@ -100,6 +100,40 @@ def main(): ...@@ -100,6 +100,40 @@ def main():
print(f"\nRemoved {len(removed)} cached model file(s), freeing {total_size / (1024*1024):.1f} MB") print(f"\nRemoved {len(removed)} cached model file(s), freeing {total_size / (1024*1024):.1f} MB")
sys.exit(0) sys.exit(0)
# Handle --download-model early (before heavy imports)
if args.download_model:
print(f"\n=== Downloading Model: {args.download_model} ===")
from codai.models.cache import download_model
# Determine file pattern for HF downloads
file_pattern = args.download_file_pattern
if file_pattern is None:
# Auto-detect based on model type hints
model_id = args.download_model
if '/' in model_id and not model_id.startswith('http'):
# Likely a HuggingFace model ID - default to GGUF for text models
file_pattern = '.gguf'
else:
# URL or local - no pattern needed
file_pattern = ''
print(f"File pattern: {file_pattern if file_pattern else '(auto-detect)'}")
try:
cached_path = download_model(args.download_model, file_pattern=file_pattern)
if cached_path:
print(f"\n=== Model downloaded successfully ===")
print(f"Cached at: {cached_path}")
sys.exit(0)
else:
print(f"\n=== Failed to download model ===")
sys.exit(1)
except Exception as e:
print(f"\n=== Error downloading model: {e} ===")
sys.exit(1)
# Import globals from codai modules (only after early exits) # Import globals from codai modules (only after early exits)
from codai.api import app from codai.api import app
from codai.api.state import ( from codai.api.state import (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment