Add support for model Load and Unload endpoints#13
Add support for model Load and Unload endpoints#13Avendor7 wants to merge 8 commits intoArdaGnsrn:masterfrom
Conversation
…nd `UnloadModelResponse`, adding support for the new `load` and `unload` methods.
…odel load and unload responses.
… and adjust `load` and `unload` methods for API consistency
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for loading and unloading models into and out of memory by implementing new load() and unload() methods in the Models resource. The implementation includes proper response classes, contract updates, tests, and documentation.
- Adds
load()andunload()methods to the Models resource - Creates dedicated response classes for both operations
- Updates the ModelsContract interface to include the new methods
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Resources/Models.php | Implements load() and unload() methods using the generate endpoint |
| src/Contracts/ModelsContract.php | Adds method signatures for load() and unload() operations |
| src/Responses/Models/LoadModelResponse.php | Response class for model loading operations |
| src/Responses/Models/UnloadModelResponse.php | Response class for model unloading operations |
| tests/OllamaTest.php | Test cases for both load and unload functionality |
| README.md | Documentation for the new load() and unload() methods |
Comments suppressed due to low confidence (1)
src/Responses/Models/UnloadModelResponse.php:23
- There's an unnecessary trailing comma after the last parameter in the constructor.
)
| { | ||
| $response = $this->ollamaClient->post('generate', [ | ||
| 'model' => $modelName, | ||
| ]); |
There was a problem hiding this comment.
The $verbose parameter is defined but never used in the method implementation. Either remove the unused parameter or implement its functionality.
| { | |
| $response = $this->ollamaClient->post('generate', [ | |
| 'model' => $modelName, | |
| ]); | |
| { | |
| if ($verbose) { | |
| error_log("Loading model: " . $modelName); | |
| } | |
| $response = $this->ollamaClient->post('generate', [ | |
| 'model' => $modelName, | |
| ]); | |
| if ($verbose) { | |
| error_log("Model loaded successfully: " . $modelName); | |
| } |
| */ | ||
| public function load(string $modelName, bool $verbose = false): LoadModelResponse | ||
| { | ||
| $response = $this->ollamaClient->post('generate', [ |
There was a problem hiding this comment.
Using the 'generate' endpoint for loading models is unconventional. Consider using a dedicated '/api/load' endpoint if available, or document why the generate endpoint is used for this purpose.
| $response = $this->ollamaClient->post('generate', [ | |
| // Use the dedicated 'load' endpoint if available, otherwise document why 'generate' is used. | |
| $response = $this->ollamaClient->post('load', [ |
| $response = $this->ollamaClient->post('generate', [ | ||
| 'model' => $modelName, | ||
| 'keep_alive' => 0, |
There was a problem hiding this comment.
Using the 'generate' endpoint for unloading models is unconventional. Consider using a dedicated '/api/unload' endpoint if available, or document why the generate endpoint is used for this purpose.
| $response = $this->ollamaClient->post('generate', [ | |
| 'model' => $modelName, | |
| 'keep_alive' => 0, | |
| // Use the dedicated '/api/unload' endpoint for unloading models. | |
| $response = $this->ollamaClient->post('unload', [ | |
| 'model' => $modelName, |
| * @return LoadModelResponse | ||
| */ | ||
| public function load(string $modelName): LoadModelResponse; |
There was a problem hiding this comment.
The contract method signature doesn't include the $verbose parameter that's present in the implementation, creating an inconsistency between the contract and implementation.
| * @return LoadModelResponse | |
| */ | |
| public function load(string $modelName): LoadModelResponse; | |
| * @param bool $verbose | |
| * @return LoadModelResponse | |
| */ | |
| public function load(string $modelName, bool $verbose = false): LoadModelResponse; |
Adds $client->models()->load() and $client->models()->unload() functions for loading and unloading models into and out of memory
Code follows existing style and adds tests