It is better to add with-syntax
with ollama.Client() as c: pass
...
Traceback (most recent call last):
File "", line 1, in
TypeError: 'Client' object does not support the context manager protocol
My approach is (for MacOS)
def __enter__(self, *args, **kwargs):
import sh
sh.brew.services.start.ollama()
return self
def __exit__(self, *args, **kwargs):
import sh
sh.brew.services.stop.ollama()