Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import com.microsoft.semantickernel.Kernel;
import com.microsoft.semantickernel.plugin.KernelPlugin;
import com.microsoft.semantickernel.plugin.KernelPluginFactory;
import com.microsoft.semantickernel.semanticfunctions.KernelFunction;
import com.microsoft.semantickernel.semanticfunctions.annotations.DefineKernelFunction;

Expand All @@ -16,6 +17,7 @@ public class Example69_MutableKernelPlugin {
*/
public static void main(String[] args) throws NoSuchMethodException {
System.out.println("======== Example69_MutableKernelPlugin ========");
KernelPluginFactory.setTypeFilterEnable(false);

KernelPlugin plugin = new KernelPlugin("Plugin", "Mutable plugin", null);
plugin.addFunction(KernelFunction.createFromMethod(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.temporal.Temporal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -54,7 +55,13 @@ public class KernelPluginFactory {
private static final CaseInsensitiveMap<Class<?>> COMMON_CLASS_NAMES = new CaseInsensitiveMap<>();
private static final Map<Class<?>, Class<?>> BOXED_FROM_PRIMITIVE = new HashMap<>();

public static final String CLASS_FILTER_ENABLE_PROPERTY = "semantic-kernel.class-filter-enable";
private static Boolean CLASS_FILTER_ENABLE;

static {
CLASS_FILTER_ENABLE = Boolean.parseBoolean(
System.getProperty(CLASS_FILTER_ENABLE_PROPERTY, "true"));

PRIMITIVE_CLASS_NAMES.put("void", void.class);
PRIMITIVE_CLASS_NAMES.put("int", int.class);
PRIMITIVE_CLASS_NAMES.put("double", double.class);
Expand All @@ -76,6 +83,9 @@ public class KernelPluginFactory {
COMMON_CLASS_NAMES.put(List.class.getName(), ArrayList.class);
COMMON_CLASS_NAMES.put(Map.class.getName(), HashMap.class);
COMMON_CLASS_NAMES.put(Set.class.getName(), HashSet.class);
COMMON_CLASS_NAMES.put(Temporal.class.getName(), Temporal.class);
Comment thread
johnoliver marked this conversation as resolved.
COMMON_CLASS_NAMES.put(java.time.OffsetDateTime.class.getName(), java.time.OffsetDateTime.class);
COMMON_CLASS_NAMES.put(java.time.ZonedDateTime.class.getName(), java.time.ZonedDateTime.class);

BOXED_FROM_PRIMITIVE.put(void.class, Void.class);
BOXED_FROM_PRIMITIVE.put(int.class, Integer.class);
Expand All @@ -89,6 +99,10 @@ public class KernelPluginFactory {

}

public static void setTypeFilterEnable(boolean enable) {
KernelPluginFactory.CLASS_FILTER_ENABLE = enable;
}

/**
* Creates a plugin that wraps the specified target object. Methods decorated with
* {@code {@literal @}DefineSKFunction} will be included in the plugin.
Expand Down Expand Up @@ -268,6 +282,9 @@ public static Class<?> getTypeForName(String className) {
}

public static boolean checkClassName(String className) {
if (CLASS_FILTER_ENABLE == false) {
return true;
}
return ClassFilter.CLASS_CHECKER.test(className);
}

Expand Down Expand Up @@ -638,8 +655,8 @@ private static boolean evaluateBlock(String className) {
for (String ban : CLASS_BLOCK_LIST) {
if (className.matches(ban)) {
LOGGER.warn(
"Skipping class not allowed by class block list {}, if you wish to unblock this class update the property: {}",
className, CLASS_BLOCK_LIST_PROPERTY_NAME);
"Skipping class not allowed by class block list {}, if you wish to unblock this class update the property: {}. Filtering can also be controlled with {} and KernelPluginFactory.setTypeFilterEnable",
className, CLASS_BLOCK_LIST_PROPERTY_NAME, CLASS_FILTER_ENABLE_PROPERTY);
return false;
}
}
Expand All @@ -660,8 +677,8 @@ private static boolean evaluateAllow(String className) {
}

LOGGER.warn(
"Skipping class not allowed by class allow list {}, if you wish to allow this class update the property: {}",
className, CLASS_ALLOW_LIST_DEFAULT);
"Skipping class not allowed by class allow list {}, if you wish to allow this class update the property: {}. Filtering can also be controlled with {} and KernelPluginFactory.setTypeFilterEnable",
className, CLASS_ALLOW_LIST_DEFAULT, CLASS_FILTER_ENABLE_PROPERTY);
return false;
}
}
Expand Down