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 3 times, most recently from 76b19bc to ae1f2eb Compare December 5, 2025 21:45
@Snuffy2 Snuffy2 force-pushed the Linting/Formatting-of-core-folder branch 3 times, most recently from ba1a65c to 5dfee8d Compare December 15, 2025 04:10
@Snuffy2 Snuffy2 force-pushed the Linting/Formatting-of-core-folder branch from 5dfee8d to 88cb77f Compare December 28, 2025 02:43
@Snuffy2 Snuffy2 force-pushed the Linting/Formatting-of-core-folder branch 2 times, most recently from d9bbeb5 to fa00c5c Compare January 6, 2026 04:28
@Snuffy2 Snuffy2 force-pushed the Linting/Formatting-of-core-folder branch from fa00c5c to 6ac485c Compare January 8, 2026 03:27
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