Skip to content

Commit

Permalink
Improve handling of error conditions with ollama and snapshot regener…
Browse files Browse the repository at this point in the history
…ation (#15527)
  • Loading branch information
hawkeye217 authored Dec 16, 2024
1 parent d49f958 commit 717493e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 9 additions & 4 deletions frigate/embeddings/maintainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,15 @@ def handle_regenerate_description(self, event_id: str, source: str) -> None:
)

if event.has_snapshot and source == "snapshot":
with open(
os.path.join(CLIPS_DIR, f"{event.camera}-{event.id}.jpg"),
"rb",
) as image_file:
snapshot_file = os.path.join(CLIPS_DIR, f"{event.camera}-{event.id}.jpg")

if not os.path.isfile(snapshot_file):
logger.error(
f"Cannot regenerate description for {event.id}, snapshot file not found: {snapshot_file}"
)
return

with open(snapshot_file, "rb") as image_file:
snapshot_image = image_file.read()
img = cv2.imdecode(
np.frombuffer(snapshot_image, dtype=np.int8), cv2.IMREAD_COLOR
Expand Down
5 changes: 5 additions & 0 deletions frigate/genai/ollama.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ def _init_provider(self):

def _send(self, prompt: str, images: list[bytes]) -> Optional[str]:
"""Submit a request to Ollama"""
if self.provider is None:
logger.warning(
"Ollama provider has not been initialized, a description will not be generated. Check your Ollama configuration."
)
return None
try:
result = self.provider.generate(
self.genai_config.model,
Expand Down

0 comments on commit 717493e

Please sign in to comment.