Class KernelPluginFactory


  • public class KernelPluginFactory
    extends Object
    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 Detail

      • KernelPluginFactory

        public KernelPluginFactory()
    • Method Detail

      • 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.
      • 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.
      • 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,
                                                                      @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.