Skip to content

Conversation

@Snuffy2
Copy link
Contributor

@Snuffy2 Snuffy2 commented Nov 23, 2025

This pull request refactors and improves the core media processing utilities for the MLX OpenAI server, focusing on better type safety, code clarity, and robust resource management. The changes modernize the codebase by adopting newer Python features, improving error handling, and enhancing support for various media formats. The most important changes are grouped below.

General Improvements and Refactoring:

  • Added module-level docstrings and from __future__ import annotations to all core processor files (__init__.py, audio_processor.py, base_processor.py, image_processor.py) for improved clarity and forward compatibility. [1] [2] [3] [4]
  • Updated method signatures throughout the codebase to use modern Python type hints (e.g., str | None, list[str], Any) and clarified return types for better type safety. [1] [2] [3]

Audio and Image Format Handling:

  • Expanded supported audio formats in AudioProcessor to include .m4a, .ogg, .flac, and .aac, and improved format detection logic for URLs and data URLs.
  • Changed image processing to always save images as PNG for consistency, replacing previous JPEG default.

Validation and Error Handling:

  • Enhanced validation logic for both audio and image data, including more comprehensive file signature checks and stricter size limitations. Improved error and exception messages to include error types for easier debugging. [1] [2] [3]
  • Improved error handling in resource cleanup and session management, ensuring exceptions are logged with their types and details.

Resource Management and Caching:

  • Refactored cache and temporary file management to use pathlib.Path for safer file operations and replaced some os calls. Periodic cleanup of old files and cache entries is now more robust. [1] [2]
  • Improved asynchronous context management for processors, including proper implementation of __aenter__ and __aexit__ for resource cleanup.

API and Method Consistency:

  • Standardized method signatures and docstrings for all processors, ensuring consistent documentation and usage patterns across audio and image processing APIs. [1] [2] [3]

These changes collectively make the media processing utilities more robust, maintainable, and easier to use and extend for future development.

@Snuffy2 Snuffy2 force-pushed the Linting/Formatting-of-core-folder branch from dc4fb0f to 9c076c8 Compare November 30, 2025 02:25
@Snuffy2 Snuffy2 force-pushed the Linting/Formatting-of-core-folder branch from 9c076c8 to 76b19bc Compare November 30, 2025 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant