Class CustomFunction
java.lang.Object
com.jackdaw.chatwithnpc.openaiapi.function.CustomFunction
Custom Function Constructor
First, you need to expend this class and implement the execute method.
You will also need to add the description and properties fields.
The description field is a string that describes what the function does.
The properties field is a map of strings that describe the parameters of the function.
The key is the name of the parameter and the value is the description of the parameter.
For example:
public class MyFunction extends CustomFunction { public MyFunction() { description = "This function does something"; properties = Map.of( "param1", Map.of( "description", "This is the first parameter", "type", "string" ), "param2", Map.of( "description", "This is the second parameter" "type", "string" ) ); required = new String[] { "param1", "param2" }; } public Map< String, String > execute(@NotNull ConversationHandler conversation, @NotNull Map args) { // Do something with the arguments } }Then register the function in the FunctionManager class.
FunctionManager.registerFunction("myFunction", new MyFunction());Finally, the function will be automatically called by the OpenAI Assistant (If you register the function for an NPC).
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
description
-
properties
-
required
-
-
Constructor Details
-
CustomFunction
public CustomFunction()
-
-
Method Details
-
execute
public abstract Map<String,String> execute(@NotNull @NotNull ConversationHandler conversation, @NotNull @NotNull Map<String, Object> args) Execute the function. This method will be called by the OpenAI Assistant in a conversation.- Parameters:
conversation
- The conversation handlerargs
- The arguments- Returns:
- The result you want to tell the OpenAI assistant
-