semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

Python: Bug: Kernel functions do not handle Union arguments well

Open q-stefanmuscalu opened this issue 1 year ago • 1 comments

Describe the bug Only the first member of a type Union makes it into the metadata. I tried this with both primitive types and classes and I got the same behaviour.

To Reproduce Steps to reproduce the behavior:

  1. Define this plugin
class SearchPlugin:

    @kernel_function(
        name="Search",
        description="Search for people",
    )
    def find_person(
        self,
        first_name: str,
        last_name: str,
        postcode: Union[str, int]
    ) -> str:
        return "nothing found"
  1. Ask the agent to search for john doe
  2. Observe the metadata that semantic kernel sends to the /chat/completions endpoint.
{
    "type": "function",
    "function": {
        "name": "SearchPlugin-Search",
        "description": "Search for people",
        "parameters": {
            "type": "object",
            "properties": {
                "first_name": {
                    "type": "string"
                },
                "last_name": {
                    "type": "string"
                },
                "postcode": {
                    "type": "string"
                }
            },
            "required": [
                "first_name",
                "last_name",
                "postcode"
            ]
        }
    }
}

Expected behavior I would expect the metadata to say that postcode is either a string or an integer

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

Platform

  • OS: Mac
  • IDE: PyCharm
  • Language: Python
  • Source: semantic kernel 1.2.0, python 3.11, Azure Open AI

Additional context Add any other context about the problem here.

q-stefanmuscalu avatar Jul 16 '24 16:07 q-stefanmuscalu

Thanks for filing @q-stefanmuscalu. This is a known gap. I'll work on this.

moonbox3 avatar Jul 19 '24 14:07 moonbox3