Add configurable LM Studio flushing and LLM retries.
This commit is contained in:
@@ -127,3 +127,39 @@ def test_process_batch_is_sequential_reuses_session_and_continues_after_error():
|
||||
assert all(len(call.args[0]) == 1 for call in session.call.call_args_list)
|
||||
assert writer_class.return_value.write.call_count == 2
|
||||
session.close.assert_called_once()
|
||||
|
||||
|
||||
def test_process_batch_flushes_after_configured_attempt_count(monkeypatch):
|
||||
monkeypatch.setattr("photools3.processing.settings.llm_flush_every_photos", 2)
|
||||
|
||||
class FakePhoto:
|
||||
def __init__(self, path):
|
||||
self.path = path
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
return None
|
||||
|
||||
response = LlmResponseCaptionsAndKeywords(caption="Ein Haus", tags=["architektur"])
|
||||
session = MagicMock()
|
||||
session.call.side_effect = [
|
||||
response,
|
||||
RuntimeError("temporary error"),
|
||||
response,
|
||||
response,
|
||||
response,
|
||||
]
|
||||
paths = [Path(f"{i}.jpg") for i in range(5)]
|
||||
|
||||
with (
|
||||
patch("photools3.processing._create_session", return_value=session),
|
||||
patch("photools3.processing.Photo", FakePhoto),
|
||||
patch("photools3.processing.MetadataWriter"),
|
||||
):
|
||||
outcomes = process_batch(paths, ProcessingMode.BOTH)
|
||||
|
||||
assert len(outcomes) == len(paths)
|
||||
assert session.flush_model.call_count == 2
|
||||
session.close.assert_called_once()
|
||||
|
||||
Reference in New Issue
Block a user