Skip to content

improve lmarena and fix Yupp#3313

Closed
3mora2 wants to merge 0 commit intoxtekky:mainfrom
3mora2:main
Closed

improve lmarena and fix Yupp#3313
3mora2 wants to merge 0 commit intoxtekky:mainfrom
3mora2:main

Conversation

@3mora2
Copy link
Copy Markdown
Contributor

@3mora2 3mora2 commented Jan 2, 2026

No description provided.

@3mora2 3mora2 marked this pull request as draft January 3, 2026 09:19
@3mora2 3mora2 marked this pull request as ready for review January 4, 2026 21:50
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 4, 2026

g4f copilot

Thank you Ammar for contributing to the project! Your extensive work in integrating nodriver with Yupp and LMArena details a sophisticated and thoughtful approach to managing browser automation and network interception.

Your implementation of request interception, stream processing, and custom handlers demonstrates attention to detail and a clear understanding of complex asynchronous workflows. The modular design with context managers and well-structured classes will be very beneficial for robust testing and interaction scenarios.

Key Highlights:

  • The RequestInterception class provides a flexible pattern for capturing and manipulating network requests/responses.
  • The _process_stream_response_ method showcases advanced handling of streaming and chunked data, essential for real-time applications.
  • The custom create_async_browser functions efficiently manage nodriver instances, cookies, and authentication flows.
  • The code structure facilitates reusability, error handling, and clean resource management.

Possible Suggestions:

  • Consider adding inline comments or docstrings for some of the helper functions to improve clarity for future maintainers.
  • Ensure all exception handling within async contexts gracefully cleans up resources to prevent dangling handlers.
  • If applicable, include some unit tests or usage examples that demonstrate key functionalities like request interception or stream processing.

Overall, this is a solid and valuable addition that enhances the project's automation capabilities. Great work!

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 5, 2026

G4F Copilot Review for PR titled "use nodriver in lmarena and Yupp"

Thanks Ammar for contributing to the project! Here's a detailed review of your implementation:

General Feedback:

  • The integration of nodriver into multiple components (Yupp, LMArena, and request handling) is comprehensive and demonstrates a good understanding of both the automation tools and the target services.
  • Your approach of encapsulating request interception and response streaming within context managers (RequestInterception, BaseRequestExpectation) enhances reusability and clarity.
  • The code introduces helpful abstractions like Response, Request, and utility functions for cookie management and navigation, which improve modularity.

Specific Points:

1. Nodriver Integration and Request Handling:

  • The get_args, nodriver_request, and request interception logic are well-structured.
  • Usage of async with context managers for managing browser sessions and request expectations is robust.
  • Consider adding explicit error handling around nodriver operations (e.g., connection drops) for more resilience.

2. Stream processing in _process_stream_response_:

  • The streaming response processing is detailed and handles various line prefixes and data formats.
  • The inline helper extract_ref_id and parsing logic for embedded blocks (like <think> and <yapp>) are effective.
  • It may help to document expected line formats and the purpose of each prefix for future maintainability.

3. HTTP Request Scripts:

  • The nodriver_request function constructs fetch scripts dynamically; ensure all headers and request options are correctly handled especially regarding cookies and redirect policies.
  • The wait_for_ready_state function is useful; verify timeout handling is sufficient for all environments.

4. Auth and Cookie Management:

  • The _start_nodriver() method properly initializes and sets cookies; consider nullable handling for cookie inputs.
  • The _get_captcha() function wraps reCAPTCHA execution well, with timeout handling.

5. Code Consistency & Cleanup:

  • Some commented sections (e.g., in _start_nodriver) can be cleaned up or clarified.
  • Ensure consistent import management and avoid redundant imports.
  • For large nested dictionaries like model mappings, consider loading from a config file or external data source for better maintainability.

6. Error Handling & Robustness:

  • Enhanced exception handling around network and driver operations can improve stability.
  • Consider adding retries for flaky operations (e.g., fetch retries or nodriver reconnects).

7. Documentation & Comments:

  • Adding docstrings to complex functions (especially parsing and interception) will aid future developers.
  • Clarify the purpose of certain parameters (like stream=True) in context managers.

Summary:

Your PR effectively integrates nodriver into the existing framework, offering automation for login, request interception, and streaming responses. With some refinements in error handling, documentation, and configurability, this will be a valuable enhancement.

