Some logging, error handling

This commit is contained in:
shamoon 2025-04-19 20:42:14 -07:00
parent 84da2ce145
commit 7e3ec32580
No known key found for this signature in database
2 changed files with 10 additions and 4 deletions

View File

@ -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":

View File

@ -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: