-
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
.Net: Introduce IAIServiceSelector interface to allow AI service and request settings to be selected during semantic function execution #3227
Merged
markwallace-microsoft
merged 19 commits into
microsoft:main
from
markwallace-microsoft:users/markwallace/ai_factories
Oct 23, 2023
Merged
Conversation
This file contains 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
shawncal
added
.NET
Issue or Pull requests regarding .NET code
kernel
Issues or pull requests impacting the core kernel
kernel.core
labels
Oct 18, 2023
github-actions
bot
changed the title
Add factories for AI services and request settings
.Net: Add factories for AI services and request settings
Oct 18, 2023
markwallace-microsoft
force-pushed
the
users/markwallace/ai_factories
branch
from
October 18, 2023 20:01
719c43e
to
93032e9
Compare
…efault order based implementation
markwallace-microsoft
changed the title
.Net: Add factories for AI services and request settings
.Net: Introduce IAIServiceSelector interface to allow AI service and request settings to be selected during semantic function execution
Oct 20, 2023
dotnet/src/SemanticKernel.Abstractions/Functions/IAIServiceSelector.cs
Outdated
Show resolved
Hide resolved
dotnet/src/SemanticKernel.Core/Functions/OrderedIAIServiceSelector.cs
Outdated
Show resolved
Hide resolved
dotnet/src/SemanticKernel.Core/Functions/OrderedIAIServiceSelector.cs
Outdated
Show resolved
Hide resolved
dotnet/src/SemanticKernel.Abstractions/Functions/ISKFunction.cs
Outdated
Show resolved
Hide resolved
SergeyMenshykh
approved these changes
Oct 23, 2023
RogerBarreto
approved these changes
Oct 23, 2023
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.
Nit comments.
Suggestion on changing SelectAIService
to aways throw if no service is found. Removing if there's any Custom logic that handling ITextCompletion
being nullj in the SemanticFunction InvokeAsync impl.
Maybe add just Verify.IsNull()
Overall LGTM
dotnet/src/SemanticKernel.Core/Functions/OrderedIAIServiceSelector.cs
Outdated
Show resolved
Hide resolved
dotnet/src/SemanticKernel.Core/Functions/OrderedIAIServiceSelector.cs
Outdated
Show resolved
Hide resolved
dotnet/src/SemanticKernel.Core/Functions/OrderedIAIServiceSelector.cs
Outdated
Show resolved
Hide resolved
dotnet/src/SemanticKernel.Core/Functions/OrderedIAIServiceSelector.cs
Outdated
Show resolved
Hide resolved
SergeyMenshykh
approved these changes
Oct 23, 2023
RogerBarreto
approved these changes
Oct 23, 2023
SOE-YoungS
pushed a commit
to SOE-YoungS/semantic-kernel
that referenced
this pull request
Nov 1, 2023
…request settings to be selected during semantic function execution (microsoft#3227) ### Motivation and Context Fix following issues for Semantic functions: 1. Allow semantic functions to dynamically retrieve the AI service and request settings to be used when executing the function Previously semantic functions execution has the following limitations: 1. The AI service was set on the semantic function when it was created. This meant that an instance of a semantic function could not be used with multiple different Kernel instances. 1. The AI request settings were set on the semantic function when it was created. This meant that different request settings could not be selected when the function was executed. ### Description This PR add's a new abstraction called `IAIServiceSelector`. An instance of this is added to a semantic function when it is created. The default implementation works as follows: 1. If the semantic function only has a single associated model request setting instance with no service id then the default AI service and the model request settings are used. This is consistent with the previous behaviour. 1. If the semantic function only has a single associated model request setting instance with a service id then the named AI service and the model request settings are used. If the named AI service is not available an exception will be thrown. This is consistent with the previous behaviour. 1. If the semantic function only has multiple associated model request setting instances then: 1. The model request setting instances are considered in order 1. The first model request setting instance with no service id is considered the default 1. For each model request setting instance that has a service id, if the service exists then it will be used with the associated model request settings 1. If no matching service can be found and default request settings are provided the default service will be used 1. If no matching service can be found and no default request settings are provided an exception will be thrown ### Contribution Checklist - [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 😄
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
Fix following issues for Semantic functions:
Previously semantic functions execution has the following limitations:
Description
This PR add's a new abstraction called
IAIServiceSelector
. An instance of this is added to a semantic function when it is created. The default implementation works as follows:Contribution Checklist