mirror of
https://github.com/amithkoujalgi/ollama4j.git
synced 2025-10-27 22:50:41 +01:00
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:
@@ -209,7 +209,6 @@ To download/pull the model into your Ollama server, run the following command in
|
|||||||
|
|
||||||
```shell
|
```shell
|
||||||
ollama pull mistral
|
ollama pull mistral
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
You can list the models available on your model server by running the following command in your terminal.
|
You can list the models available on your model server by running the following command in your terminal.
|
||||||
|
|||||||
@@ -804,9 +804,21 @@ public class Ollama {
|
|||||||
ocm.setResponse(request.getPrompt());
|
ocm.setResponse(request.getPrompt());
|
||||||
chatRequest.setMessages(msgs);
|
chatRequest.setMessages(msgs);
|
||||||
msgs.add(ocm);
|
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;
|
OllamaChatTokenHandler hdlr = null;
|
||||||
chatRequest.setUseTools(true);
|
chatRequest.setUseTools(true);
|
||||||
chatRequest.setTools(request.getTools());
|
chatRequest.setTools(allTools);
|
||||||
if (streamObserver != null) {
|
if (streamObserver != null) {
|
||||||
chatRequest.setStream(true);
|
chatRequest.setStream(true);
|
||||||
if (streamObserver.getResponseStreamHandler() != null) {
|
if (streamObserver.getResponseStreamHandler() != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user