Thank you once again for your effort. Looking forward to your updates!

Best,
G4F Copilot

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 5, 2026

g4f Copilot Review

Thank you, Ammar, for contributing your substantial updates and improvements to the project!

General Observations & Suggestions

  • The overall structure of the code shows thoughtful integration of nodriver and enhanced request handling, especially in the context of complex streaming responses.
  • The addition of helper functions like set_cookies_for_browser, clear_cookies_for_url, and the custom RequestInterception class significantly boosts modularity and usability for browser automation scenarios.
  • Some areas with extensive inline regex parsing and string manipulations (e.g., in _load_info and _process_stream_response_) could benefit from additional comments or helper methods to improve readability and maintenance.
  • Be cautious with long multi-line string scripts used with page.evaluate(). Ensure proper escaping and validation to prevent runtime issues.

Specific Feedback

Good practices:

  • The use of context managers (async with) for request handling and browser management is excellent for resource safety.
  • The implementation of RequestInterception class provides flexible request/response observing, which is vital in complex streaming scenarios.
  • Handling of cached images with expiry checks helps optimize performance and resource usage (check_link_expiry).

Areas for improvement:

  • Error handling and logging:
    • Consistency in exception messages helps troubleshooting. For example, in prepare_images, catching and re-raising exceptions with more context is recommended.
    • For example, instead of raise Exception("Failed to get upload URL"), include more context or the original response for easier debugging.
  • Consistency in async implementation:
    • Some functions use async def but contain synchronous code or comments (e.g., in get_args). Make sure all async operations are properly awaited and non-async code is minimal.
  • Code readability:
    • Complex inline regex and nested loops in _load_info and _process_stream_response_ can be abstracted into smaller helper functions with descriptive names.
    • Consider adding docstrings for _load_info, _process_stream_response_, and other complex functions to clarify their purpose and flow.
  • Caching and expiry check:
    • The check_link_expiry() function correctly interprets expiry based on X-Amz-Date. Ensure all places using cached images correctly handle expiry status.
  • Security:
    • When handling cookies and sensitive tokens, ensure data is stored securely and not exposed in logs or exceptions.

Overall

Your contribution introduces valuable enhancements, especially around nodriver integration, stream response processing, and browser automation. With some refactoring for clarity and robustness, the code can be even more maintainable and reliable.

Thanks again for your work on this project!


Please implement the suggested improvements for better maintainability and robustness.

Best regards,
g4f Copilot

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 6, 2026

Review of PR: use nodriver in lmarena and Yupp

Thank you Ammar for contributing to the project! Your work significantly enhances the functionality with robust integration of nodriver and improves request handling and streaming capabilities.

Summary of changes

  • Implemented nodriver integration for LMArena and Yupp providers, including functions for managing cookies, requests, and responses.
  • Added classes Request, Response, and BaseRequestExpectation to handle request interception, streaming, and response data extraction.
  • Enhanced image preparation with expiry cache checks, robust multipart upload workflow, and adaptive session handling.
  • Developed context managers for resource management and stream processing of responses, facilitating real-time streaming and request control.
  • Introduced various utility functions (wait_for_ready_state, remove_handlers, click_trunstile, etc.) for better browser interaction and event management.

Notable points

  • The check_link_expiry function now reliably verifies cache validity based on X-Amz-Date and X-Amz-Expires parameters.
  • The create_async_browser method effectively manages login/authentication flow, CAPTCHA retrieval, and request preparation.
  • The streaming response handler _process_stream_response_ meticulously processes different line prefixes and yields appropriate responses, supporting images, reasoning, and conversation updates.
  • The nodriver_request function is carefully crafted to emulate browser fetch behavior, including headers, redirects, and promise handling.
  • Proper resource cleanup methods (cleanup_async_browser, stop_nodriver) ensure session integrity.

Suggestions

  • Consider adding more extensive error handling/logging around network retries or CAPTCHA failures for improved resilience.
  • Document usage of the nodriver functions explicitly for easier onboarding.
  • Verify thread safety if this module is extended for concurrent requests; however, current lock usage appears sufficient.

Thank you again for your detailed and well-structured contribution! It will help tremendously in making the provider integrations more reliable and flexible.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 6, 2026

Review of PR: "use nodriver in lmarena and Yupp"

Thank you Ammar for contributing to the project! Your updates demonstrate considerable effort in integrating nodriver for better automation and streamlining the request handling within both the Yupp and LMArena providers.

Key improvements:

  • Introduced nodriver_request function for standardized request execution using nodriver.
  • Enhanced cookie management with clear_cookies_for_url and set_cookies_for_browser.
  • Added RequestInterception classes for fine-grained request/response handling during browser automation.
  • Updated create_async_browser methods to leverage nodriver for browser interactions, including login and session management.
  • Improved image preparation with expiry check in prepare_images.
  • Refactored stream response handling in _process_stream_response_ for better parsing and error handling.
  • Implemented comprehensive helper functions for navigation, waiting for page load, and mouse interaction simulations (e.g., mouse_click with human-like randomness).

Suggestions:

  • Error Handling & Robustness: You've added try-except blocks; ensure all asynchronous handlers are properly cleanup (e.g., remove handlers on teardown). Consider adding more explicit cleanup or try-finally to prevent event handler leaks.
  • Code Comments & Documentation: Some sections, especially complex asynchronous flows and regex parsing, could benefit from inline comments explaining intent and flow for easier future maintenance.
  • Type Hints & Consistency: The code uses advanced type hints; ensure all functions and class methods consistently specify return types for clarity.
  • Expiry Link Check: The function check_link_expiry appears to parse URLs for expiry validation. Consider integrating this into the cache logic directly to prevent stale entries effectively.
  • Testing & Validation: Given the extensive changes, especially around browser automation, thorough testing on different environments is recommended.

Overall, your implementation significantly enhances the providers' flexibility and robustness with nodriver integration and detailed request handling.

Once again, thank you for your valuable contribution. Keep up the great work!


G4F Copilot

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 6, 2026

Review of Pull Request: use nodriver in lmarena and Yupp

Thank you Ammar for contributing to the project and implementing the integration of nodriver into both lmarena and Yupp providers. Your changes enhance automation and potentially improve testing and interaction capabilities.

Summary of key improvements

  • Added nodriver support to LMArena with functions for starting browser instances, handling cookies, and navigation.
  • Implemented functions for request interception, response handling, and streaming response body via nodriver.
  • Enhanced Yupp provider to utilize nodriver for better request/response management, including response parsing and image URL extraction.
  • Introduced RequestInterception class for flexible request/response monitoring.
  • Added mechanisms for cookie handling, CAPTCHA solving, and session management.
  • Provided prepare_images method that integrates image uploads with expiry checks leveraging check_link_expiry.
  • Created nodriver_request utility for executing fetch requests within the browser context.
  • Implemented helper functions for waiting for page states and cleanup procedures.

Code Quality & Style

  • Overall, the code is well-structured with clear separation of concerns.
  • Usage of type hints and dataclasses improves readability.
  • The addition of detailed comments and inline docstrings is appreciated and aids comprehension.
  • The new nodriver integration is comprehensive and thoughtfully encapsulated.

Suggestions & Improvements

  • Error handling and fallback: Consider adding more robust fallback strategies if nodriver encounters issues, especially in environments where nodriver might not be fully reliable.
  • Testing: Ensure thorough testing exists for create_async_browser and stream handling to confirm performance and stability.
  • Consistency in comments: Some sections have commented-out code or notes that could be cleaned up for clarity.
  • Expiry check function: The check_link_expiry function is a great addition. Make sure the date parsing matches expected format and consider adding timezone considerations if needed.
  • Response stream parsing: In _process_stream_response_, confirm correctness in handling different line prefixes, as response parsing logic is critical.

Final Remarks

This update significantly enhances the providers' capabilities through nodriver, providing more control and automation for browser interactions within the framework. Your attention to detail and clean implementation are commendable.

Thank you again for your valuable contribution!


g4f Copilot

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 6, 2026

G4F Copilot Review

Thank you Ammar for contributing to the project! Your implementation of integrating nodriver to improve interaction with LMArena and Yupp providers is a significant enhancement.

Key Observations:

  • Code Structure & Clarity: The added nodriver_request and associated functions are well-structured, offering a clear pathway for browser automation and request interception.
  • Robustness: The inclusion of error handling, especially within get_args_from_nodriver, helps ensure resilience and fallback mechanisms.
  • Features & Flexibility: Functions like wait_for_ready_state, remove_handlers, and the context managers for request expectations enhance flexibility and control over network interactions.
  • Human-like Interaction: The mouse_click function, with its randomization and delays, effectively mimics human behavior, aiding in bot detection avoidance.

Recommendations:

  • Code Consistency & Documentation: Consider adding more inline comments and docstrings in private methods to improve maintainability.
  • Error Handling: In __load_actions, it might be helpful to log or handle parsing errors gracefully, perhaps with retries or more detailed logs.
  • Test Coverage: Adding unit tests for the new functions, especially the request interception and response streaming, will ensure stability across updates.
  • Cleanup & De-duplication: There are some commented-out code snippets and redundant imports which could be cleaned up to streamline the codebase.

Overall:

The integration of nodriver for managing browser sessions and intercepting network requests is thoughtfully implemented. It will significantly improve automation reliability and mimicry. Excellent work!


Thanks again for your valuable contribution!

@3mora2 3mora2 changed the title use nodriver in lmarena and Yupp improve lmarena and fix Yupp Jan 9, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 9, 2026

Review of PR by Ammar: improve lmarena and fix Yupp

Thank you, Ammar, for your contribution to the project! Your efforts in improving the lmarena provider and fixing issues in the Yupp provider are highly appreciated.

Summary of Changes:

  • Significant enhancements to Yupp.py including addition of new attributes (nodriver, stop_nodriver, _next_actions)
  • Improved request handling and response parsing logic within create_async_generator and prepare_images
  • Refinements to error handling and logging, notably more detailed exception traces
  • Enhanced response parsing in pars_data, with better management of asynchronous streams and error scenarios
  • Introduction of captcha handling and login flow improvements (_start_nodriver, _login)
  • Addition of utility functions (check_link_expiry) and utilities for request interception (Request, Response, BaseRequestExpectation)
  • Updates to nodriver_request for more flexible fetch simulation
  • Modifications to __load_actions for better parsing of embedded JavaScript data

Observations:

  • The code now includes a robust mechanism for managing node driver sessions, including login flow and cookie management.
  • Response streaming and body extraction are more resilient and handle various encoding scenarios.
  • The request interception classes (Request, Response, BaseRequestExpectation) are well-structured, facilitating detailed network expectation handling.
  • Utility functions like check_link_expiry improve cache validity checks, reducing unnecessary re-uploads.
  • The code comments and structure demonstrate good clarity and maintainability.

