Skip to content

.Net: Support function calling#2842

Merged
gitri-ms merged 46 commits intomicrosoft:mainfrom
gitri-ms:function-calling-dotnet
Sep 28, 2023
Merged

.Net: Support function calling#2842
gitri-ms merged 46 commits intomicrosoft:mainfrom
gitri-ms:function-calling-dotnet

Conversation

@gitri-ms
Copy link
Contributor

@gitri-ms gitri-ms commented Sep 15, 2023

Motivation and Context

Enable the use of OpenAI's function calling capability with SK. However, since this feature is limited to OpenAI chat completion models, we want to do so without widespread changes to the kernel.
Fixes #2315

Description

  • Add ability to pass functions to chat completion model via request settings. If the model does not support function calling, this will be ignored.
  • Add OpenAIFunction class to store function information when passing to the model. This reduces coupling with OpenAI's FunctionDefinition, but adds an extra layer of translation.
  • Add translation layer between FunctionView and OpenAIFunction to easily utilize functions already registered with the kernel
  • Add example demonstrating how to include functions, parse response, and invoke chosen function if registered with the kernel
  • Add required field to ParameterView (default false). This improves the chances of getting correct function arguments from OpenAI.

Contribution Checklist

@gitri-ms gitri-ms requested a review from a team as a code owner September 15, 2023 01:26
@shawncal shawncal added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel kernel.core labels Sep 15, 2023
@gitri-ms gitri-ms marked this pull request as draft September 15, 2023 01:26
@github-actions github-actions bot changed the title .NET: Support function calling for chat completions .Net: Support function calling for chat completions Sep 15, 2023
@gitri-ms gitri-ms changed the title .Net: Support function calling for chat completions .Net: Support function calling Sep 15, 2023
@gitri-ms gitri-ms self-assigned this Sep 15, 2023
Change Console.WriteLine to use GetValue<string>() instead of Result
property in Example59_OpenAIFunctionCalling.cs. This improves the
output handling and ensures proper string conversion.
Replace `OpenApiPluginExecutionParameters` with
`OpenApiFunctionExecutionParameters` in the import of the
KlarnaShoppingPlugin.
@gitri-ms gitri-ms added this pull request to the merge queue Sep 28, 2023
Merged via the queue into microsoft:main with commit 8bf8963 Sep 28, 2023
SOE-YoungS pushed a commit to SOE-YoungS/semantic-kernel that referenced this pull request Nov 1, 2023
### Motivation and Context

<!-- 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.
-->
Enable the use of [OpenAI's function calling
capability](https://platform.openai.com/docs/guides/gpt/function-calling)
with SK. However, since this feature is limited to OpenAI chat
completion models, we want to do so without widespread changes to the
kernel.
 Fixes microsoft#2315 
### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
- Add ability to pass functions to chat completion model via request
settings. If the model does not support function calling, this will be
ignored.
- Add OpenAIFunction class to store function information when passing to
the model. This reduces coupling with OpenAI's FunctionDefinition, but
adds an extra layer of translation.
- Add translation layer between FunctionView and OpenAIFunction to
easily utilize functions already registered with the kernel
- Add example demonstrating how to include functions, parse response,
and invoke chosen function if registered with the kernel
- Add required field to ParameterView (default false). This improves the
chances of getting correct function arguments from OpenAI.

### 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 😄
- [x] Design decisions captured in MADR

---------

Co-authored-by: Lee Miller <lemiller@microsoft.com>
@gitri-ms gitri-ms deleted the function-calling-dotnet branch November 27, 2023 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs and tests Improvements or additions to documentation kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code PR: ready for review All feedback addressed, ready for reviews

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Azure Open AI Functions calling integration into Kernel OpenAI Chat Service classes should support function calling and other API updates

9 participants