Refactor tool handling in Ollama class to merge request-specific and globally registered tools into a single list, ensuring original requests remain unmodified. Also, remove unnecessary newline in documentation for model pulling command.

This commit is contained in:
amithkoujalgi
2025-10-23 22:20:24 +05:30
parent 1c1452836d
commit 614f7422b6
2 changed files with 13 additions and 2 deletions

View File

@@ -209,7 +209,6 @@ To download/pull the model into your Ollama server, run the following command in
```shell
ollama pull mistral
```
You can list the models available on your model server by running the following command in your terminal.

View File

@@ -804,9 +804,21 @@ public class Ollama {
ocm.setResponse(request.getPrompt());
chatRequest.setMessages(msgs);
msgs.add(ocm);
// Merge request's tools and globally registered tools into a new list to avoid mutating the
// original request
List<Tools.Tool> allTools = new ArrayList<>();
if (request.getTools() != null) {
allTools.addAll(request.getTools());
}
List<Tools.Tool> registeredTools = this.getRegisteredTools();
if (registeredTools != null) {
allTools.addAll(registeredTools);
}
OllamaChatTokenHandler hdlr = null;
chatRequest.setUseTools(true);
chatRequest.setTools(request.getTools());
chatRequest.setTools(allTools);
if (streamObserver != null) {
chatRequest.setStream(true);
if (streamObserver.getResponseStreamHandler() != null) {