-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for multiple native function arguments
- Native skills can now have any number of string parameters. The parameters are populated from context variables of the same name. If no context variable exists for that name, it'll be populated with a default value if one was supplied via either an attribute or a default parameter value, or if there is none, the function will fail to be invoked. - SKFunctionContextParameterAttribute may now be specified on a parameter directly. - SKFunctionInputAttribute is now applied directly to the parameter rather than to the method. It may be applied to at most one string parameter, in which case it'll override that parameter to be named "Input". - DefaultValue was removed from SKFunctionInput as it wasn't actually being respected. - SKFunctionNameAttribute was removed, with the Name moving to being an optional property of the SKFunctionAttribute. - If there's only one string parameter, it first looks to get its value from a context parameter named the same as the parameter, but if that fails, it'll fall back to using "Input". - InvokeAsync will now catch exceptions and store the exception into the context. This means native skills should handle all failures by throwing exceptions rather than by directly interacting with the context.
- Loading branch information
1 parent
0906f22
commit 7dba232
Showing
50 changed files
with
843 additions
and
950 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,18 +10,24 @@ namespace SemanticKernel.IntegrationTests.Fakes; | |
internal sealed class EmailSkillFake | ||
{ | ||
[SKFunction("Given an email address and message body, send an email")] | ||
[SKFunctionInput(Description = "The body of the email message to send.")] | ||
[SKFunctionContextParameter(Name = "email_address", Description = "The email address to send email to.", DefaultValue = "[email protected]")] | ||
public Task<SKContext> SendEmailAsync(string input, SKContext context) | ||
public Task<SKContext> SendEmailAsync( | ||
[SKFunctionInput("The body of the email message to send.")] string input, | ||
[SKFunctionContextParameter("The email address to send email to.", DefaultValue = "[email protected]")] string? email_address, | ||
SKContext context) | ||
{ | ||
context.Variables.Get("email_address", out string emailAddress); | ||
context.Variables.Update($"Sent email to: {emailAddress}. Body: {input}"); | ||
if (string.IsNullOrWhiteSpace(email_address)) | ||
{ | ||
email_address = "[email protected]"; | ||
} | ||
|
||
context.Variables.Update($"Sent email to: {email_address}. Body: {input}"); | ||
return Task.FromResult(context); | ||
} | ||
|
||
[SKFunction("Lookup an email address for a person given a name")] | ||
[SKFunctionInput(Description = "The name of the person to email.")] | ||
public Task<SKContext> GetEmailAddressAsync(string input, SKContext context) | ||
public Task<SKContext> GetEmailAddressAsync( | ||
[SKFunctionInput("The name of the person to email.")] string input, | ||
SKContext context) | ||
{ | ||
if (string.IsNullOrEmpty(input)) | ||
{ | ||
|
@@ -38,8 +44,9 @@ public Task<SKContext> GetEmailAddressAsync(string input, SKContext context) | |
} | ||
|
||
[SKFunction("Write a short poem for an e-mail")] | ||
[SKFunctionInput(Description = "The topic of the poem.")] | ||
public Task<SKContext> WritePoemAsync(string input, SKContext context) | ||
public Task<SKContext> WritePoemAsync( | ||
[SKFunctionInput("The topic of the poem.")] string input, | ||
SKContext context) | ||
{ | ||
context.Variables.Update($"Roses are red, violets are blue, {input} is hard, so is this test."); | ||
return Task.FromResult(context); | ||
|
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
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
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
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
28 changes: 0 additions & 28 deletions
28
dotnet/src/SemanticKernel.Abstractions/SkillDefinition/SKFunctionNameAttribute.cs
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.