Skip to content

Python: native function always has 'input' parameter #2233

@joowon-dm-snu

Description

@joowon-dm-snu

Describe the bug
A clear and concise description of what the bug is.

Native function always has 'input' parameter in its parameter list.
Becuase @sk_function decorator always pass __sk_function_input_description__ as default value, None.

# semantic-kernel/python/semantic_kernel/skill_definition/sk_function_decorator.py
def sk_function(
    *,
    description: str = "",
    name: str = None,
    input_description: str = None,
    input_default_value: str = None
):
    def decorator(func):
        func.__sk_function__ = True
        func.__sk_function_description__ = description
        func.__sk_function_name__ = name if name else func.__name__
        func.__sk_function_input_description__ = input_description
        func.__sk_function_input_default_value__ = input_default_value
# /Users/joowonkim/Repo/semantic-kernel-jw/semantic-kernel/python/semantic_kernel/orchestration/sk_function.py
class SKFunction(SKFunctionBase):
    @staticmethod
    def from_native_method(method, skill_name="", log=None) -> "SKFunction":

        ...

        if hasattr(method, "__sk_function_input_description__"):
            input_param = ParameterView(
                "input",
                method.__sk_function_input_description__,
                method.__sk_function_input_default_value__,
            )
            parameters = [input_param] + parameters

To Reproduce
Steps to reproduce the behavior:

from semantic_kernel import Kernel, SKContext
from semantic_kernel.skill_definition import sk_function, sk_function_context_parameter


class TestSkill:
    @sk_function(
        description="Test skill",
        name="testSkill",
    )
    @sk_function_context_parameter(
        name="testParam",
        description="Test parameter",
    )
    def test(self, context: SKContext):
        pass


k = Kernel()
skill = k.import_skill(TestSkill(), "TestSkill")

for param in skill['testSkill'].parameters:
    print(f"{param.name}: {param.description}")

# Result:
# input: None
# testParam: Test parameter
image image

Expected behavior
A clear and concise description of what you expected to happen.

# Result:
# testParam: Test parameter

Screenshots
If applicable, add screenshots to help explain your problem.

Platform

  • OS: [e.g. Windows, Mac]
  • IDE: [e.g. Visual Studio, VS Code]
  • Language: [e.g. C#, Python]
  • Source: [e.g. NuGet package version 0.1.0, pip package version 0.1.0, main branch of repository]

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETIssue or Pull requests regarding .NET codepythonPull requests for the Python Semantic Kernel

    Type

    No type

    Projects

    Status

    Sprint: Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions