Class KernelPluginFactory
- java.lang.Object
-
- com.microsoft.semantickernel.plugin.KernelPluginFactory
-
public class KernelPluginFactory extends Object
Factory for creatingKernelPlugininstances.KernelPlugins can be created from a Java object, from loading a directory of plugins, or from loading plugins from a resource.
-
-
Constructor Summary
Constructors Constructor Description KernelPluginFactory()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static KernelPlugincreateFromFunctions(String pluginName, String description, List<KernelFunction<?>> functions)Initializes the new plugin from the provided name, description, and function collection.static KernelPlugincreateFromFunctions(String pluginName, List<KernelFunction<?>> functions)Creates a plugin from the provided name and function collection.static KernelPlugincreateFromObject(Class<?> clazz, Object target, String pluginName)Creates a plugin that wraps the specified target object.static KernelPlugincreateFromObject(Object target, String pluginName)Creates a plugin that wraps the specified target object.static Class<?>getTypeForName(String className)Returns the class for the provided type name.static KernelPluginimportPluginFromDirectory(Path parentDirectory, String pluginDirectoryName, PromptTemplateFactory promptTemplateFactory)Imports a plugin from a directory.static KernelPluginimportPluginFromResourcesDirectory(String parentDirectory, String pluginDirectoryName, String functionName, PromptTemplateFactory promptTemplateFactory)static KernelPluginimportPluginFromResourcesDirectory(String parentDirectory, String pluginDirectoryName, String functionName, PromptTemplateFactory promptTemplateFactory, Class<?> clazz)Imports a plugin from a resource directory, which may be on the classpath or filesystem.
-
-
-
Method Detail
-
createFromObject
public static KernelPlugin createFromObject(Object target, String pluginName)
Creates a plugin that wraps the specified target object. Methods decorated with{@literal @}DefineSKFunctionwill be included in the plugin.- Parameters:
target- The instance of the class to be wrapped.pluginName- Name of the plugin for function collection and prompt templates. If the value isnull, a plugin name is derived from the type of the target.- Returns:
- The new plugin.
-
createFromObject
public static KernelPlugin createFromObject(Class<?> clazz, Object target, String pluginName)
Creates a plugin that wraps the specified target object. Methods decorated with{@literal @}DefineSKFunctionwill be included in the plugin.- Parameters:
clazz- The class to be wrapped.target- The instance of the class to be wrapped.pluginName- Name of the plugin for function collection and prompt templates. If the value isnull, a plugin name is derived from the type of the target.- Returns:
- The new plugin.
-
getTypeForName
public static Class<?> getTypeForName(String className)
Returns the class for the provided type name.- Parameters:
className- The type name.- Returns:
- The class for the type name.
-
createFromFunctions
public static KernelPlugin createFromFunctions(String pluginName, @Nullable List<KernelFunction<?>> functions)
Creates a plugin from the provided name and function collection.- Parameters:
pluginName- The name for the plugin.functions- The initial functions to be available as part of the plugin.- Returns:
- The new plugin.
-
createFromFunctions
public static KernelPlugin createFromFunctions(String pluginName, @Nullable String description, @Nullable List<KernelFunction<?>> functions)
Initializes the new plugin from the provided name, description, and function collection.- Parameters:
pluginName- The name for the plugin.description- A description of the plugin.functions- The initial functions to be available as part of the plugin.- Returns:
- The new plugin.
-
importPluginFromDirectory
public static KernelPlugin importPluginFromDirectory(Path parentDirectory, String pluginDirectoryName, @Nullable PromptTemplateFactory promptTemplateFactory)
Imports a plugin from a directory. The directory should contain subdirectories, each of which contains a prompt template and a configuration file. The configuration file should be named "config.json" and the prompt template should be named "skprompt.txt".- Parameters:
parentDirectory- The parent directory containing the plugin directories.pluginDirectoryName- The name of the plugin directory.promptTemplateFactory- The factory to use for creating prompt templates.- Returns:
- The imported plugin.
-
importPluginFromResourcesDirectory
@Nullable public static KernelPlugin importPluginFromResourcesDirectory(String parentDirectory, String pluginDirectoryName, String functionName, @Nullable PromptTemplateFactory promptTemplateFactory)
- Parameters:
parentDirectory- The parent directory containing the plugin directories.pluginDirectoryName- The name of the plugin directory.functionName- The name of the function to import.promptTemplateFactory- The factory to use for creating prompt templates.- Returns:
- The imported plugin.
- See Also:
importPluginFromResourcesDirectory(String, String, String, PromptTemplateFactory, Class)
-
importPluginFromResourcesDirectory
@Nullable public static KernelPlugin importPluginFromResourcesDirectory(String parentDirectory, String pluginDirectoryName, String functionName, @Nullable PromptTemplateFactory promptTemplateFactory, @Nullable Class<?> clazz)
Imports a plugin from a resource directory, which may be on the classpath or filesystem. The directory should contain subdirectories, each of which contains a prompt template and a configuration file. The configuration file should be named "config.json" and the prompt template should be named "skprompt.txt".- Parameters:
parentDirectory- The parent directory containing the plugin directories.pluginDirectoryName- The name of the plugin directory.functionName- The name of the function to import.promptTemplateFactory- The factory to use for creating prompt templates.clazz- The class to use for loading resources. If null, the classloader will be used.- Returns:
- The imported plugin.
-
-