Python: Pydantic-ify the KernelFunction class. Fix code paths related to tool_calls.#4863
Merged
moonbox3 merged 7 commits intomicrosoft:mainfrom Feb 5, 2024
Merged
Conversation
eavanvalkenburg
requested changes
Feb 3, 2024
Member
eavanvalkenburg
left a comment
There was a problem hiding this comment.
Some comments on the tool call/ function call changes, let's discuss. The rest looks good
python/samples/kernel-syntax-examples/chat_gpt_api_function_calling.py
Outdated
Show resolved
Hide resolved
python/semantic_kernel/connectors/ai/open_ai/models/chat/tool_calls.py
Outdated
Show resolved
Hide resolved
python/semantic_kernel/connectors/ai/open_ai/semantic_functions/open_ai_chat_prompt_template.py
Outdated
Show resolved
Hide resolved
….com/moonbox3/semantic-kernel into kernel_func_pydantic_and_other_fixes
eavanvalkenburg
requested changes
Feb 5, 2024
Member
eavanvalkenburg
left a comment
There was a problem hiding this comment.
couple of open questions and one seeming typo!
eavanvalkenburg
approved these changes
Feb 5, 2024
Bryan-Roe
pushed a commit
to Bryan-Roe-ai/semantic-kernel
that referenced
this pull request
Oct 6, 2024
… to tool_calls. (microsoft#4863) ### Motivation and Context Solves microsoft#4864 The KernelFunction was configured as a Python class without regards to using Pydantic fields and its validations. As an aside, while running a kernel example related to function/tool calling, it didn't succeed. <!-- 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 This PR cleans up the KernelFunction by creating Pydantic fields. We're also able to remove the KernelFunctionBase as it didn't contain a lot of logic after removing the properties. While testing other code, I found that the tool call kernel example wasn't succeeding. The tool_call payload needed a small reformat, and we needed to handle the tool_call_id and correctly handle the ToolCall object. As further work towards v1, we should look at removing support for FunctionCall as it is deprecated in Azure OpenAI. We now see: ``` User:> What is 3+3? Mosscap:> Ah, the timeless question of arithmetic! The sum of 3 and 3 is undoubtedly a splendid number. By utilizing my mathematical prowess, I can confidently declare that 3 plus 3 equals 6. It is a harmonious union of two threes, joining forces to create a new entity, greater in magnitude. The addition of these two numbers results in a perfect balance, a symphony of numerical harmony. ``` <!-- 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 😄 --------- Co-authored-by: Evan Mattson <evan.mattson@microsoft.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Solves #4864
The KernelFunction was configured as a Python class without regards to using Pydantic fields and its validations. As an aside, while running a kernel example related to function/tool calling, it didn't succeed.
Description
This PR cleans up the KernelFunction by creating Pydantic fields. We're also able to remove the KernelFunctionBase as it didn't contain a lot of logic after removing the properties.
While testing other code, I found that the tool call kernel example wasn't succeeding. The tool_call payload needed a small reformat, and we needed to handle the tool_call_id and correctly handle the ToolCall object. As further work towards v1, we should look at removing support for FunctionCall as it is deprecated in Azure OpenAI.
We now see:
Contribution Checklist