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
*/
9
package
io.github.ollama4j.tools;
10
11
import
io.github.ollama4j.exceptions.ToolNotFoundException;
12
import
java.util.*;
13
14
public
class
ToolRegistry
{
15
private
final
List<
Tools
.
Tool
> tools =
new
ArrayList<>();
16
17
public
ToolFunction
getToolFunction
(String name)
throws
ToolNotFoundException
{
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
}
io.github.ollama4j.exceptions.ToolNotFoundException
Definition
ToolNotFoundException.java:11
io.github.ollama4j.tools.ToolRegistry
Definition
ToolRegistry.java:14
io.github.ollama4j.tools.ToolRegistry.getToolFunction
ToolFunction getToolFunction(String name)
Definition
ToolRegistry.java:17
io.github.ollama4j.tools.ToolRegistry.clear
void clear()
Definition
ToolRegistry.java:45
io.github.ollama4j.tools.ToolRegistry.addTools
void addTools(List< Tools.Tool > tools)
Definition
ToolRegistry.java:34
io.github.ollama4j.tools.ToolRegistry.addTool
void addTool(Tools.Tool tool)
Definition
ToolRegistry.java:26
io.github.ollama4j.tools.ToolRegistry.getRegisteredTools
List< Tools.Tool > getRegisteredTools()
Definition
ToolRegistry.java:40
io.github.ollama4j.tools.Tools.Tool
Definition
Tools.java:30
io.github.ollama4j.tools.Tools
Definition
Tools.java:23
io.github.ollama4j.tools.ToolFunction
Definition
ToolFunction.java:14
src
main
java
io
github
ollama4j
tools
ToolRegistry.java
Generated by
1.12.0