Extends chat API to automatically load registered Tools

This commit is contained in:
Markus Klenke
2024-12-04 09:12:55 +01:00
committed by Markus Klenke
parent 903a8176cd
commit e9c33ab0b2
3 changed files with 29 additions and 2 deletions

View File

@@ -775,8 +775,8 @@ public class OllamaAPI {
result = requestCaller.callSync(request);
}
//add registered Tools to Request
// add all registered tools to Request
request.setTools(toolRegistry.getRegisteredSpecs().stream().map(Tools.ToolSpecification::getToolPrompt).collect(Collectors.toList()));
return new OllamaChatResult(result.getResponse(), result.getResponseTime(), result.getHttpStatusCode(), request.getMessages());
}

View File

@@ -1,5 +1,6 @@
package io.github.ollama4j.tools;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@@ -14,4 +15,8 @@ public class ToolRegistry {
public void addTool (String name, Tools.ToolSpecification specification) {
tools.put(name, specification);
}
public Collection<Tools.ToolSpecification> getRegisteredSpecs(){
return tools.values();
}
}