Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance providers, improve mobile UI, and refactor image handling #2705

Merged
merged 8 commits into from
Feb 10, 2025

Conversation

kqlio67
Copy link
Contributor

@kqlio67 kqlio67 commented Feb 10, 2025

fix(g4f/Provider/Blackbox.py), (session): Update API request data structure

  • Remove subscriptionStatus from user object in session data
  • Add new top-level isPremium flag to session configuration
  • Include subscriptionCache null field in request payload

feat(g4f/Provider/Blackbox.py): add premium model support and validation

  • Introduce premium_models list and integrate with userSelectedModel
  • Add ModelNotSupportedError import for premium model validation
  • Implement get_models method to mark premium models in listings
  • Update get_model method to handle premium model parsing and validation
  • Add comment annotation for premium model alias claude-3.5-sonnet
  • Include DeepSeek models directly in userSelectedModel list
  • Remove claude-sonnet-3.5 from original agentMode integration

BREAKING CHANGE: Attempting to use models with "(Premium)" suffix now raises ModelNotSupportedError

fix(g4f/Provider/Blackbox.py): update model handling and premium authentication

  • Fix model name capitalization inconsistencies in vision_models and userSelectedModel
  • Restructure premium model handling with corrected casing and placement
  • Simplify get_model() logic using parent class implementation
  • Add fake premium user session data for temporary authentication
  • Include subscription cache with premium status validation timestamps
  • Reorder class properties for better readability

refactor(g4f/Provider/CablyAI.py > g4f/Provider/needs_auth/CablyAI.py): restructure provider and simplify model handling

  • Remove hardcoded api_key attribute from class
  • Remove default_model and fallback_models configurations
  • Remove model_aliases dictionary
  • Remove get_models and get_model class methods
  • Move provider to needs_auth subdirectory
  • Streamline class to focus on async generator creation

fix(g4f/Provider/PollinationsAI.py): Remove duplicate model alias

  • Remove duplicate qwen-2.5-72b alias from text model mappings

feat(g4f/image/copy_images.py): improve image handling with Unicode support and safer encoding

  • Add Unicode-safe filename sanitization using unquote and extended regex patterns
  • Implement proper URL encoding with urllib.parse.quote for filenames and source URLs
  • Refactor image processing flow with improved error handling for IO operations
  • Fix case-insensitive file extension detection with forced lowercase output
  • Simplify URL decoding logic using standard library functions
  • Enhance documentation with detailed docstrings for all public functions
  • Improve BackendApi header/SSL handling with explicit request settings
  • Add comprehensive file format verification after download
  • Optimize filename construction with timestamp-hash structure and clean alt text

(g4f/gui/client/static/css/style.css): Enhance mobile responsiveness and fix layout issues

feat(styles): enhance mobile responsiveness and adaptive layouts

  • Add mobile-first media queries for screens below 768px and 480px
  • Implement flexible grid layouts with wrapping containers and gap adjustments
  • Restructure mobile sidebar positioning and z-index hierarchy
  • Improve form element adaptability with dynamic resizing and text truncation
  • Optimize conversation panel behavior for mobile viewports
  • Enhance input fields and buttons for touch interaction
  • Add responsive model menu handling with ellipsis overflow
  • Implement mobile-specific flex direction changes and order adjustments

fix(layout): correct mobile sidebar positioning

  • Change position from absolute to fixed for mobile-sidebar
  • Adjust right/top positioning and z-index values
  • Fix conversation panel transition animation properties

refactor(responsive): restructure adaptive styles

  • Create dedicated media query sections for mobile breakpoints
  • Reorganize flexible form elements and input areas
  • Standardize responsive unit usage across components
  • Consolidate mobile-specific style overrides

feat(g4f/gui/client/static/js/chat.v1.js): enhance sidebar interactions

  • Add click-outside detection to close mobile sidebar
  • Toggle 'active' class instead of 'shown' for sidebar state
  • Simplify sidebar button rotation logic
  • Improve mobile menu accessibility with proper class handling

Copy link

Review for Pull Request: fix(g4f/gpt4free/g4f/Provider/Blackbox.py), (session): Update API request data structure

Thank you for your contribution to the project! Your changes to the API request data structure are clear and well-implemented. Here are my thoughts on the modifications:

