semantic-kernel
semantic-kernel copied to clipboard
Python: Bug: Kernel functions do not handle Union arguments well
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:
- 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"
- Ask the agent to search for john doe
- Observe the metadata that semantic kernel sends to the
/chat/completionsendpoint.
{
"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.
Thanks for filing @q-stefanmuscalu. This is a known gap. I'll work on this.