allow @Tool methods without parameters (e.g. get current date, time, etc)

This commit is contained in:
deep-learning-dynamo 2023-07-03 14:51:15 +02:00
parent 087bcd3676
commit 01a07d45a4
2 changed files with 9 additions and 0 deletions

View File

@ -10,7 +10,13 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Target({METHOD}) @Target({METHOD})
public @interface Tool { public @interface Tool {
/**
* Name of the tool. If not provided, method name will be used.
*/
String name() default ""; String name() default "";
/**
* Description of the tool. LLM should understand what this tool is for and when it should be used.
*/
String value() default ""; String value() default "";
} }

View File

@ -88,6 +88,9 @@ class OpenAiConverters {
} }
private static dev.ai4j.openai4j.chat.Parameters toOpenAiParameters(ToolParameters toolParameters) { private static dev.ai4j.openai4j.chat.Parameters toOpenAiParameters(ToolParameters toolParameters) {
if (toolParameters == null) {
return dev.ai4j.openai4j.chat.Parameters.builder().build();
}
return dev.ai4j.openai4j.chat.Parameters.builder() return dev.ai4j.openai4j.chat.Parameters.builder()
.properties(toolParameters.properties()) .properties(toolParameters.properties())
.required(toolParameters.required()) .required(toolParameters.required())