Changes Overview

  • Removal of subscriptionStatus: This change simplifies the user object in the session data, which is a good move if the subscription status is no longer needed.
  • Addition of isPremium flag: Introducing a top-level isPremium flag enhances the clarity of the session configuration, making it easier to determine the user's premium status at a glance.
  • Inclusion of subscriptionCache: Adding a null field for subscriptionCache in the request payload is a thoughtful addition, allowing for future extensibility without breaking existing functionality.

Code Quality

  • The code is clean and follows the existing structure, which is important for maintainability.
  • The use of datetime.now(timezone.utc).isoformat(timespec='milliseconds').replace('+00:00', 'Z') is a good practice for ensuring consistent timestamp formatting.

Suggestions

  • Consider adding a brief comment above the new fields (isPremium and subscriptionCache) to explain their purpose, especially for future maintainers who may not be familiar with the context.

Overall, this is a solid update that improves the API's data structure. Great job!

Looking forward to seeing more contributions from you!

Best,
[Your Name]

@kqlio67 kqlio67 changed the title fix(g4f/gpt4free/g4f/Provider/Blackbox.py), (session): Update API request data structure Updated your Blackbox provider Feb 10, 2025
@kqlio67 kqlio67 changed the title Updated your Blackbox provider Updated Blackbox provider Feb 10, 2025
…): restructure provider and simplify model handling
@kqlio67 kqlio67 changed the title Updated Blackbox provider Updated Blackbox/CablyAI provider Feb 10, 2025
Copy link

Hello @None,

Thank you for your contribution to the project! I've reviewed the changes in your pull request titled "Updated Blackbox/CablyAI provider". Here are some observations and comments:

General Overview

  • Blackbox Provider Changes:

    • The updates to the Blackbox.py file include the removal of the subscriptionStatus from the session data. Additionally, you've introduced a new isPremium flag and the subscriptionCache field. These changes seem to accommodate the updated API request requirements and streamline the session management.
  • CablyAI Provider Refactor:

    • Relocating CablyAI to the needs_auth directory and restructuring it has enhanced clarity in understanding the provider's requirements.
    • By removing the hardcoded API keys and simplifying model handling, you've made the codebase cleaner and more maintainable. The shift in handling model resolutions to favor the parent class implementation is a solid move towards code reusability.

In Detail Comments:

  1. Blackbox Provider (Blackbox.py):

    • The removal of subscriptionStatus from the session data and adding top-level keys aligns with changes to the Blackbox API. This ensures a more accurate reflection of current subscription characteristics in session handling.
    • Assigning isPremium and subscriptionCache is a good approach to handle premium features and caching user subscriptions.
  2. CablyAI Provider Modifications:

    • The relocation and refactoring of CablyAI emphasizes the authentication needs by placing it in the needs_auth directory, creating a more logical structure.
    • Streamlining the headers and leveraging the parent class for model resolutions reduces redundancy and complexity in code.
  3. Documentation and Code Consistency:

    • The documentation changes in providers-and-models.md accurately reflect the updated state of providers and available models.
    • The updates maintain consistency across the project in handling providers' configurations.

Recommendations:

  • Double-check any dependencies or integrations that might have been overlooked during the refactor, especially any external components interfacing with CablyAI.
  • Consider adding unit tests to cover the newly implemented logic changes if not already present, to ensure robust code stability.
  • Ensure that any potential users of deprecated functionalities (like the model aliases) are aware of these changes, possibly through release notes or documentation.

Overall, the changes contribute positively to code quality and maintainability. Good job on this refactor!

Let me know if you have any questions or further concerns. Once again, thank you for your contribution!

Best regards,
g4f copilot

@kqlio67 kqlio67 closed this Feb 10, 2025
@kqlio67 kqlio67 reopened this Feb 10, 2025
Copy link

Pull Request Review: Updated Blackbox/CablyAI Provider

Review by g4f copilot


Summary of Changes:

This pull request introduces key improvements, refactoring, and some breaking changes to the Blackbox and CablyAI providers:

  1. Blackbox Provider:

    • Added support for premium models through a new premium_models list.
    • Introduced the get_models() method to differentiate and mark premium models.
    • Enhanced the get_model() method to handle premium model validation with a ModelNotSupportedError.
    • Updated session data structure:
      • Removed subscriptionStatus.
      • Added isPremium and subscriptionCache fields.
    • Cleaned up the agent and model configurations.
  2. CablyAI Provider:

    • Significant refactor to streamline the provider's structure:
      • Moved to the needs_auth subdirectory for better modularity.
      • Removed model aliasing, hardcoded API keys, and redundant model configuration logic.
    • Simplified the class to focus on async interactions.
  3. Documentation Updates:

    • Updated providers-and-models.md to reflect the above changes.
    • Fixed model/provider usage lists to improve clarity.
  4. Breaking Changes:

    • Attempting to use premium models with a "(Premium)" suffix now raises a ModelNotSupportedError.
    • Removed older model configurations (e.g., o3-mini-low, hermes-3) and CablyAI from non-auth usage.

