Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions llm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3360,14 +3360,15 @@ def embed_multi(
for alias, attach_path in attach:
db.attach(alias, attach_path)

effective_model_id = model or get_default_embedding_model()
try:
collection_obj = Collection(
collection, db=db, model_id=model or get_default_embedding_model()
)
collection_obj = Collection(collection, db=db, model_id=effective_model_id)
except ValueError:
raise click.ClickException(
"You need to specify an embedding model (no default model is set)"
)
if effective_model_id is None:
raise click.ClickException(
"You need to specify an embedding model (no default model is set)"
)
raise

expected_length = None
if files:
Expand Down
24 changes: 23 additions & 1 deletion tests/test_embed_cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import pathlib
import sys
from unittest.mock import ANY
from unittest.mock import ANY, patch

import pytest
import sqlite_utils
Expand Down Expand Up @@ -715,3 +715,25 @@ def test_duplicate_content_embedded_only_once(embed_demo):
# Should have only embedded one more thing
assert db["embeddings"].count == 4
assert len(embed_demo.embedded_content) == 4


def test_embed_multi_non_model_valueerror_is_not_masked(user_path):
# A ValueError raised by Collection() for a reason other than a missing model
# must not be swallowed and replaced with the "no default model" message.
runner = CliRunner()
sentinel = ValueError("DB migration failed unexpectedly")

def raise_sentinel(*args, **kwargs):
raise sentinel

with patch("llm.cli.Collection", side_effect=raise_sentinel):
result = runner.invoke(
cli,
["embed-multi", "test", "-", "-m", "embed-demo"],
input="id,text\n1,hello",
)

# The original ValueError must propagate, not be converted to a ClickException
# about missing embedding models.
assert result.exception is sentinel
assert "no default model" not in (result.output or "")
Loading