From 01a07d45a4bba2fee1ca856ce2610c44c830f27f Mon Sep 17 00:00:00 2001 From: deep-learning-dynamo Date: Mon, 3 Jul 2023 14:51:15 +0200 Subject: [PATCH] allow @Tool methods without parameters (e.g. get current date, time, etc) --- .../src/main/java/dev/langchain4j/agent/tool/Tool.java | 6 ++++++ .../java/dev/langchain4j/model/openai/OpenAiConverters.java | 3 +++ 2 files changed, 9 insertions(+) diff --git a/langchain4j/src/main/java/dev/langchain4j/agent/tool/Tool.java b/langchain4j/src/main/java/dev/langchain4j/agent/tool/Tool.java index 323f789cc..4f0c47467 100644 --- a/langchain4j/src/main/java/dev/langchain4j/agent/tool/Tool.java +++ b/langchain4j/src/main/java/dev/langchain4j/agent/tool/Tool.java @@ -10,7 +10,13 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; @Target({METHOD}) public @interface Tool { + /** + * Name of the tool. If not provided, method name will be used. + */ String name() default ""; + /** + * Description of the tool. LLM should understand what this tool is for and when it should be used. + */ String value() default ""; } diff --git a/langchain4j/src/main/java/dev/langchain4j/model/openai/OpenAiConverters.java b/langchain4j/src/main/java/dev/langchain4j/model/openai/OpenAiConverters.java index 4332d74ff..9233831f6 100644 --- a/langchain4j/src/main/java/dev/langchain4j/model/openai/OpenAiConverters.java +++ b/langchain4j/src/main/java/dev/langchain4j/model/openai/OpenAiConverters.java @@ -88,6 +88,9 @@ class OpenAiConverters { } 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() .properties(toolParameters.properties()) .required(toolParameters.required())