diff --git a/packages/openai-sdk-python/src/supermemory_openai/memory_client.py b/packages/openai-sdk-python/src/supermemory_openai/memory_client.py index 06e1ed89..fa30ca0a 100644 --- a/packages/openai-sdk-python/src/supermemory_openai/memory_client.py +++ b/packages/openai-sdk-python/src/supermemory_openai/memory_client.py @@ -42,6 +42,10 @@ class MemoryClient: async def __aexit__(self, *args): """Async context manager exit - cleanup client.""" + await self.aclose() + + async def aclose(self): + """Close the httpx client.""" if self._client: await self._client.aclose() self._client = None diff --git a/packages/openai-sdk-python/src/supermemory_openai/wrapper.py b/packages/openai-sdk-python/src/supermemory_openai/wrapper.py index 4c8131a9..12155fb2 100644 --- a/packages/openai-sdk-python/src/supermemory_openai/wrapper.py +++ b/packages/openai-sdk-python/src/supermemory_openai/wrapper.py @@ -105,6 +105,11 @@ class SupermemoryOpenAIWrapper: self._executor.shutdown(wait=True) self._executor = None + async def aclose(self) -> None: + """Async cleanup of resources.""" + await self.memory_client.aclose() + self.close() + def __enter__(self): """Context manager entry.""" return self @@ -113,6 +118,14 @@ class SupermemoryOpenAIWrapper: """Context manager exit - cleanup resources.""" self.close() + async def __aenter__(self): + """Async context manager entry.""" + return self + + async def __aexit__(self, *args): + """Async context manager exit - cleanup resources.""" + await self.aclose() + async def _add_memory_if_needed(self, messages: List[ChatCompletionMessageParam]) -> None: """Add conversation to memory if configured to do so.""" if self.options.add_memory != "always":