Skip to content

Add async context manager to OpenAI model client - #8103

Open
mikemikimike wants to merge 1 commit into
microsoft:mainfrom
mikemikimike:fix/openai-client-context-manager
Open

Add async context manager to OpenAI model client#8103
mikemikimike wants to merge 1 commit into
microsoft:mainfrom
mikemikimike:fix/openai-client-context-manager

Conversation

@mikemikimike

Copy link
Copy Markdown

Summary

OpenAIChatCompletionClient already exposes an asynchronous close() method, but callers cannot use the client with async with. This change adds the async context manager protocol to the shared OpenAI client base so OpenAI-compatible clients return themselves on entry and close their underlying client on exit.

Testing

  • ruff format --check on the changed source and test files
  • ruff check on the changed source and test files
  • pytest python/packages/autogen-ext/tests/models/test_openai_model_client.py -k async_context_manager --no-cov

Closes #5108.

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.

OpenAIChatCompletionClient should be a ContextManager

1 participant