mirror of
https://github.com/ollama/ollama-python.git
synced 2026-05-01 11:48:17 +08:00
feat: add __enter__ and __aenter__ for context manager support
Client and AsyncClient had __exit__/__aexit__ and close() methods but were missing __enter__/__aenter__, so `with Client() as c:` and `async with AsyncClient() as c:` would raise TypeError. Closes #532
This commit is contained in:
parent
dbccf192ac
commit
0638e947c6
@ -117,9 +117,15 @@ class BaseClient(contextlib.AbstractContextManager, contextlib.AbstractAsyncCont
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self.close()
|
||||
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
|
||||
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
||||
await self.close()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user