fix(openai): add async context manager support - #8040
fix(openai): add async context manager support#8040Vishnu Vardhan (Vishnu3568) wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds async context manager support to the OpenAI model client so it can be used with async with ... to ensure underlying OpenAI resources are closed automatically, and adds tests to validate cleanup and exception propagation behavior.
Changes:
- Implement
__aenter__/__aexit__onBaseOpenAIChatCompletionClientto close the underlying async OpenAI client on context exit. - Add pytest-asyncio tests that verify
OpenAIChatCompletionClientcan be used as an async context manager and thatclose()is awaited even when exceptions occur inside the block.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| python/packages/autogen-ext/tests/models/test_openai_model_client.py | Adds async context manager tests (normal flow + exception flow) for OpenAIChatCompletionClient. |
| python/packages/autogen-ext/src/autogen_ext/models/openai/_openai_client.py | Implements async context manager protocol (__aenter__/__aexit__) that calls close() on exit. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Vishnu Vardhan (@Vishnu3568) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
Why are these changes needed?
Related issue number
Checks