]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Refactor
authorshamoon <4887959+shamoon@users.noreply.github.com>
Mon, 21 Apr 2025 18:34:09 +0000 (11:34 -0700)
committershamoon <4887959+shamoon@users.noreply.github.com>
Tue, 22 Apr 2025 15:08:28 +0000 (08:08 -0700)
src/documents/views.py
src/paperless/ai/ai_classifier.py [moved from src/paperless/ai/llm_classifier.py with 89% similarity]

index b475cbff1599b1aac7f9b80f39615cc085465f37..860be20a03ee478831962d1a5c96a3bcd381be98 100644 (file)
@@ -77,12 +77,6 @@ from rest_framework.viewsets import ViewSet
 
 from documents import bulk_edit
 from documents import index
-from documents.ai.llm_classifier import get_ai_document_classification
-from documents.ai.matching import extract_unmatched_names
-from documents.ai.matching import match_correspondents_by_name
-from documents.ai.matching import match_document_types_by_name
-from documents.ai.matching import match_storage_paths_by_name
-from documents.ai.matching import match_tags_by_name
 from documents.bulk_download import ArchiveOnlyStrategy
 from documents.bulk_download import OriginalAndArchiveStrategy
 from documents.bulk_download import OriginalsOnlyStrategy
@@ -176,6 +170,12 @@ from documents.tasks import sanity_check
 from documents.tasks import train_classifier
 from documents.templating.filepath import validate_filepath_template_and_render
 from paperless import version
+from paperless.ai.ai_classifier import get_ai_document_classification
+from paperless.ai.matching import extract_unmatched_names
+from paperless.ai.matching import match_correspondents_by_name
+from paperless.ai.matching import match_document_types_by_name
+from paperless.ai.matching import match_storage_paths_by_name
+from paperless.ai.matching import match_tags_by_name
 from paperless.celery import app as celery_app
 from paperless.config import GeneralConfig
 from paperless.db import GnuPG
similarity index 89%
rename from src/paperless/ai/llm_classifier.py
rename to src/paperless/ai/ai_classifier.py
index 7370a3cb47713b8b2ea77d1512664506793fde97..71eae8bacaa731ea494619ef66da4cdc4e52765d 100644 (file)
@@ -4,7 +4,7 @@ import logging
 from documents.models import Document
 from paperless.ai.client import run_llm_query
 
-logger = logging.getLogger("paperless.ai.llm_classifier")
+logger = logging.getLogger("paperless.ai.ai_classifier")
 
 
 def get_ai_document_classification(document: Document) -> dict:
@@ -50,14 +50,14 @@ def get_ai_document_classification(document: Document) -> dict:
 
     try:
         result = run_llm_query(prompt)
-        suggestions = parse_llm_classification_response(result)
+        suggestions = parse_ai_classification_response(result)
         return suggestions or {}
     except Exception:
         logger.exception("Error during LLM classification: %s", exc_info=True)
         return {}
 
 
-def parse_llm_classification_response(text: str) -> dict:
+def parse_ai_classification_response(text: str) -> dict:
     """
     Parses LLM output and ensures it conforms to expected schema.
     """
@@ -77,4 +77,9 @@ def parse_llm_classification_response(text: str) -> dict:
         }
     except json.JSONDecodeError:
         # fallback: try to extract JSON manually?
+        logger.exception(
+            "Failed to parse LLM classification response: %s",
+            text,
+            exc_info=True,
+        )
         return {}