Recommendations:

  • Consider adding more explicit type hints in some methods for better static analysis.
  • Some commented-out code and duplicate comments (# lines) could be tidied for clarity.
  • Ensure that exception handling blocks (especially in __load_actions) are logged or handled to avoid swallowed errors during parsing.
  • For future enhancements, adding unit tests for request parsing and response handling could further solidify reliability.

Again, thank you for your detailed and impactful update! Your contributions significantly enhance the robustness and flexibility of the providers.

Best,
g4f copilot

@github-actions
Copy link
Copy Markdown

Review of PR: improve lmarena and fix Yupp

Thank you Ammar for your contribution! You've made significant enhancements to the Yupp provider and the LMArena integration, improving robustness, functionality, and code structure.

Highlights

  • Yupp.py updates:

    • Added nodriver, stop_nodriver, and _next_actions attributes with default values for better navigation control.
    • Improved parsing with parsing_data updates, notably capturing 'next_actions'.
    • Extended JSON response handling in create_async_generator() with better error logging, clearer exception messages, and additional response parsing.
    • Enhanced error handling: detailed logs for unexpected errors, including exception types.
    • Added functions for managing images (prepare_images()) with link expiry checks.
    • Implemented new method _prepare_data() for clean request data assembly.
    • Improved stream response handling in _process_stream_response_(), supporting both byte-encoded streams and chunked data, with better JSON parsing.
    • Provided a complete get_args_from_nodriver() method to initialize the browser context, with optional cookie management.
    • Introduced check_link_expiry() for robust cache validation based on URL timestamp data.
    • Added __load_actions() for parsing embedded scripts and extracting actions, making the code more resilient to dynamic content.
  • needs_auth/LMArena.py updates:

    • Overhauled request handling with __load_actions(), _wait_auth(), and improved login and captcha handling.
    • Added sophisticated session start (_start_nodriver()) with cookie and captcha management.
    • Extensive create_async_browser() logic now cleanly manages multiple sessions, including captcha, login, and request preparation.
    • Streamlined image handling, with cache expiry check (check_link_expiry()), and request data assembly.
    • Enhanced error logs and fallback mechanisms.
    • Added @classmethod for _prepare_data() to assemble request payloads in a clean, readable manner.
    • Improved response streaming with response_data_stream() supporting line-by-line handling and stream content extraction.
    • Modularized _get_captcha() and _start_nodriver() for better testability and clarity.
    • Implemented request expectations with a custom BaseRequestExpectation class to await specific network traffic, with clean setup and teardown.
  • nodriver_.py:

    • Complete implementation of request interception, including:
      • Request, Response, and RequestInterception classes with context management.
      • Robust methods for continuing, fulfilling, and fail requests (continue_request(), fulfill_request(), etc.).
      • Response body handling supporting base64 decoding, stream reading (response_body_as_stream()).
      • Helper functions: wait_for_ready_state(), remove_handlers(), and mouse_click() with human-like simulation.
    • Designed with a flexible, reusable pattern that should facilitate advanced request interception and response handling scenarios.
    • Enhanced logging for request handling and stream operations.

Suggestions

  • Consider additional comments/documentation for RequestInterception and BaseRequestExpectation classes for clarity.
  • The link expiry check function check_link_expiry() is a good addition; ensure all cache-related code uses it uniformly.
  • For better maintainability, think about splitting large functions (like _prepare_data()) into smaller, testable units.

Overall

Excellent work! Your changes significantly improve the robustness, extensibility, and clarity of both provider logic and network interception capabilities.

Keep up the great work!


Thanks again for contributing to the project!

@github-actions
Copy link
Copy Markdown

Review of PR: improve lmarena and fix Yupp

Thank you Ammar for your contribution to the project! Your updates significantly enhance the functionality and robustness of the LMArena and Yupp providers.

Major updates and feedback:

  • Enhanced Yupp Provider:

    • Added support for _next_actions to dynamically track various user actions, improving interaction management.
    • Improved JSON parsing in process_content_chunk for clearer error messages.
    • Included careful handling of image URL extraction with fallback keys (signed_url or signedURL).
    • Added detailed exception handling and logging, aiding debugging and stability.
    • Refined request management to ensure consistent stream handling and response parsing.
    • Improved configuration of next_action defaults with inline comments for clarity.
  • LMArena Provider Overhaul:

    • Implemented __load_actions with regex parsing for embedded scripts, enhancing dynamic response handling.
    • Added check_link_expiry function to verify cached URL validity using timestamp parsing, reducing stale data issues.
    • Developed get_args_from_nodriver method to fetch necessary session args and cookies, improving browser automation consistency.
    • Upgraded image upload process:
      • Now checks cached images' expiry before reuse.
      • Improved URL upload process, with better error handling if URL retrieval fails.
    • Refined _prepare_data to correctly set request payload, including model IDs, modes, and conversation/session info.
    • Introduced robust _process_stream_response_ to handle various response prefix lines (a0:, a2:, etc.) for incremental data processing, supporting different response streaming patterns.
    • Added context-managed browser start/stop functions (_start_nodriver, cleanup_async_browser) ensuring resource clean-up.
    • Implemented _wait_auth, _get_captcha, and _login to manage authentication flow via nodriver and embedded CAPTCHA retrieval.
    • Improved error handling in async flows with retries and exception differentiation (e.g., CloudflareError, RateLimitError).

Code improvements:

  • Moved towards async/await consistency throughout the request and driver management code, reducing blocking.
  • Applied regex-based parsing for embedded scripts to better extract _next_actions.
  • Established expiry check (check_link_expiry) to avoid using stale cached images.
  • Added extensive logging for better traceability.
  • Modularized complex methods like _prepare_data and _process_stream_response_ for clarity.

Suggestions:

  • Consider adding more comments/docstrings for clarity on complex regex parsing and the streaming response handling.
  • Review the handling of model_aliases to ensure no missing key issues.
  • Possibly abstract common patterns in captcha/auth handling for reuse.
  • Verify thread-safety if invoking from multiple concurrent contexts.

Overall, this PR demonstrates great attention to detail, enhancing both stability and feature completeness. Well done!


Please let me know if you'd like me to assist with any further refinements or testing.

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