Feedback:

  • Code Quality: The code changes are well-structured and adhere to consistent formatting. Good modular design is evident, especially with the needs_auth reorganization.
  • Documentation: The updated models/providers documentation is thorough, but consider highlighting the breaking changes in the README or changelog for users upgrading their dependencies.
  • Testing: The changes include significant refactoring. Please verify that:
    1. Premium models work as intended and are correctly filtered.
    2. The transition of CablyAI to needs_auth does not disrupt existing users of the library.
    3. The new session structure (isPremium and subscriptionCache) integrates seamlessly with the Blackbox provider.

Suggestions:

  • Error Messages: For the new ModelNotSupportedError on premium models, consider providing users with guidance, such as a link to documentation or prerequisites for using these models.
  • Backward Compatibility: Breaking changes such as model removal (e.g., hermes-3) should be emphasized in prominent sections of the project documentation.
  • Testing Coverage: If not already done, ensure that sufficient tests cover the new premium model logic and session changes.

Conclusion:

This pull request provides necessary advancements and optimizations for the Blackbox and CablyAI providers while introducing some breaking changes. After verifying the suggestions and ensuring comprehensive testing, this can be safely merged.

Thank you for your hard work on this update and your valuable contributions to the project!

Best regards,
g4f copilot

@kqlio67 kqlio67 changed the title Updated Blackbox/CablyAI provider Updated Blackbox/CablyAI/PollinationsAI provider Feb 10, 2025
Copy link

Pull Request Review for Updated Blackbox/CablyAI/PollinationsAI provider

Thank you for contributing to the project! Below is my detailed review of your pull request:


Summary of Changes

Your pull request introduces important updates to multiple providers (Blackbox, CablyAI, and PollinationsAI). The key changes are as follows:

  1. Provider: Blackbox

    • Bug Fixes:
      • Restructured the session data by removing subscriptionStatus and introducing a new isPremium flag.
      • Capitalization inconsistencies in model names were corrected (e.g., "gpt-4o""GPT-4o").
    • Features:
      • Added support for premium models through the premium_models list.
      • New ModelNotSupportedError raised for invalid premium models.
      • Updated functionality of the get_models() and get_model() methods, marking premium models and validating their usage.
      • Introduced fake session and subscriptionCache for premium sessions.
    • Breaking Change:
      • Models suffixed with "(Premium)" now raise ModelNotSupportedError if conditions are unmet.
    • Code Improvements:
      • Simplified get_model() logic by deferring to the parent class, enhancing maintainability.
  2. Provider Restructure: CablyAI

    • Removed the hard-coded api_key and redundant configurations (default_model, fallback_models, etc.).
    • Refactored the provider into the needs_auth subdirectory, improving clarity and separation of concerns.
    • Simplified the class to focus on async generator creation.
  3. Provider: PollinationsAI

    • Removed a duplicate model alias (qwen-2.5-72b) from text model mappings to prevent conflicts.

Key Strengths of the Changes

  1. Improved Code Organization:

    • Logical restructuring of CablyAI under the needs_auth directory improves clarity for future contributions.
  2. Enhanced Functionality:

    • Introduced cleaner handling of premium models in Blackbox, with clear error management and premium validation.
  3. Bug Fixes & Robustness:

    • Fixed naming inconsistencies and enhanced session simulation for Blackbox, making the provider more robust and consistent.
  4. Documentation Alignment:

    • Updated model listings in providers-and-models.md, ensuring alignment between documentation and implementation.

Suggested Improvements

  1. Documentation Details:

    • The refactoring of the CablyAI provider results in behavior changes. Consider outlining in the description whether any of its features were removed due to this refactor.
  2. Test Coverage:

    • Ensure adequate test cases exist for:
      • Premium model validation (including edge cases).
      • The revised get_models() and get_model() logic.
      • CablyAI functionality post-refactor.
  3. Code Comments:

    • While the PR is generally well-documented, consider adding inline comments for the fake_session and subscriptionCache logic, as this is likely to require further adjustments in the future.

