diff --git a/src/main/java/io/github/ollama4j/tools/ReflectionalToolFunction.java b/src/main/java/io/github/ollama4j/tools/ReflectionalToolFunction.java index 397b2f6..8483d84 100644 --- a/src/main/java/io/github/ollama4j/tools/ReflectionalToolFunction.java +++ b/src/main/java/io/github/ollama4j/tools/ReflectionalToolFunction.java @@ -8,6 +8,9 @@ import java.lang.reflect.Method; import java.util.LinkedHashMap; import java.util.Map; +/** + * Specification of a {@link ToolFunction} that provides the implementation via java reflection calling. + */ @Setter @Getter @AllArgsConstructor diff --git a/src/main/java/io/github/ollama4j/tools/annotations/OllamaToolService.java b/src/main/java/io/github/ollama4j/tools/annotations/OllamaToolService.java index 8140f92..5118430 100644 --- a/src/main/java/io/github/ollama4j/tools/annotations/OllamaToolService.java +++ b/src/main/java/io/github/ollama4j/tools/annotations/OllamaToolService.java @@ -1,13 +1,23 @@ package io.github.ollama4j.tools.annotations; +import io.github.ollama4j.OllamaAPI; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Annotates a class that calls {@link io.github.ollama4j.OllamaAPI} such that the Method + * {@link OllamaAPI#registerAnnotatedTools()} can be used to auto-register all provided classes (resp. all + * contained Methods of the provider classes annotated with {@link ToolSpec}). + */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface OllamaToolService { + /** + * @return Classes with no-arg constructor that will be used for tool-registration. + */ Class[] providers(); } diff --git a/src/main/java/io/github/ollama4j/tools/annotations/ToolProperty.java b/src/main/java/io/github/ollama4j/tools/annotations/ToolProperty.java index bd1bf07..28d9acc 100644 --- a/src/main/java/io/github/ollama4j/tools/annotations/ToolProperty.java +++ b/src/main/java/io/github/ollama4j/tools/annotations/ToolProperty.java @@ -5,13 +5,28 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Annotates a Method Parameter in a {@link ToolSpec} annotated Method. A parameter annotated with this annotation will + * be part of the tool description that is sent to the llm for tool-calling. + */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) public @interface ToolProperty { + /** + * @return name of the parameter that is used for the tool description. Has to be set as depending on the caller, + * method name backtracking is not possible with reflection. + */ String name(); + /** + * @return a detailed description of the parameter. This is used by the llm called to specify, which property has + * to be set by the llm and how this should be filled. + */ String desc(); + /** + * @return tells the llm that it has to set a value for this property. + */ boolean required() default true; } diff --git a/src/main/java/io/github/ollama4j/tools/annotations/ToolSpec.java b/src/main/java/io/github/ollama4j/tools/annotations/ToolSpec.java index c8725a4..7f99768 100644 --- a/src/main/java/io/github/ollama4j/tools/annotations/ToolSpec.java +++ b/src/main/java/io/github/ollama4j/tools/annotations/ToolSpec.java @@ -1,15 +1,28 @@ package io.github.ollama4j.tools.annotations; +import io.github.ollama4j.OllamaAPI; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Annotates Methods of classes that should be registered as tools by {@link OllamaAPI#registerAnnotatedTools()} + * automatically. + */ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface ToolSpec { + /** + * @return tool-name that the method should be used as. Defaults to the methods name. + */ String name() default ""; + /** + * @return a detailed description of the method that can be interpreted by the llm, whether it should call the tool + * or not. + */ String desc(); }