Refactor Core Logic to Async-Native with Sync Facade#36
Conversation
- Updated `pyproject.toml` with `anyio`, `httpx`, `aiofiles`. - Refactored `src/coreason_optimizer/core/client.py`: - Created `OpenAIClientAsync` and `OpenAIEmbeddingClientAsync` as Async-Native cores. - Created `OpenAIClient` and `OpenAIEmbeddingClient` as Sync Facades using `anyio.run`. - Updated BudgetAware wrappers to be compatible (async wrappers created, sync wrappers preserved). - Updated `src/coreason_optimizer/core/interfaces.py` to include Async protocols. - Updated tests in `tests/core/test_client.py` and `tests/core/test_client_embedding.py` to verify both Async and Sync behavior using `AsyncMock` and `pytest-asyncio`. - Verified no `threading.local` usage. - Ensured strict lifecycle management with `__aenter__` and `__enter__`.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
- Ran `poetry lock` to synchronize `poetry.lock` with `pyproject.toml` changes (added `anyio`, `httpx`, `aiofiles`). - Refactored `src/coreason_optimizer/core/client.py`: - Created `OpenAIClientAsync` and `OpenAIEmbeddingClientAsync` as Async-Native cores. - Created `OpenAIClient` and `OpenAIEmbeddingClient` as Sync Facades using `anyio.run`. - Updated BudgetAware wrappers to be compatible (async wrappers created, sync wrappers preserved). - Updated `src/coreason_optimizer/core/interfaces.py` to include Async protocols. - Updated tests in `tests/core/test_client.py` and `tests/core/test_client_embedding.py` to verify both Async and Sync behavior.
- Added `pytest-asyncio` to `pyproject.toml` dev dependencies and regenerated `poetry.lock`. - Updated `tests/core/test_client_edge_cases.py` to use `AsyncMock` for `OpenAIClient` (which uses `AsyncOpenAI` internally) and support async/await patterns properly. - Updated `tests/test_readme_usage.py` to patch `AsyncOpenAI` instead of `OpenAI` and properly mock async responses. - Verified local tests pass with `pytest-asyncio` mode auto.
- Added `pytest-asyncio` to `pyproject.toml` dev dependencies and regenerated `poetry.lock`. - Updated `tests/core/test_client_edge_cases.py` to use `AsyncMock` for `OpenAIClient` (which uses `AsyncOpenAI` internally) and support async/await patterns properly. - Updated `tests/test_readme_usage.py` to patch `AsyncOpenAI` instead of `OpenAI` and properly mock async responses. - Updated `tests/core/test_client_budget_wrapper.py` to fully cover Sync/Async budget wrappers and `OpenAIClient` exception handling in `__exit__`. - Verified local tests pass with `pytest-asyncio` mode auto. - Ensured strict lifecycle management tests for both sync and async paths.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
* Refactor Core Logic to Async-Native with Sync Facade - Updated `pyproject.toml` with `anyio`, `httpx`, `aiofiles`. - Refactored `src/coreason_optimizer/core/client.py`: - Created `OpenAIClientAsync` and `OpenAIEmbeddingClientAsync` as Async-Native cores. - Created `OpenAIClient` and `OpenAIEmbeddingClient` as Sync Facades using `anyio.run`. - Updated BudgetAware wrappers to be compatible (async wrappers created, sync wrappers preserved). - Updated `src/coreason_optimizer/core/interfaces.py` to include Async protocols. - Updated tests in `tests/core/test_client.py` and `tests/core/test_client_embedding.py` to verify both Async and Sync behavior using `AsyncMock` and `pytest-asyncio`. - Verified no `threading.local` usage. - Ensured strict lifecycle management with `__aenter__` and `__enter__`. * Fix poetry.lock and Refactor Core Logic - Ran `poetry lock` to synchronize `poetry.lock` with `pyproject.toml` changes (added `anyio`, `httpx`, `aiofiles`). - Refactored `src/coreason_optimizer/core/client.py`: - Created `OpenAIClientAsync` and `OpenAIEmbeddingClientAsync` as Async-Native cores. - Created `OpenAIClient` and `OpenAIEmbeddingClient` as Sync Facades using `anyio.run`. - Updated BudgetAware wrappers to be compatible (async wrappers created, sync wrappers preserved). - Updated `src/coreason_optimizer/core/interfaces.py` to include Async protocols. - Updated tests in `tests/core/test_client.py` and `tests/core/test_client_embedding.py` to verify both Async and Sync behavior. * Fix CI issues and Async Mocking - Added `pytest-asyncio` to `pyproject.toml` dev dependencies and regenerated `poetry.lock`. - Updated `tests/core/test_client_edge_cases.py` to use `AsyncMock` for `OpenAIClient` (which uses `AsyncOpenAI` internally) and support async/await patterns properly. - Updated `tests/test_readme_usage.py` to patch `AsyncOpenAI` instead of `OpenAI` and properly mock async responses. - Verified local tests pass with `pytest-asyncio` mode auto. 93770a1
* Refactor Core Logic to Async-Native with Sync Facade - Updated `pyproject.toml` with `anyio`, `httpx`, `aiofiles`. - Refactored `src/coreason_optimizer/core/client.py`: - Created `OpenAIClientAsync` and `OpenAIEmbeddingClientAsync` as Async-Native cores. - Created `OpenAIClient` and `OpenAIEmbeddingClient` as Sync Facades using `anyio.run`. - Updated BudgetAware wrappers to be compatible (async wrappers created, sync wrappers preserved). - Updated `src/coreason_optimizer/core/interfaces.py` to include Async protocols. - Updated tests in `tests/core/test_client.py` and `tests/core/test_client_embedding.py` to verify both Async and Sync behavior using `AsyncMock` and `pytest-asyncio`. - Verified no `threading.local` usage. - Ensured strict lifecycle management with `__aenter__` and `__enter__`. * Fix poetry.lock and Refactor Core Logic - Ran `poetry lock` to synchronize `poetry.lock` with `pyproject.toml` changes (added `anyio`, `httpx`, `aiofiles`). - Refactored `src/coreason_optimizer/core/client.py`: - Created `OpenAIClientAsync` and `OpenAIEmbeddingClientAsync` as Async-Native cores. - Created `OpenAIClient` and `OpenAIEmbeddingClient` as Sync Facades using `anyio.run`. - Updated BudgetAware wrappers to be compatible (async wrappers created, sync wrappers preserved). - Updated `src/coreason_optimizer/core/interfaces.py` to include Async protocols. - Updated tests in `tests/core/test_client.py` and `tests/core/test_client_embedding.py` to verify both Async and Sync behavior. * Fix CI issues and Async Mocking - Added `pytest-asyncio` to `pyproject.toml` dev dependencies and regenerated `poetry.lock`. - Updated `tests/core/test_client_edge_cases.py` to use `AsyncMock` for `OpenAIClient` (which uses `AsyncOpenAI` internally) and support async/await patterns properly. - Updated `tests/test_readme_usage.py` to patch `AsyncOpenAI` instead of `OpenAI` and properly mock async responses. - Verified local tests pass with `pytest-asyncio` mode auto. 93770a1
This PR refactors the core client logic to follow the "Async-Native with Sync Facade" pattern. This ensures better resource management and non-blocking I/O for future async features while maintaining backward compatibility for synchronous scripts.
Key changes:
OpenAIClientAsyncandOpenAIEmbeddingClientAsynchandlingAsyncOpenAIinteractions.OpenAIClientandOpenAIEmbeddingClientfacades that useanyio.runto bridge synchronous calls to the async core.anyio,httpx,aiofiles.PR created automatically by Jules for task 935374347695940404 started by @gowthamrao