2.0 KiB
2.0 KiB
System Patterns: PyNamer
Architecture: Command-Line Interface (CLI) tool.
Core Components:
- CLI Parser (
argparse
): Handles command-line arguments (images
,config
,dry-run
,verbose
). - Configuration Loader (
PyYAML
): Loads settings fromconfig.yaml
. - LLM Interaction (
litellm
): Abstracts communication with various LLM providers. Handles API key and endpoint configuration. - Image Processing (
Pillow
):- Opens and reads image files.
- Resizes images exceeding
resize_max_dimension
while maintaining aspect ratio. - Saves the processed image to a specified format (
resize_format
) in memory.
- Encoding (
base64
,io
): Encodes the processed image data for transmission via API. - File System Interaction (
os
,pathlib
): Checks file existence, extracts paths/extensions, renames files. - Filename Cleaning: Simple string manipulation to enforce snake_case and remove invalid characters.
- Logging (
logging
): Provides informative output about the process.
Workflow Pattern:
- Parse CLI arguments.
- Initialize
PyNamer
class with the config path. - Load configuration (
_load_config
). - Set up LLM client (
_setup_llm
), including image resize settings. - Iterate through input image paths provided via CLI.
- For each image:
a. Check existence and supported format (
_is_supported_format
). b. Resize and encode the image (_resize_and_encode_image
). c. Prepare API request payload (prompts + image data). d. Call LLM vialitellm.completion
. e. Extract and clean the suggested filename. f. Construct the new file path. g. If not dry-run, rename the file, handling potential name collisions (rename_image
). h. Log/print the outcome.
Configuration Pattern:
- Centralized YAML file (
config.yaml
) for user-configurable settings (LLM details, API keys, prompts, image processing parameters). - Environment variables can override API keys/endpoints if not set in the config.