Logging #16

Merged
mathias2784 merged 8 commits from logging into master 2026-10-03 08:24:17 +00:00
3 changed files with 15 additions and 6 deletions
Showing only changes of commit f67b7c37a6 - Show all commits
+1
View File
@@ -10,3 +10,4 @@ wheels/
.venv
.env
logs/
+8 -5
View File
@@ -1,7 +1,9 @@
import logging
from pathlib import Path
from typing import Annotated
import typer
from utils.logging_config import LoggingSettings
from photools3.llm_session import (
LlmSessionCaptionsAndKeywords,
@@ -10,7 +12,8 @@ from photools3.llm_session import (
from photools3.photo import Photo
app = typer.Typer(help="PhotoTools3: A CLI for image processing.")
LoggingSettings()
logger = logging.getLogger(__name__)
@app.callback(invoke_without_command=True)
def main(
@@ -49,16 +52,16 @@ def _run_llm_task(
file_path: Path, session: LlmSessionCaptionsAndKeywords | LlmSessionQuality
):
try:
typer.echo(f"Processing: {file_path}")
logger.info(f"Processing: {file_path}")
photo = Photo(file_path)
result = session.call([photo])
print(result)
logger.info(result)
except FileNotFoundError:
typer.echo(f"Error: File '{file_path}' does not exist.", err=True)
logger.error(f"Error: File '{file_path}' does not exist.")
raise typer.Exit(code=1)
except Exception as e: # noqa: BLE001
typer.echo(f"Error processing image: {e}", err=True)
raise typer.Exit(code=1)
logger.error(f"Error processing image: {e}")
if __name__ == "__main__":
+6 -1
View File
@@ -1,4 +1,5 @@
import json
import logging
import re
import openai
@@ -18,6 +19,8 @@ from photools3.models import (
from photools3.photo import Photo
from photools3.settings import Settings
logger = logging.getLogger(__name__)
settings = Settings() # type: ignore[reportCallIssue]
@@ -83,10 +86,12 @@ class LlmSession:
except (json.JSONDecodeError, ValidationError) as e:
last_error = e
if attempt < max_retries:
logger.info("Chatbot response is invalid; promting to correct ...")
# Prepare a correction prompt
correction_prompt = (
f"The previous response was invalid due to: {e}. "
f"Please provide the corrected JSON based on this content: {json_str if 'json_str' in locals() else 'the original input'}"
f"Please provide the corrected JSON based on this content: "
f"{json_str if 'json_str' in locals() else 'the original input'}"
)
# Append correction prompt as a new user message for the next attempt
request.messages.append(