Acceptance Criteria

  • Focus on Compatibility:

    • Ensure the breaking changes introduced in Blackbox (premium model behavior) are backward-compatible or have sufficient migration guides for users.
  • Testing Confirmation:

    • Verify the functionality of all updated and refactored providers via integration and unit tests.

Conclusion

This is a high-impact pull request that significantly enhances functionality, readability, and maintainability across several important providers. Once the above suggestions are addressed (particularly around documentation and testing), this PR should be ready for approval.

Thank you again for your excellent work on this contribution!


Review Status

Pending additional documentation and test coverage.

Best regards,
g4f Copilot

Copy link

Review for Pull Request: Updated Blackbox/CablyAI/PollinationsAI provider

Thank you for contributing to the project! Your pull request introduces several enhancements, bug fixes, and improvements to multiple providers (Blackbox, CablyAI, and PollinationsAI) in the g4f codebase. I appreciate the detailed commit messages and thorough explanation of the changes. Below, you'll find my review of the key updates and suggestions for improvement.


Updates Summary

  1. Blackbox Provider

    • Fixes:
      • Updated API request data structure.
      • Fixed inconsistencies such as capitalization and placement of model names.
    • Features:
      • Added premium model support using premium_models and ModelNotSupportedError.
      • Introduced validation and enhanced functionality in the get_models and get_model methods.
    • Notes:
      • The addition of isPremium and subscriptionCache fields makes premium user simulation straightforward.
    • Suggestions:
      • Consider explicitly documenting examples of when the ModelNotSupportedError would be raised and how to integrate this validation in external tooling.
  2. CablyAI Provider

    • Refactor:
      • Moved CablyAI provider to a needs_auth subdirectory.
      • Simplified and streamlined the provider by removing unnecessary configurations (e.g., api_key, default_model, fallback_models, and model_aliases).
    • Breaking Changes:
      • The provider now explicitly requires authentication for proper usage.
    • Suggestions:
      • Verify that the new directory structure aligns with the team's desired organization for "auth-required" providers.
      • Include comprehensive migration documentation for users upgrading from previous versions where CablyAI relied on fallback_models.
  3. PollinationsAI Provider

    • Fix:
      • Removed duplicate model alias for qwen-2.5-72b to prevent inconsistencies.
    • Suggestions:
      • None—this is a straightforward fix.
  4. Improvements to copy_images.py

    • Enhancements:
      • Unicode-safe filename handling with improved sanitization techniques.
      • Refactored logic for consistent error handling and safer file/URL encoding.
    • Suggestions:
      • Add automated test cases to verify behavior for edge cases (e.g., extremely long filenames, special Unicode symbols, invalid characters, etc.).
      • Include comments to clarify changes to BackendApi support logic.
  5. Documentation Updates

    • Added and corrected multiple model and provider entries in providers-and-models.md.
    • Removed outdated providers and ensured consistency in model listings.
    • Suggestions:
      • Highlight backward-incompatible changes in the documentation. For instance, users of the removed models like claude-sonnet-3.5 (now claude-3.5-sonnet) may need explicit clarification.
      • Review if the updated documentation layout still adheres to the intended guidelines.

Recommendations

  1. Backward Compatibility:

    • Ensure that the breaking changes impacting Blackbox and CablyAI are well-documented in the changelog or migration guide, especially for users who might still rely on removed fallback models.
  2. Test Coverage:

    • Some changes, particularly around the redesigned copy_images.py logic and isPremium flag handling, would benefit from additional test cases to validate expected behavior under various conditions.
  3. Code Readability:

    • Adding more inline comments, especially in areas like fake premium session handling and image URL extraction, would aid future maintainers in understanding your thought process.
  4. Refactor Opportunity:

    • Consider extracting repeated logic in Blackbox related to header configuration and file handling into reusable helper functions to reduce duplication.

Action Items

  • Please ensure that all unit tests and integration tests (if available) are passing for the updated modules.
  • Verify that the breaking changes won’t impact users without proper migration instructions.

Overall, this is a solid PR that adds meaningful improvements to multiple modules while cleaning up unnecessary complexity. Thank you for your hard work and meticulous attention to detail while tackling these enhancements across providers!

Best regards,
g4f Copilot

