enable use without optional models, adds warning

This commit is contained in:
LUIS NOVO 2024-11-14 12:12:11 -03:00
parent cd3ad2e9fa
commit c8b5d422ae
12 changed files with 108 additions and 44 deletions

View file

@ -110,7 +110,6 @@ class ObjectModel(BaseModel):
def save(self) -> None:
from open_notebook.domain.models import model_manager
from open_notebook.models import EmbeddingModel
try:
self.model_validate(self.model_dump(), strict=True)
@ -120,8 +119,16 @@ class ObjectModel(BaseModel):
if self.needs_embedding():
embedding_content = self.get_embedding_content()
if embedding_content:
EMBEDDING_MODEL: EmbeddingModel = model_manager.embedding_model
data["embedding"] = EMBEDDING_MODEL.embed(embedding_content)
EMBEDDING_MODEL = model_manager.embedding_model
if not EMBEDDING_MODEL:
logger.warning(
"No embedding model found. Content will not be searchable."
)
data["embedding"] = (
EMBEDDING_MODEL.embed(embedding_content)
if EMBEDDING_MODEL
else []
)
if self.id is None:
data["created"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")