KernelPluginFactory Class

  • java.lang.Object
    • com.microsoft.semantickernel.plugin.KernelPluginFactory

public class KernelPluginFactory

Factory for creating KernelPlugin instances. KernelPlugins can be created from a Java object, from loading a directory of plugins, or from loading plugins from a resource.

Constructor Summary

Constructor Description
KernelPluginFactory()

Method Summary

Modifier and Type Method and Description
static KernelPlugin createFromFunctions(String pluginName, String description, List<KernelFunction<?>> functions)

Initializes the new plugin from the provided name, description, and function collection.

static KernelPlugin createFromFunctions(String pluginName, List<KernelFunction<?>> functions)

Creates a plugin from the provided name and function collection.

static KernelPlugin createFromObject(Class<?> clazz, Object target, String pluginName)

Creates a plugin that wraps the specified target object.

static KernelPlugin createFromObject(Object target, String pluginName)

Creates a plugin that wraps the specified target object.

static java.lang.Class<?> getTypeForName(String className)

Returns the class for the provided type name.

static KernelPlugin importPluginFromDirectory(Path parentDirectory, String pluginDirectoryName, PromptTemplateFactory promptTemplateFactory)

Imports a plugin from a directory.

static KernelPlugin importPluginFromResourcesDirectory(String parentDirectory, String pluginDirectoryName, String functionName, PromptTemplateFactory promptTemplateFactory)

Imports a plugin from a resource directory on the filesystem.

static KernelPlugin importPluginFromResourcesDirectory(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.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Constructor Details

KernelPluginFactory

public KernelPluginFactory()

Method Details

createFromFunctions

public static KernelPlugin createFromFunctions(String pluginName, String description, List> 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.

createFromFunctions

public static KernelPlugin createFromFunctions(String pluginName, List> 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.

createFromObject

public static KernelPlugin createFromObject(Class clazz, Object target, String pluginName)

Creates a plugin that wraps the specified target object. Methods decorated with {@literal @}DefineSKFunction will 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 is null, a plugin name is derived from the type of the target.

Returns:

The new plugin.

createFromObject

public static KernelPlugin createFromObject(Object target, String pluginName)

Creates a plugin that wraps the specified target object. Methods decorated with {@literal @}DefineSKFunction will 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 is null, 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.

importPluginFromDirectory

public static KernelPlugin importPluginFromDirectory(Path parentDirectory, String pluginDirectoryName, 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

public static KernelPlugin importPluginFromResourcesDirectory(String parentDirectory, String pluginDirectoryName, String functionName, PromptTemplateFactory promptTemplateFactory)

Imports a plugin from a resource directory on the filesystem.

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.

importPluginFromResourcesDirectory

public static KernelPlugin importPluginFromResourcesDirectory(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. 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.

Applies to