Skip to content
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

Add support for custom delegates as SKFunctions #893

Merged
merged 3 commits into from
May 10, 2023

Conversation

dluc
Copy link
Collaborator

@dluc dluc commented May 9, 2023

Motivation and Context

In some scenarios like RPC and OpenAPI it can be useful turning native code into SK Functions allowing to pass signature details (name, description, params) without the use of SK* attributes. For example, loading these details from OpenAPI docs or config files, rather than using reflection.

Description

Add a new FromNativeFunction factory method to SKFunction to pass a custom delegate. The custom delegate must use one of the supported signatures, but doesn't need the "SK*[...]" attributes.

Example:

async Task<SKContext> MyFunctionAsync(SKContext context)
{
    await Task.Delay(0);
    return context;
}
ISKFunction function = SKFunction.FromNativeFunction(
            nativeFunction: MyFunctionAsync,
            skillName: "Test",
            functionName: "HelloWorld"
            description: "This is a test");

@dluc dluc requested a review from SergeyMenshykh May 9, 2023 21:58
@github-actions github-actions bot added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel kernel.core labels May 9, 2023
@dluc dluc added PR: ready for review All feedback addressed, ready for reviews PR: ready to merge PR has been approved by all reviewers, and is ready to merge. labels May 9, 2023
@dluc
Copy link
Collaborator Author

dluc commented May 10, 2023

The PR is ready to be merged.

One of the issues fixed here has been addressed also in #900 so the remaining part is fixing how native function signatures are handled reusing the same code used for native skills.

@adrianwyatt adrianwyatt enabled auto-merge (squash) May 10, 2023 18:14
@adrianwyatt adrianwyatt removed the PR: ready for review All feedback addressed, ready for reviews label May 10, 2023
@github-actions github-actions bot removed the samples label May 10, 2023
@adrianwyatt adrianwyatt merged commit 08f318a into microsoft:main May 10, 2023
@dluc dluc deleted the dluc148customdelegates branch May 10, 2023 19:04
dehoward pushed a commit to lemillermicrosoft/semantic-kernel that referenced this pull request Jun 1, 2023
### Motivation and Context

In some scenarios like RPC and OpenAPI it can be useful turning native
code into SK Functions allowing to pass signature details (name,
description, params) without the use of SK* attributes. For example,
loading these details from OpenAPI docs or config files, rather than
using reflection.


### Description

Add a new `FromNativeFunction` factory method to `SKFunction` to pass a
custom delegate. The custom delegate must use one of the supported
signatures, but doesn't need the "SK*[...]" attributes.

Example:

```
async Task<SKContext> MyFunctionAsync(SKContext context)
{
    await Task.Delay(0);
    return context;
}
```

```
ISKFunction function = SKFunction.FromNativeFunction(
            nativeFunction: MyFunctionAsync,
            skillName: "Test",
            functionName: "HelloWorld"
            description: "This is a test");
```

Co-authored-by: Adrian Bonar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code PR: ready to merge PR has been approved by all reviewers, and is ready to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants