-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python: Introduce the new function calling abstraction, FunctionChoiceBehavior #6910
Conversation
Python 3.10 Test Coverage Report •
Python 3.10 Unit Test Overview
|
…in the function schema or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couple of comments, mostly small things, biggest one is wondering if we can simplify the function choice behavior class a bit further?
python/semantic_kernel/connectors/utils/function_call_format.py
Outdated
Show resolved
Hide resolved
..._kernel/connectors/ai/open_ai/prompt_execution_settings/open_ai_prompt_execution_settings.py
Show resolved
Hide resolved
python/semantic_kernel/connectors/ai/function_choice_behavior.py
Outdated
Show resolved
Hide resolved
python/semantic_kernel/connectors/ai/function_choice_behavior.py
Outdated
Show resolved
Hide resolved
python/samples/concepts/plugins/plugin_with_param_not_included_in_function_schema.py
Outdated
Show resolved
Hide resolved
python/semantic_kernel/connectors/ai/function_choice_behavior.py
Outdated
Show resolved
Hide resolved
python/semantic_kernel/connectors/ai/open_ai/services/open_ai_chat_completion_base.py
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a bunch of comments...
python/semantic_kernel/connectors/ai/function_choice_behavior.py
Outdated
Show resolved
Hide resolved
python/semantic_kernel/connectors/ai/function_choice_behavior.py
Outdated
Show resolved
Hide resolved
python/semantic_kernel/connectors/ai/function_choice_behavior.py
Outdated
Show resolved
Hide resolved
python/semantic_kernel/connectors/ai/function_choice_behavior.py
Outdated
Show resolved
Hide resolved
...antic_kernel/planners/function_calling_stepwise_planner/function_calling_stepwise_planner.py
Show resolved
Hide resolved
python/samples/concepts/auto_function_calling/function_calling_with_required_type.py
Show resolved
Hide resolved
python/samples/concepts/auto_function_calling/functions_defined_in_json_prompt.py
Show resolved
Hide resolved
…to invoke_function_call. Cleaned up other code/tests. Improved samples.
…ic-kernel into func_calling_abstraction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor comments, overal looks great!
python/semantic_kernel/connectors/ai/open_ai/services/open_ai_chat_completion_base.py
Outdated
Show resolved
Hide resolved
…al for invoke_function_call.
…tegration tests for function choice behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it, looks great!
…eBehavior (microsoft#6910) ### Motivation and Context The current `FunctionCallBehavior` has allowed us to utilize auto function calling for OpenAI type models. As we proceed to support more AI connectors, that differ from OpenAI models, we need to be able to handle functions for all models that support function calling. <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> ### Description In this PR: - We introduce a new function calling abstraction called `FunctionChoiceBehavior` which has three types: Auto, Required, and None. - One is able to configure the `function_choice_behavior` along with fully qualified function names (e.g., plugin1.function1), `maximum_auto_invoke_attempts` or `auto_invoke_kernel_functions` in yaml and JSON prompts. We have a new concept example showing how to do this for for yaml and JSON prompts. - If the fully qualified names are specified in the config file, they take precedence over the filters, if specified at a later point. - To make sure this isn't a breaking change, we still handle the previous `FunctionCallBehavior`, but so we can make decisions on the new `FunctionChoiceBehavior` we map the `FunctionCallBehavior` to `FunctionChoiceBehavior`. Each time `FunctionCallBehavior` is updated, `FunctionChoiceBehavior` will be updated, too. - The `_process_tool_call()` method in the `open_ai_chat_completion_base` needs to maintain the argument name as `function_call_behavior` as we cannot introduce a breaking change. - All concept samples have been converted to use `FunctionChoiceBehavior`. - New unit tests have been added for `FunctionChoiceBehavior` and we still currently support `FunctionCallBehavior` tests to make sure we haven't broken the backwards compatibility. - Added `deprecated` typing decorators to classes/methods to alert users that it would be best to transition to `FunctionChoiceBehavior` even though `FunctionCallBehavior` is still supported. - The `FunctionCallingStepwisePlanner` was updated to use the new `FunctionChoiceBehavior`. - Closes microsoft#6496, microsoft#6458 - Addresses microsoft#6626 <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄
Motivation and Context
The current
FunctionCallBehavior
has allowed us to utilize auto function calling for OpenAI type models. As we proceed to support more AI connectors, that differ from OpenAI models, we need to be able to handle functions for all models that support function calling.Description
In this PR:
FunctionChoiceBehavior
which has three types: Auto, Required, and None.function_choice_behavior
along with fully qualified function names (e.g., plugin1.function1),maximum_auto_invoke_attempts
orauto_invoke_kernel_functions
in yaml and JSON prompts. We have a new concept example showing how to do this for for yaml and JSON prompts.FunctionCallBehavior
, but so we can make decisions on the newFunctionChoiceBehavior
we map theFunctionCallBehavior
toFunctionChoiceBehavior
. Each timeFunctionCallBehavior
is updated,FunctionChoiceBehavior
will be updated, too._process_tool_call()
method in theopen_ai_chat_completion_base
needs to maintain the argument name asfunction_call_behavior
as we cannot introduce a breaking change.FunctionChoiceBehavior
.FunctionChoiceBehavior
and we still currently supportFunctionCallBehavior
tests to make sure we haven't broken the backwards compatibility.deprecated
typing decorators to classes/methods to alert users that it would be best to transition toFunctionChoiceBehavior
even thoughFunctionCallBehavior
is still supported.FunctionCallingStepwisePlanner
was updated to use the newFunctionChoiceBehavior
.Contribution Checklist