Logging #16

Merged
mathias2784 merged 8 commits from logging into master 2026-10-03 08:24:17 +00:00
4 changed files with 33 additions and 30 deletions
Showing only changes of commit 79655633d0 - Show all commits
+1
View File
@@ -69,6 +69,7 @@ def _run_keywords_extraction(file_path: Path) -> Any:
photo = Photo(file_path) photo = Photo(file_path)
return session.call([photo]) return session.call([photo])
def _run_qa(file_path: Path) -> Any: def _run_qa(file_path: Path) -> Any:
"""Handles the core logic of loading the photo and calling the LLM.""" """Handles the core logic of loading the photo and calling the LLM."""
session = LlmSessionQuality() session = LlmSessionQuality()
+28 -28
View File
@@ -138,38 +138,38 @@ class LlmSessionCaptionsAndKeywords(LlmSession):
model_id=model_id, model_id=model_id,
) )
class LlmSessionQuality(LlmSession): class LlmSessionQuality(LlmSession):
def __init__(self, temperature: float = settings.llm_default_temperature): def __init__(self, temperature: float = settings.llm_default_temperature):
super().__init__( super().__init__(
system_prompt=( system_prompt=(
"You are a helpful photographer's assistant that helps to identify " "You are a helpful photographer's assistant that helps to identify "
"photos that can be sorted out due to qulity issues:\n" "photos that can be sorted out due to qulity issues:\n"
"- Your answer is a simple string that must strictly comply with this scheme: " "- Your answer is a simple string that must strictly comply with this scheme: "
"'{flag}|{reason}', " "'{flag}|{reason}', "
"where {flag} and {reason} are placeholders for possible values " "where {flag} and {reason} are placeholders for possible values "
"that are explained in the following points.\n" "that are explained in the following points.\n"
"- {flag} is the general image quality assessment." "- {flag} is the general image quality assessment."
"It can have the following values:\n" "It can have the following values:\n"
" - `not_ok`: photo lacks basic quality and should almost certainly be deleted.\n" " - `not_ok`: photo lacks basic quality and should almost certainly be deleted.\n"
" - `review`: photo has some quality issues, not severe but might be deleted.\n" " - `review`: photo has some quality issues, not severe but might be deleted.\n"
" - `ok`: no issues, photo can be kept.\n" " - `ok`: no issues, photo can be kept.\n"
"- {reason} is the reason for the photo being flagged as `not_ok` or `review`. " "- {reason} is the reason for the photo being flagged as `not_ok` or `review`. "
"Thus, for any photo that is not `ok`, one or more reasons have to be given. " "Thus, for any photo that is not `ok`, one or more reasons have to be given. "
"If there is more than one reason, give a comma-separated list: " "If there is more than one reason, give a comma-separated list: "
"'{flag}|{reason1},{flag}|{reason2},...'. " "'{flag}|{reason1},{flag}|{reason2},...'. "
"Possible reasons for a lower-than-`ok` assessment are:\n" "Possible reasons for a lower-than-`ok` assessment are:\n"
" - `blur`: Obviously mis-focussed or motion-blurred.\n" " - `blur`: Obviously mis-focussed or motion-blurred.\n"
" - `exposure`: severly under- or over-exposed.\n" " - `exposure`: severly under- or over-exposed.\n"
" - `style`: photo has severe style issues (beyond paersonal taste)\n" " - `style`: photo has severe style issues (beyond paersonal taste)\n"
), ),
temperature=temperature temperature=temperature,
) )
def call(self, photos: list[Photo], model_id=None): def call(self, photos: list[Photo], model_id=None):
return super().call( return super().call(
prompt="Assess the quality of the following photos to help me decide which ones to sort out", prompt="Assess the quality of the following photos to help me decide which ones to sort out",
photos=photos, photos=photos,
model_id=model_id, model_id=model_id,
) )
+1 -1
View File
@@ -102,7 +102,7 @@ class LlmResponseCaptionsAndKeywords(BaseModel):
"A list of keywords that properly tag the photo. " "A list of keywords that properly tag the photo. "
"Allowed keywords: " "Allowed keywords: "
+ str(load_valid_keywords()) + str(load_valid_keywords())
.replace("'", "\"") .replace("'", '"')
.replace("{", "[") .replace("{", "[")
.replace("}", "]") .replace("}", "]")
) )
+3 -1
View File
@@ -61,7 +61,9 @@ def test_llm_session_captions_and_keywords_mocked(test_photo):
mock_choice = MagicMock() mock_choice = MagicMock()
mock_message = MagicMock() mock_message = MagicMock()
mock_message.content = '{"caption": "A mocked caption", "tags": ["architektur"]}' mock_message.content = (
'{"caption": "A mocked caption", "tags": ["architektur"]}'
)
mock_choice.message = mock_message mock_choice.message = mock_message
mock_response.choices = [mock_choice] mock_response.choices = [mock_choice]