semantic-kernel
semantic-kernel copied to clipboard
Python: implement Hooks
Motivation and Context
This pull request includes significant changes across multiple files, mainly related to the addition of hooks and the modification of function invocations in the semantic_kernel
module. The changes also include the addition of a new sample and a YAML file, and modifications to the __init__.py
files.
Addition of Hooks:
-
python/semantic_kernel/hooks/__init__.py
: Added new context classes, protocol classes, helpers (utils and const) and a hook filter decorator.
Other Additions and Modifications:
-
python/samples/kernel-syntax-examples/azure_chat_gpt_api_with_hooks.py
: Added a new Python script that demonstrates the usage of hooks with the Azure Chat GPT API. -
python/semantic_kernel/connectors/ai/open_ai/utils.py
: Modified the_describe_tool_call
andparse_param
functions to handle more complex parameter types. [1] [2] -
python/semantic_kernel/functions/kernel_function.py
: Modified theinvoke
andinvoke_stream
methods to include pre and post hooks. [1] [2] [3] [4] -
python/semantic_kernel/functions/kernel_function_from_prompt.py
: Modified the_invoke_internal
and_invoke_internal_stream
methods to include pre and post prompt render hooks. [1] [2]
Removals:
-
python/semantic_kernel/events
: Removed the previously used events.
New Exceptions:
-
python/semantic_kernel/exceptions/kernel_exceptions.py
: Added new exception classesOperationCancelledException
andHookInvalidSignatureError
. [1] [2]
Changes to Function Decorator:
-
python/semantic_kernel/functions/kernel_function_decorator.py
: Modified the_parse_internal_annotation
function to handle list and dict types.
Fixes: #3038
Contribution Checklist
- [x] The code builds clean without any errors or warnings
- [x] The PR follows the SK Contribution Guidelines and the pre-submission formatting script raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone :smile: