Description
The Ollama client currently creates a persistent requests.Session() to improve request performance, but the session is never explicitly closed.
While this is generally acceptable for short-lived executions, it can lead to unnecessary resource usage during long-running watch mode sessions, repeated test runs, or future integrations where multiple client instances may be created.
Improve the client by implementing proper session lifecycle management.
Tasks
- Add an explicit
close() method to the Ollama client.
- (Optional) Implement context manager support using
__enter__() and __exit__().
- Ensure the pipeline properly closes the session after execution.
- Update unit tests to verify that sessions are cleaned up correctly.
- Preserve the existing API and behavior for current users.
Files to Modify
llm/ollama.py
core/pipeline.py
tests/test_ollama.py
Suggested Implementation
Possible approaches include:
- Implement a
close() method that releases the underlying requests.Session.
- Support usage such as:
with OllamaClient(...) as client:
...
- Ensure watch mode and long-running processes clean up resources gracefully on exit.
Acceptance Criteria
Difficulty
Easy
Estimated Time
~30 Minutes
Thank you for contributing to QWENTUS!
Description
The Ollama client currently creates a persistent
requests.Session()to improve request performance, but the session is never explicitly closed.While this is generally acceptable for short-lived executions, it can lead to unnecessary resource usage during long-running watch mode sessions, repeated test runs, or future integrations where multiple client instances may be created.
Improve the client by implementing proper session lifecycle management.
Tasks
close()method to the Ollama client.__enter__()and__exit__().Files to Modify
llm/ollama.pycore/pipeline.pytests/test_ollama.pySuggested Implementation
Possible approaches include:
close()method that releases the underlyingrequests.Session.Acceptance Criteria
close()method.Difficulty
Easy
Estimated Time
~30 Minutes
Thank you for contributing to QWENTUS!