]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Changeup logging
authorshamoon <4887959+shamoon@users.noreply.github.com>
Sun, 20 Apr 2025 04:01:54 +0000 (21:01 -0700)
committershamoon <4887959+shamoon@users.noreply.github.com>
Wed, 2 Jul 2025 18:00:58 +0000 (11:00 -0700)
src/documents/ai/client.py
src/documents/ai/llm_classifier.py

index 4d3b85ec0c00d33c06ff23696fdc9ba2c6bb9a45..13bf680bc354f9634105b6979388776767156fcf 100644 (file)
@@ -7,9 +7,20 @@ logger = logging.getLogger("paperless.ai.client")
 
 
 def run_llm_query(prompt: str) -> str:
-    if settings.LLM_BACKEND == "ollama":
-        return _run_ollama_query(prompt)
-    return _run_openai_query(prompt)
+    logger.debug(
+        "Running LLM query against %s with model %s",
+        settings.LLM_BACKEND,
+        settings.LLM_MODEL,
+    )
+    match settings.LLM_BACKEND:
+        case "openai":
+            result = _run_openai_query(prompt)
+        case "ollama":
+            result = _run_ollama_query(prompt)
+        case _:
+            raise ValueError(f"Unsupported LLM backend: {settings.LLM_BACKEND}")
+    logger.debug("LLM query result: %s", result)
+    return result
 
 
 def _run_ollama_query(prompt: str) -> str:
index 53fad9148eea9be515b631ecf5ec77e02dd4de06..b4c4db33f2a19f188bef77702ab328534aea57e6 100644 (file)
@@ -15,6 +15,9 @@ def get_ai_document_classification(document: Document) -> dict:
     filename = document.filename or ""
     content = document.content or ""
 
+    # Limit the content to 10k characters
+    content = content[:10000]
+
     prompt = f"""
     You are a document classification assistant. Based on the content below, return a JSON object suggesting the following classification fields:
     - title: A descriptive title for the document
@@ -33,9 +36,7 @@ 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 or {}
     except Exception: