KernelHooks Class
- java.
lang. Object - com.
microsoft. semantickernel. hooks. KernelHooks
- com.
public class KernelHooks
Represents a collection of hooks that can be used to intercept and modify events in the kernel.
Constructor Summary
Constructor | Description |
---|---|
KernelHooks() |
Creates a new instance of the KernelHooks class. |
KernelHooks(KernelHooks kernelHooks) |
Creates a copy of the KernelHooks. |
KernelHooks(Map<String,KernelHook<?>> hooks) |
Creates a new instance of the KernelHooks class from the given hooks. |
Method Summary
Modifier and Type | Method and Description |
---|---|
T |
executeHooks(T event)
Executes the hooks in this collection that accept the event. |
java.lang.String |
addFunctionInvokedHook(Function<FunctionInvokedEvent<?>,FunctionInvokedEvent<?>> function)
Add a FunctionInvokedHook to the collection of hooks. |
java.lang.String |
addFunctionInvokingHook(Function<FunctionInvokingEvent<?>,FunctionInvokingEvent<?>> function)
Add a FunctionInvokingHook to the collection of hooks. |
java.lang.String |
addHook(KernelHook<?> hook)
Add a KernelHook<T> to the collection of hooks. |
java.lang.String |
addHook(String hookName, KernelHook<?> hook)
Add a KernelHook<T> to the collection of hooks. |
Kernel |
addHooks(KernelHooks kernelHooks)
Appends the given hooks to this collection. |
java.lang.String |
addPostChatCompletionHook(Function<PostChatCompletionEvent,PostChatCompletionEvent> function)
Add a PostChatCompletionEvent to the collection of hooks. |
java.lang.String |
addPreChatCompletionHook(Function<PreChatCompletionEvent,PreChatCompletionEvent> function)
Add a PreChatCompletionHook to the collection of hooks. |
java.lang.String |
addPreToolCallHook(Function<PreToolCallEvent,PreToolCallEvent> function)
Add a PreToolCallHook to the collection of hooks. |
java.lang.String |
addPromptRenderedHook(Function<PromptRenderedEvent,PromptRenderedEvent> function)
Add a PromptRenderedHook to the collection of hooks. |
java.lang.String |
addPromptRenderingHook(Function<PromptRenderingEvent,PromptRenderingEvent> function)
Add a PromptRenderingHook to the collection of hooks. |
protected
java.util.Map<java.lang.String,Kernel |
getHooks()
Gets the hooks in this collection. |
boolean |
isEmpty()
Determines if this collection of hooks is empty. |
static
Kernel |
merge(KernelHooks a, KernelHooks b)
Builds the list of hooks to be invoked for the given context, by merging the hooks in this collection with the hooks in the context. |
Kernel |
removeHook(String hookName)
Remove a hook from the collection of hooks. |
Unmodifiable |
unmodifiableClone()
Creates an unmodifiable copy of this KernelHooks. |
Methods inherited from java.lang.Object
Constructor Details
KernelHooks
public KernelHooks()
Creates a new instance of the KernelHooks class.
KernelHooks
public KernelHooks(KernelHooks kernelHooks)
Creates a copy of the KernelHooks.
Parameters:
KernelHooks
public KernelHooks(Map
Creates a new instance of the KernelHooks class from the given hooks.
Parameters:
Method Details
executeHooks
public T
Executes the hooks in this collection that accept the event.
Parameters:
Returns:
addFunctionInvokedHook
public String addFunctionInvokedHook(Function
Add a FunctionInvokedHook to the collection of hooks.
Parameters:
Returns:
addFunctionInvokingHook
public String addFunctionInvokingHook(Function
Add a FunctionInvokingHook to the collection of hooks.
Parameters:
Returns:
addHook
public String addHook(KernelHook hook)
Add a KernelHook<T> to the collection of hooks.
Parameters:
Returns:
addHook
public String addHook(String hookName, KernelHook hook)
Add a KernelHook<T> to the collection of hooks.
Parameters:
Returns:
addHooks
public KernelHooks addHooks(KernelHooks kernelHooks)
Appends the given hooks to this collection.
Parameters:
Returns:
addPostChatCompletionHook
public String addPostChatCompletionHook(Function
Add a PostChatCompletionEvent to the collection of hooks.
Parameters:
Returns:
addPreChatCompletionHook
public String addPreChatCompletionHook(Function
Add a PreChatCompletionHook to the collection of hooks.
Parameters:
Returns:
addPreToolCallHook
public String addPreToolCallHook(Function
Add a PreToolCallHook to the collection of hooks.
Parameters:
Returns:
addPromptRenderedHook
public String addPromptRenderedHook(Function
Add a PromptRenderedHook to the collection of hooks.
Parameters:
Returns:
addPromptRenderingHook
public String addPromptRenderingHook(Function
Add a PromptRenderingHook to the collection of hooks.
Parameters:
Returns:
getHooks
protected Map
Gets the hooks in this collection.
Returns:
isEmpty
public boolean isEmpty()
Determines if this collection of hooks is empty.
Returns:
true
if the collection is empty, otherwise false
merge
public static KernelHooks merge(KernelHooks a, KernelHooks b)
Builds the list of hooks to be invoked for the given context, by merging the hooks in this collection with the hooks in the context. Duplicate hooks in b will override hooks in a.
Parameters:
Returns:
removeHook
public KernelHook removeHook(String hookName)
Remove a hook from the collection of hooks.
Parameters:
Returns:
null
if the hook was not foundunmodifiableClone
public KernelHooks.UnmodifiableKernelHooks unmodifiableClone()
Creates an unmodifiable copy of this KernelHooks.
Returns: