Repository: fedora-copr/logdetective

Issue:
ModuleNotFoundError: No module named 'logdetective.server.models'
When I install logdetective as RPM (without server part) I get:

```
 logdetective https://kojipkgs.fedoraproject.org//work/tasks/7637/130807637/root.log
Traceback (most recent call last):
  File "/usr/bin/logdetective", line 5, in <module>
    from logdetective.logdetective import main
  File "/usr/lib/python3.13/site-packages/logdetective/logdetective.py", line 6, in <module>
    from logdetective.utils import (
    ...<6 lines>...
    )
  File "/usr/lib/python3.13/site-packages/logdetective/utils.py", line 11, in <module>
    from logdetective.server.models import AnalyzedSnippet
ModuleNotFoundError: No module named 'logdetective.server.models'
[ble: exit 1]
```

Hints from issue comments:
@xsuchy: I will work on this.

Solution patch:
diff --git a/logdetective/logdetective.py b/logdetective/logdetective.py
index 3a43254..9de6469 100644
--- a/logdetective/logdetective.py
+++ b/logdetective/logdetective.py
@@ -1,6 +1,7 @@
 import argparse
 import logging
 import sys
+import os
 
 from logdetective.constants import DEFAULT_ADVISOR
 from logdetective.utils import (
@@ -67,7 +68,10 @@ def setup_args():
     parser.add_argument("-v", "--verbose", action="count", default=0)
     parser.add_argument("-q", "--quiet", action="store_true")
     parser.add_argument(
-        "--prompts", type=str, default="", help="Path to prompt configuration file."
+        "--prompts",
+        type=str,
+        default=f"{os.path.dirname(__file__)}/prompts.yml",
+        help="Path to prompt configuration file."
     )
     return parser.parse_args()
 
diff --git a/logdetective/server/server.py b/logdetective/server/server.py
index 0582d3e..aeac924 100644
--- a/logdetective/server/server.py
+++ b/logdetective/server/server.py
@@ -26,10 +26,13 @@ from logdetective.utils import (
     validate_url,
     compute_certainty,
     format_snippets,
-    format_analyzed_snippets,
     load_prompts,
 )
-from logdetective.server.utils import load_server_config, get_log
+from logdetective.server.utils import (
+    load_server_config,
+    get_log,
+    format_analyzed_snippets,
+)
 from logdetective.server.metric import track_request
 from logdetective.server.models import (
     BuildLog,
diff --git a/logdetective/server/utils.py b/logdetective/server/utils.py
index aba49b2..e013745 100644
--- a/logdetective/server/utils.py
+++ b/logdetective/server/utils.py
@@ -1,6 +1,18 @@
 import logging
 import yaml
-from logdetective.server.models import Config
+from logdetective.constants import SNIPPET_DELIMITER
+from logdetective.server.models import Config, AnalyzedSnippet
+
+
+def format_analyzed_snippets(snippets: list[AnalyzedSnippet]) -> str:
+    """Format snippets for submission into staged prompt."""
+    summary = f"\n{SNIPPET_DELIMITER}\n".join(
+        [
+            f"[{e.text}] at line [{e.line_number}]: [{e.explanation.text}]"
+            for e in snippets
+        ]
+    )
+    return summary
 
 
 def load_server_config(path: str | None) -> Config:
diff --git a/logdetective/utils.py b/logdetective/utils.py
index 591e9ca..358dcda 100644
--- a/logdetective/utils.py
+++ b/logdetective/utils.py
@@ -7,8 +7,6 @@ import requests
 import yaml
 
 from llama_cpp import Llama, CreateCompletionResponse, CreateCompletionStreamResponse
-from logdetective.constants import SNIPPET_DELIMITER
-from logdetective.server.models import AnalyzedSnippet
 from logdetective.models import PromptConfig
 
 
@@ -178,17 +176,6 @@ def format_snippets(snippets: list[str] | list[Tuple[int, str]]) -> str:
     return summary
 
 
-def format_analyzed_snippets(snippets: list[AnalyzedSnippet]) -> str:
-    """Format snippets for submission into staged prompt."""
-    summary = f"\n{SNIPPET_DELIMITER}\n".join(
-        [
-            f"[{e.text}] at line [{e.line_number}]: [{e.explanation.text}]"
-            for e in snippets
-        ]
-    )
-    return summary
-
-
 def validate_url(url: str) -> bool:
     """Validate incoming URL to be at least somewhat sensible for log files
     Only http and https protocols permitted. No result, params or query fields allowed.


Test patch:
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 7620613..08040ed 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -3,9 +3,9 @@ import pytest
 from logdetective.utils import (
     compute_certainty,
     format_snippets,
-    format_analyzed_snippets,
     load_prompts,
 )
+from logdetective.server.utils import format_analyzed_snippets
 from logdetective.server.models import AnalyzedSnippet, Explanation
 from logdetective.models import PromptConfig
 from logdetective import constants