Skip to content

Commit 41b5110

Browse files
committed
fix: skip media files during LLM analysis
Signed-off-by: Makia98 <makia98@foxmail.com>
1 parent fd25398 commit 41b5110

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

src/skillspector/llm_analyzer_base.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,38 @@
4646
CHARS_PER_TOKEN = 4
4747
CHUNK_OVERLAP_LINES = 50
4848

49+
_MEDIA_FILE_EXTENSIONS = (
50+
".png",
51+
".jpg",
52+
".jpeg",
53+
".gif",
54+
".bmp",
55+
".ico",
56+
".webp",
57+
".avif",
58+
".heic",
59+
".heif",
60+
".tif",
61+
".tiff",
62+
".mp3",
63+
".aac",
64+
".flac",
65+
".m4a",
66+
".ogg",
67+
".opus",
68+
".wav",
69+
".mp4",
70+
".m4v",
71+
".avi",
72+
".mov",
73+
".webm",
74+
".mkv",
75+
".mpeg",
76+
".mpg",
77+
".ogv",
78+
".3gp",
79+
)
80+
4981

5082
# ---------------------------------------------------------------------------
5183
# Default structured-output schemas (discovery mode)
@@ -303,6 +335,9 @@ def get_batches(
303335

304336
batches: list[Batch] = []
305337
for path in file_paths:
338+
if path.lower().endswith(_MEDIA_FILE_EXTENSIONS):
339+
logger.info("Skipping media file from LLM analysis: %s", path)
340+
continue
306341
content = file_cache.get(path) or "No content available for this file."
307342
file_findings = findings_by_file.get(path, [])
308343

tests/nodes/test_llm_analyzer_base.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,44 @@ def test_zero_padding(self) -> None:
203203
assert "L11: line10" in result
204204

205205

206+
# ---------------------------------------------------------------------------
207+
# LLMAnalyzerBase.get_batches
208+
# ---------------------------------------------------------------------------
209+
210+
211+
class TestLLMAnalyzerBaseGetBatches:
212+
MODEL = "nvidia/openai/gpt-oss-120b"
213+
214+
@pytest.mark.parametrize(
215+
"path",
216+
[
217+
"assets/demo.gif",
218+
"assets/screenshot.PNG",
219+
"assets/tutorial.mp4",
220+
"assets/voice.mp3",
221+
"assets/photo.webp",
222+
"assets/movie.mkv",
223+
],
224+
)
225+
@patch(MOCK_PATCH_TARGET, _mock_get_chat_model)
226+
def test_media_files_are_skipped(self, path: str) -> None:
227+
analyzer = LLMAnalyzerBase(base_prompt="test", model=self.MODEL)
228+
229+
assert analyzer.get_batches([path], {path: "decoded media data"}) == []
230+
231+
@patch(MOCK_PATCH_TARGET, _mock_get_chat_model)
232+
def test_text_files_and_svg_are_preserved(self) -> None:
233+
analyzer = LLMAnalyzerBase(base_prompt="test", model=self.MODEL)
234+
file_cache = {
235+
"src/main.py": "print('hello')\n",
236+
"assets/icon.svg": '<svg><script>alert("x")</script></svg>',
237+
}
238+
239+
batches = analyzer.get_batches(list(file_cache), file_cache)
240+
241+
assert {batch.file_path for batch in batches} == set(file_cache)
242+
243+
206244
# ---------------------------------------------------------------------------
207245
# LLMAnalyzerBase.build_prompt (default implementation)
208246
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)