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

refactor: Remove networking imports outside azure core #3683

Merged
merged 13 commits into from
Aug 27, 2024

Conversation

kdestin
Copy link
Contributor

@kdestin kdestin commented Aug 22, 2024

Description

This pull request removes all networking imports flagged by rule C4749(networking-import-outside-azure-core-transport) from azure-pylint-guidelines-checker, and refactors the uses of those imports to do http requests through azure-core.

Concretely this pull request:

  • Adds src/promptflow-evals/promptflow/evals/_http_utils.py which includes a sync and async version of azure.core.pipeline.Pipeline that provides a requests-like api for general http requests.
  • Refactors the sdk and tests to use those pipelines
  • Removes the dependency on aiohttp_retry
  • Remove both duplicate implementations of AsyncHTTPClientWithRetry.

Background

This PR is part of an effort to ready promptflow-evals to be migrated to Azure/azure-sdk-for-python.

Azure SDKs are disallowed from directly using networking libraries like requests, aiohttp, etc... They're instead meant to use azure-core, which under the hood can delegate to those libraries.

All Promptflow Contribution checklist:

  • The pull request does not introduce [breaking changes].
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.
  • I confirm that all new dependencies are compatible with the MIT license.
  • Create an issue and link to the pull request to get dedicated review from promptflow team. Learn more: suggested workflow.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

…pipeline

    The `RetryClient` from `aiohttp_retry` was used extensively through
    promptflow/evals/synthetic to do async http requests. Both directly
    and as the basis of the `AsyncHTTPClientWithRetry` class.

    The two retry strategies used with RetryClient were:
      * Retries with fixed length backoff
      * Retries with jittered exponential backoff

    azure.core pipelines essentially covers those two strategies with
    their (Async)RetryPolicy, with the major difference being that
    the exponential flavor doesn't incorporate random jitter.

    This commit ends up accomplishing the following:
      * All references to RetryClient, and the two duplicate (?)
        implementation of `AsyncHTTPClientWithRetry` were replaced
        with our "requests-like" azure.core.pipeline. Appropriate retry
        policies were applied to replicate the previous functionality.
      * The dependency on `aiohttp_retry` was removed, since the SDK
        no longer references it
@kdestin kdestin requested a review from a team as a code owner August 22, 2024 19:11
@kdestin kdestin changed the title refactor: Remote networking imports outside azure core refactor: Remove networking imports outside azure core Aug 22, 2024
Copy link

github-actions bot commented Aug 22, 2024

promptflow-evals test result

 12 files  ±    0   12 suites  ±0   1h 40m 58s ⏱️ + 1h 22m 48s
 13 tests  -    97   12 ✅  -    98   1 💤 + 1  0 ❌ ±0 
156 runs   - 1 164  144 ✅  - 1 176  12 💤 +12  0 ❌ ±0 

Results for commit ce632fb. ± Comparison against base commit cef8ee5.

This pull request removes 110 and adds 13 tests. Note that renamed tests count towards both.
tests.evals.unittests.test_batch_run_context.TestBatchRunContext ‑ test_batch_timeout_custom
tests.evals.unittests.test_batch_run_context.TestBatchRunContext ‑ test_batch_timeout_default
tests.evals.unittests.test_batch_run_context.TestBatchRunContext ‑ test_with_codeclient
tests.evals.unittests.test_batch_run_context.TestBatchRunContext ‑ test_with_pfclient
tests.evals.unittests.test_built_in_evaluator.TestBuiltInEvaluators ‑ test_fluency_evaluator
tests.evals.unittests.test_built_in_evaluator.TestBuiltInEvaluators ‑ test_fluency_evaluator_empty_string
tests.evals.unittests.test_built_in_evaluator.TestBuiltInEvaluators ‑ test_fluency_evaluator_non_string_inputs
tests.evals.unittests.test_chat_evaluator.TestChatEvaluator ‑ test_conversation_validation_invalid_citations
tests.evals.unittests.test_chat_evaluator.TestChatEvaluator ‑ test_conversation_validation_missing_role
tests.evals.unittests.test_chat_evaluator.TestChatEvaluator ‑ test_conversation_validation_normal
…
tests.evals.e2etests.test_adv_simulator.TestAdvSimulator ‑ test_adv_conversation_sim_responds_with_responses
tests.evals.e2etests.test_adv_simulator.TestAdvSimulator ‑ test_adv_qa_sim_responds_with_one_response
tests.evals.e2etests.test_adv_simulator.TestAdvSimulator ‑ test_adv_rewrite_sim_responds_with_responses
tests.evals.e2etests.test_adv_simulator.TestAdvSimulator ‑ test_adv_sim_init_with_prod_url
tests.evals.e2etests.test_adv_simulator.TestAdvSimulator ‑ test_adv_summarization_jailbreak_sim_responds_with_responses
tests.evals.e2etests.test_adv_simulator.TestAdvSimulator ‑ test_adv_summarization_sim_responds_with_responses
tests.evals.e2etests.test_adv_simulator.TestAdvSimulator ‑ test_incorrect_scenario_raises_error
tests.evals.e2etests.test_evaluate.TestEvaluate ‑ test_evaluate_track_in_cloud
tests.evals.e2etests.test_evaluate.TestEvaluate ‑ test_evaluate_track_in_cloud_no_target
tests.evals.e2etests.test_evaluate.TestEvaluate ‑ test_evaluate_with_content_safety_evaluator
…

♻️ This comment has been updated with latest results.

    pylint "struggles" with decorators, and seems unable to infer
    the parameters of the decorated functions of (Async)HttpPipeline.

    Adding #pylint: disable comments to those invocations that are
    known to be correct
@kdestin kdestin force-pushed the kdestin/remove-networking-imports-outside-azure-core branch from 3fd6b5b to e077ca4 Compare August 22, 2024 21:23
    Removing `aiohttp_retry` means we don't have a guarantee `aiohttp`
@kdestin kdestin force-pushed the kdestin/remove-networking-imports-outside-azure-core branch from e077ca4 to 2b4c502 Compare August 22, 2024 21:39
diondrapeck
diondrapeck previously approved these changes Aug 23, 2024
@kdestin kdestin merged commit 8546ad9 into main Aug 27, 2024
77 checks passed
@kdestin kdestin deleted the kdestin/remove-networking-imports-outside-azure-core branch August 27, 2024 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants