Ollama4j
A Java library (wrapper/binding) for Ollama server.
Loading...
Searching...
No Matches
ToolRegistry.java
Go to the documentation of this file.
1/*
2 * Ollama4j - Java library for interacting with Ollama server.
3 * Copyright (c) 2025 Amith Koujalgi and contributors.
4 *
5 * Licensed under the MIT License (the "License");
6 * you may not use this file except in compliance with the License.
7 *
8*/
9package io.github.ollama4j.tools;
10
11import io.github.ollama4j.exceptions.ToolNotFoundException;
12import java.util.*;
13
14public class ToolRegistry {
15 private final List<Tools.Tool> tools = new ArrayList<>();
16
18 for (Tools.Tool tool : tools) {
19 if (tool.getToolSpec().getName().equals(name)) {
20 return tool.getToolFunction();
21 }
22 }
23 throw new ToolNotFoundException(String.format("Tool '%s' not found.", name));
24 }
25
26 public void addTool(Tools.Tool tool) {
27 try {
28 getToolFunction(tool.getToolSpec().getName());
29 } catch (ToolNotFoundException e) {
30 tools.add(tool);
31 }
32 }
33
34 public void addTools(List<Tools.Tool> tools) {
35 for (Tools.Tool tool : tools) {
36 addTool(tool);
37 }
38 }
39
40 public List<Tools.Tool> getRegisteredTools() {
41 return tools;
42 }
43
45 public void clear() {
46 tools.clear();
47 }
48}
ToolFunction getToolFunction(String name)
void addTools(List< Tools.Tool > tools)