From 7e3ec325805c650bb6d4109ec3cdeddc9519435f Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat, 19 Apr 2025 20:42:14 -0700 Subject: [PATCH] Some logging, error handling --- src/documents/ai/client.py | 4 ++++ src/documents/ai/llm_classifier.py | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/documents/ai/client.py b/src/documents/ai/client.py index 588b45bf3..4d3b85ec0 100644 --- a/src/documents/ai/client.py +++ b/src/documents/ai/client.py @@ -1,6 +1,10 @@ +import logging + import httpx from django.conf import settings +logger = logging.getLogger("paperless.ai.client") + def run_llm_query(prompt: str) -> str: if settings.LLM_BACKEND == "ollama": diff --git a/src/documents/ai/llm_classifier.py b/src/documents/ai/llm_classifier.py index a6809c15e..53fad9148 100644 --- a/src/documents/ai/llm_classifier.py +++ b/src/documents/ai/llm_classifier.py @@ -33,12 +33,14 @@ def get_ai_document_classification(document: Document) -> dict: """ try: + logger.debug(f"LLM classification prompt: {prompt}") result = run_llm_query(prompt) + logger.debug(f"LLM classification result: {result}") suggestions = parse_llm_classification_response(result) - return suggestions - except Exception as e: - logger.error(f"Error during LLM classification: {e}") - return None + return suggestions or {} + except Exception: + logger.exception("Error during LLM classification: %s", exc_info=True) + return {} def parse_llm_classification_response(text: str) -> dict: