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

Python: Provide methods to register single native function to the kernel in Python SDK #2321

Closed
blackchoey opened this issue Aug 4, 2023 · 2 comments · Fixed by #2390
Closed
Assignees
Labels
.NET Issue or Pull requests regarding .NET code python Pull requests for the Python Semantic Kernel

Comments

@blackchoey
Copy link

I want to register a native function to the kernel when using the Python SDK. In .NET, the kernel has RegisterCustomFunction method to register a function. But in Python, seems there's only an import_skill method available, which requires me to declare a class with the native function in it.

The current experience of registering a native function:

class Test:
    @sk_function(name="getLightStatus")
    def get_light_status(self) -> str:
        return "off"

kernel.import_skill(Test())

The expected experience I want is:

@sk_function(name="getLightStatus")
def get_light_status() -> str:
    return "off"

kernel.register_native_function(get_light_status)
@shawncal shawncal added .NET Issue or Pull requests regarding .NET code python Pull requests for the Python Semantic Kernel triage labels Aug 4, 2023
@shawncal shawncal changed the title Provide methods to register single native function to the kernel in Python SDK Python: Provide methods to register single native function to the kernel in Python SDK Aug 4, 2023
@shawncal shawncal changed the title Python: Provide methods to register single native function to the kernel in Python SDK .Net: Provide methods to register single native function to the kernel in Python SDK Aug 4, 2023
@joowon-dm-snu
Copy link
Contributor

@alexchaomander I've opened a PR, how does this look?

@nacharya1 nacharya1 changed the title .Net: Provide methods to register single native function to the kernel in Python SDK Python: Provide methods to register single native function to the kernel in Python SDK Aug 10, 2023
@nacharya1 nacharya1 removed the triage label Aug 10, 2023
@alexchaomander
Copy link
Contributor

@joowon-dm-snu Nice! Thank you for the first pass of the implementation! I agree that having it be easy to import native functions in Python would be great. We might need to tweak the naming of it, but will discuss with the team!

github-merge-queue bot pushed a commit that referenced this issue Aug 23, 2023
…nel (#2390)

### 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.
-->
solve #2321 

### Description

<!-- 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: -->

- [ ] The code builds clean without any errors or warnings
- [ ] 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
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄

---------

Co-authored-by: Abby Harrison <54643756+awharrison-28@users.noreply.github.com>
Co-authored-by: Abby Harrison <abby.harrison@microsoft.com>
Co-authored-by: Lee Miller <lemiller@microsoft.com>
SOE-YoungS pushed a commit to SOE-YoungS/semantic-kernel that referenced this issue Nov 1, 2023
…nel (microsoft#2390)

### 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.
-->
solve microsoft#2321 

### Description

<!-- 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: -->

- [ ] The code builds clean without any errors or warnings
- [ ] 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
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄

---------

Co-authored-by: Abby Harrison <54643756+awharrison-28@users.noreply.github.com>
Co-authored-by: Abby Harrison <abby.harrison@microsoft.com>
Co-authored-by: Lee Miller <lemiller@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
.NET Issue or Pull requests regarding .NET code python Pull requests for the Python Semantic Kernel
Projects
Archived in project
5 participants