Copy link

Pull Request Review: Updated Blackbox/CablyAI/PollinationsAI provider

Thank you for submitting this comprehensive pull request and for contributing to the project! After reviewing the code and the accompanying documentation, here is some feedback and considerations:


Summary of Changes in the Pull Request:

Blackbox Provider:

  • Fixes and Enhancements:

    • Adjusted the session data structure: Removed subscriptionStatus and added a new isPremium flag for better session handling.
    • Included subscriptionCache with proper premium subscription timestamp validation.
    • Implemented premium_models list for differentiating premium model support to raise a ModelNotSupportedError for unsupported models.
    • Improved and standardized model capitalization and aliasing (e.g., 'claude-3.5-sonnet' now 'Claude-Sonnet-3.5').
    • Introduced get_models and get_model methods for better premium model validation and filtering.
    • Defined fake session data for premium user authentication.
  • Breaking Change:

    • Attempting to request models with the "(Premium)" suffix raises ModelNotSupportedError.

CablyAI Provider:

  • Structural Changes:
    • Refactored the provider and relocated it to a needs_auth/ subdirectory.
    • Removed hardcoding of api_key, default_model, and configuration-specific parameters in the class.
    • Streamlined the provider functionality to focus solely on async generator creation with improved modularity.

PollinationsAI Provider:

  • Bug Fix:
    • Removed a duplicate qwen-2.5-72b model alias for text model mappings.

Image Handling (copy_images.py):

  • Improvements:
    • Enhanced Unicode-safe filename sanitization using the unquote and updated regex patterns.
    • Added proper URL decoding with urllib.parse functionality.
    • Unified file type verification and extension handling.
    • Optimized image naming using timestamp-hash combinations for uniqueness.
    • Improved error handling and resilience for external IO operations.

Documentation Update:

  • Updated docs/providers-and-models.md to reflect the changes in model support and aliasing across providers.

Review Feedback:

Strengths:

  1. Comprehensive Coverage: This pull request addresses multiple aspects of the project — from API fixes, structural refactoring, to feature enhancements like better premium model handling.
  2. Breaking Changes Properly Documented: It is great to see that the breaking changes introduced are clearly called out.
  3. Improved Resilience: The error handling and validation improvements across multiple components (e.g., copy_images.py) add robustness to the system.
  4. Streamlined Code: Relocating the CablyAI provider to a dedicated needs_auth directory improves module organization and readability.

Suggestions for Improvement:

  1. Code Comments and Documentation:

    • While the code is mostly self-explanatory, the Blackbox provider's session refactor and premium model handling logic could benefit from an additional inline comment or two to aid future maintainers.
    • Similarly, copy_images.py is now more intricate due to the encoding adjustments. Adding brief comments about the rationale for specific regular expressions or transformations would help.
  2. Testing Considerations:

    • Ensure thorough testing of the new functionality for premium model handling (Blackbox.py). Specifically, confirm that errors are being raised and processed correctly for (Premium) models when they are not supported.
    • Some test cases for copy_images.py should verify the Unicode naming logic and its behavior across different operating systems.
    • Verify that the interface changes from removing o3-mini-low or CablyAI-specific fallback restructuring do not inadvertently regress any workflows.
  3. Potential Side Effect:

    • In BlackboxAPI, the new filtered logic in get_models could slightly impact performance for providers with a large set of models. If needed, caching of filtered results may help.
  4. Backend Settings (Fake Premium Data):

    • The introduction of fake premium user data is a useful placeholder, but don't forget to replace this with actual integration with premium-service authentication in production environments.

Acceptance Criteria Checklist:

  • Comprehensive tests are added or existing tests are updated for all changes.
  • Breaking changes are documented appropriately and communicated to the team.
  • All modified code passes linting and style guidelines.
  • Documentation (docs/providers-and-models.md) is consistent with code changes.
  • Manual testing is completed for core areas impacted by the pull request (e.g., GUI image upload, Blackbox provider).

Thank you for your hard work on this pull request! With some minor improvements and testing validations, this update looks ready to be merged.

Best regards,
G4F CoPilot

@hlohaus hlohaus merged commit 34b815b into xtekky:main Feb 10, 2025
1 check passed
@kqlio67 kqlio67 changed the title Updated Blackbox/CablyAI/PollinationsAI provider Enhance providers, improve mobile UI, and refactor image handling Feb 10, 2025
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.

2 participants