|
1 | 1 | import logging |
2 | 2 | import time |
3 | 3 | from datetime import timedelta |
| 4 | +from pathlib import Path |
4 | 5 |
|
5 | 6 | import click |
6 | 7 |
|
7 | 8 | from embeddings.config import configure_logger, configure_sentry |
| 9 | +from embeddings.models.registry import get_model_class |
8 | 10 |
|
9 | 11 | logger = logging.getLogger(__name__) |
10 | 12 |
|
@@ -46,6 +48,54 @@ def ping() -> None: |
46 | 48 | click.echo("pong") |
47 | 49 |
|
48 | 50 |
|
| 51 | +@main.command() |
| 52 | +@click.option( |
| 53 | + "--model-uri", |
| 54 | + required=True, |
| 55 | + help="HuggingFace model URI (e.g., 'org/model-name')", |
| 56 | +) |
| 57 | +@click.option( |
| 58 | + "--output", |
| 59 | + required=True, |
| 60 | + type=click.Path(path_type=Path), |
| 61 | + help="Output path for zipped model (e.g., '/path/to/model.zip')", |
| 62 | +) |
| 63 | +def download_model(model_uri: str, output: Path) -> None: |
| 64 | + """Download a model from HuggingFace and save as zip file.""" |
| 65 | + try: |
| 66 | + model_class = get_model_class(model_uri) |
| 67 | + except ValueError as e: |
| 68 | + logger.exception("Unknown model URI: %s", model_uri) |
| 69 | + raise click.ClickException(str(e)) from e |
| 70 | + |
| 71 | + logger.info("Downloading model: %s", model_uri) |
| 72 | + model = model_class(model_uri) |
| 73 | + |
| 74 | + try: |
| 75 | + result_path = model.download(output) |
| 76 | + logger.info("Model downloaded successfully to: %s", result_path) |
| 77 | + click.echo(f"Model saved to: {result_path}") |
| 78 | + except NotImplementedError as e: |
| 79 | + logger.exception("Download not yet implemented for model: %s", model_uri) |
| 80 | + raise click.ClickException(str(e)) from e |
| 81 | + except Exception as e: |
| 82 | + logger.exception("Failed to download model: %s", model_uri) |
| 83 | + msg = f"Download failed: {e}" |
| 84 | + raise click.ClickException(msg) from e |
| 85 | + |
| 86 | + |
| 87 | +@main.command() |
| 88 | +@click.option( |
| 89 | + "--model-uri", |
| 90 | + required=True, |
| 91 | + help="HuggingFace model URI (e.g., 'org/model-name')", |
| 92 | +) |
| 93 | +def create_embeddings(model_uri: str) -> None: |
| 94 | + """Create embeddings.""" |
| 95 | + logger.info("create-embeddings command called with model: %s", model_uri) |
| 96 | + raise NotImplementedError |
| 97 | + |
| 98 | + |
49 | 99 | if __name__ == "__main__": # pragma: no cover |
50 | 100 | logger = logging.getLogger("embeddings.main") |
51 | 101 | main() |
0 commit comments