Llm client quality #14
@@ -69,6 +69,7 @@ def _run_keywords_extraction(file_path: Path) -> Any:
|
||||
photo = Photo(file_path)
|
||||
return session.call([photo])
|
||||
|
||||
|
||||
def _run_qa(file_path: Path) -> Any:
|
||||
"""Handles the core logic of loading the photo and calling the LLM."""
|
||||
session = LlmSessionQuality()
|
||||
|
||||
@@ -138,38 +138,38 @@ class LlmSessionCaptionsAndKeywords(LlmSession):
|
||||
model_id=model_id,
|
||||
)
|
||||
|
||||
|
||||
class LlmSessionQuality(LlmSession):
|
||||
|
||||
def __init__(self, temperature: float = settings.llm_default_temperature):
|
||||
super().__init__(
|
||||
system_prompt=(
|
||||
"You are a helpful photographer's assistant that helps to identify "
|
||||
"photos that can be sorted out due to qulity issues:\n"
|
||||
"- Your answer is a simple string that must strictly comply with this scheme: "
|
||||
"'{flag}|{reason}', "
|
||||
"where {flag} and {reason} are placeholders for possible values "
|
||||
"that are explained in the following points.\n"
|
||||
"- {flag} is the general image quality assessment."
|
||||
"It can have the following values:\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"
|
||||
" - `ok`: no issues, photo can be kept.\n"
|
||||
"- {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. "
|
||||
"If there is more than one reason, give a comma-separated list: "
|
||||
"'{flag}|{reason1},{flag}|{reason2},...'. "
|
||||
"Possible reasons for a lower-than-`ok` assessment are:\n"
|
||||
" - `blur`: Obviously mis-focussed or motion-blurred.\n"
|
||||
" - `exposure`: severly under- or over-exposed.\n"
|
||||
" - `style`: photo has severe style issues (beyond paersonal taste)\n"
|
||||
),
|
||||
temperature=temperature
|
||||
)
|
||||
system_prompt=(
|
||||
"You are a helpful photographer's assistant that helps to identify "
|
||||
"photos that can be sorted out due to qulity issues:\n"
|
||||
"- Your answer is a simple string that must strictly comply with this scheme: "
|
||||
"'{flag}|{reason}', "
|
||||
"where {flag} and {reason} are placeholders for possible values "
|
||||
"that are explained in the following points.\n"
|
||||
"- {flag} is the general image quality assessment."
|
||||
"It can have the following values:\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"
|
||||
" - `ok`: no issues, photo can be kept.\n"
|
||||
"- {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. "
|
||||
"If there is more than one reason, give a comma-separated list: "
|
||||
"'{flag}|{reason1},{flag}|{reason2},...'. "
|
||||
"Possible reasons for a lower-than-`ok` assessment are:\n"
|
||||
" - `blur`: Obviously mis-focussed or motion-blurred.\n"
|
||||
" - `exposure`: severly under- or over-exposed.\n"
|
||||
" - `style`: photo has severe style issues (beyond paersonal taste)\n"
|
||||
),
|
||||
temperature=temperature,
|
||||
)
|
||||
|
||||
def call(self, photos: list[Photo], model_id=None):
|
||||
return super().call(
|
||||
prompt="Assess the quality of the following photos to help me decide which ones to sort out",
|
||||
photos=photos,
|
||||
model_id=model_id,
|
||||
)
|
||||
|
||||
prompt="Assess the quality of the following photos to help me decide which ones to sort out",
|
||||
photos=photos,
|
||||
model_id=model_id,
|
||||
)
|
||||
|
||||
@@ -102,7 +102,7 @@ class LlmResponseCaptionsAndKeywords(BaseModel):
|
||||
"A list of keywords that properly tag the photo. "
|
||||
"Allowed keywords: "
|
||||
+ str(load_valid_keywords())
|
||||
.replace("'", "\"")
|
||||
.replace("'", '"')
|
||||
.replace("{", "[")
|
||||
.replace("}", "]")
|
||||
)
|
||||
|
||||
@@ -61,7 +61,9 @@ def test_llm_session_captions_and_keywords_mocked(test_photo):
|
||||
mock_choice = 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_response.choices = [mock_choice]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user