allow saving of empty description

This commit is contained in:
Josh Hawkins 2024-09-23 21:46:27 -05:00
parent df96c04c38
commit 8063ec38bb

View File

@ -911,34 +911,32 @@ def set_description(id):
json: dict[str, any] = request.get_json(silent=True) or {} json: dict[str, any] = request.get_json(silent=True) or {}
new_description = json.get("description") new_description = json.get("description")
if new_description is None or len(new_description) == 0: event.data["description"] = new_description or None
return make_response(
jsonify(
{
"success": False,
"message": "description cannot be empty",
}
),
400,
)
event.data["description"] = new_description
event.save() event.save()
# If semantic search is enabled, update the index # If semantic search is enabled, update the index
if current_app.frigate_config.semantic_search.enabled: if current_app.frigate_config.semantic_search.enabled:
context: EmbeddingsContext = current_app.embeddings context: EmbeddingsContext = current_app.embeddings
context.embeddings.description.upsert( if new_description is None or len(new_description) == 0:
documents=[new_description], context.embeddings.description.delete(ids=[id])
metadatas=[get_metadata(event)], else:
ids=[id], context.embeddings.description.upsert(
) documents=[new_description],
metadatas=[get_metadata(event)],
ids=[id],
)
response_message = (
f"Event {id} description is now blank"
if new_description is None or len(new_description) == 0
else f"Event {id} description set to {new_description}"
)
return make_response( return make_response(
jsonify( jsonify(
{ {
"success": True, "success": True,
"message": "Event " + id + " description set to " + new_description, "message": response_message,
} }
), ),
200, 200,