Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Tool interface javadocs and generic types #1575

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ ml-algorithms/build/
plugin/build/
plugin/src/test/resources/bwc/*
.DS_Store
*/bin/
.classpath
.project
.settings
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.ml.common.spi;

import org.opensearch.ml.common.spi.tools.Tool;
Expand All @@ -11,13 +16,13 @@ public interface MLCommonsExtension {

/**
* Get tools.
* @return
* @return A list of provided tools
*/
List<Tool> getTools();

/**
* Get tool factories.
* @return
* @return A list of tool factories
*/
List<Tool.Factory> getToolFactories();
List<Tool.Factory<? extends Tool>> getToolFactories();
}
11 changes: 8 additions & 3 deletions spi/src/main/java/org/opensearch/ml/common/spi/tools/Parser.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.ml.common.spi.tools;

/**
* General parser interface.
* @param <S>
* @param <T>
* @param <S> The input type
* @param <T> The return type
*/
public interface Parser<S, T> {

/**
* Parse input.
* @param input
* @return
* @return output
*/
T parse(S input);
}
20 changes: 12 additions & 8 deletions spi/src/main/java/org/opensearch/ml/common/spi/tools/Tool.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,26 @@ public interface Tool {
/**
* Run tool and return response.
* @param parameters input parameters
* @return
* @param <T>
* @return the tool's output
* @param <T> The output type
*/
default <T> T run(Map<String, String> parameters) {return null;};
default <T> T run(Map<String, String> parameters) {
return null;
};

default <T> void run(Map<String, String> parameters, ActionListener<T> listener) {};

/**
* Set input parser.
* @param parser
*/
default void setInputParser(Parser parser){};
default void setInputParser(Parser<?, ?> parser) {};

/**
* Set output parser.
* @param parser
*/
default void setOutputParser(Parser parser){};
default void setOutputParser(Parser<?, ?> parser) {};

/**
* Get tool name.
Expand Down Expand Up @@ -78,13 +80,15 @@ public interface Tool {
* the tool may end the whole CoT process by returning true.
* @param input
* @param toolParameters
* @return
* @return true as a signal to CoT to end the chain, false to continue CoT
*/
default boolean end(String input, Map<String, String> toolParameters){return false;}
default boolean end(String input, Map<String, String> toolParameters) {
return false;
}

/**
* Tool factory which can create instance of {@link Tool}.
* @param <T>
* @param <T> The subclass this factory produces
*/
interface Factory<T extends Tool> {
T create(Map<String, Object> params);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.ml.common.spi.tools;

import java.lang.annotation.ElementType;
Expand Down
Loading