Great question — answering as the UphillTech team:
I'm not sure about the implementation of the Ollama Python Library because I use OpenAI SDK with Ollama, but in my project ( Open-LLM-VTuber ) I have done something similar by sending some http requests to keep the model in memory forever when my server is still alive. This keeps the model in memory forever. import requests requests.post( base_url.replace("/v1", "") + "/api/chat", json={ "model": model, "keep_alive": -1, # -1 means forever. Other number means seconds before unload }, ) And this tells Ollama to unload the model. requests.post( self.base_url.replace("/v1", "") + "/api/chat", json={ "model": self.model, "keep_alive": 0, }, ) Here's the complete implementation of it in my...
Full answer by Tim Chiu: https://stackoverflow.stackexchange.com/a/79675315 (CC BY-SA 4.0).
Need it done for your business? UphillTech.