semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

Python: implement Hooks

Open eavanvalkenburg opened this issue 3 months ago • 5 comments

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 and parse_param functions to handle more complex parameter types. [1] [2]

  • python/semantic_kernel/functions/kernel_function.py: Modified the invoke and invoke_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 classes OperationCancelledException and HookInvalidSignatureError. [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

eavanvalkenburg avatar Mar 27 '24 16:03 eavanvalkenburg