mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-23 10:39:25 -05:00
Refactor
This commit is contained in:
parent
16d7d95517
commit
131ae28794
@ -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
|
||||
|
@ -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 {}
|
Loading…
x
Reference in New Issue
Block a user