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

feat: Add async client #9

Merged
merged 9 commits into from
Jan 13, 2025
Merged

feat: Add async client #9

merged 9 commits into from
Jan 13, 2025

Conversation

vblagoje
Copy link
Owner

@vblagoje vblagoje commented Jan 10, 2025

Why:

Introduces asynchronous client capabilities to handle OpenAPI interactions for improved performance and scalability. This enhancement addresses the need for async operations when working with APIs in a non-blocking fashion.

What:

  • Added AsyncOpenAPIClient: A new asynchronous client class to perform OpenAPI operations.
  • Updated README.md: Included documentation and examples for the newly introduced async client patterns.
  • Modified dependencies in pyproject.toml to include aiohttp for async HTTP client support.

How can it be used:

The async client can be used in three main ways, as shown in the examples below:

  1. Using async context manager:

    async with AsyncOpenAPIClient(config) as service_api:
        service_response = await service_api.invoke(response)
  2. Using setup/cleanup explicitly:

    service_api = AsyncOpenAPIClient(config)
    await service_api.setup()
    service_response = await service_api.invoke(response)
    await service_api.cleanup()
  3. With a shared aiohttp session:

    async with aiohttp.ClientSession() as session:
        await service_api.setup(session=session)
        service_response = await service_api.invoke(response)

How did you test it:

Unit and integration tests have been added, such as test/test_openapi_client_live_openai_async.py, which validate the async client's ability to handle API interactions under various scenarios, ensuring correct functionality and error handling.

Notes for the reviewer:

Ensure environment variables like OPENAI_API_KEY and SERPERDEV_API_KEY are set for the tests. Focus on the proper handling of async context management and the sessions' lifecycle within the AsyncOpenAPIClient class.

@coveralls
Copy link

coveralls commented Jan 10, 2025

Pull Request Test Coverage Report for Build 12723623819

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+2.7%) to 84.016%

Totals Coverage Status
Change from base Build 12712525336: 2.7%
Covered Lines: 410
Relevant Lines: 488

💛 - Coveralls

@vblagoje vblagoje merged commit 94cbb89 into main Jan 13, 2025
7 checks passed
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.

Feature Request: Async suppport
2 participants