You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
During calling my own native function which is not properly designed,
the error should be raised via infer_unknown below.
@staticmethod
@_infers(DelegateTypes.Unknown)
def infer_unknown(signature: Signature) -> NoReturn:
raise KernelException(
KernelException.ErrorCodes.FunctionTypeNotSupported,
"Invalid function type detected, unable to infer DelegateType.",
)
However, the type error is raised since awaitable parameter is not included in the infer_unknown function.
TypeError: DelegateInference.infer_unknown() takes 1 positional argument but 2 were given
def infer_delegate_type(function) -> DelegateTypes:
# Get the function signature
function_signature = signature(function)
awaitable = iscoroutinefunction(function)
for name, value in DelegateInference.__dict__.items():
wrapped = getattr(value, "__wrapped__", getattr(value, "__func__", None))
if name.startswith("infer_") and hasattr(wrapped, "_delegate_type"):
# Get the delegate type
if wrapped(**function_signature, awaitable**):
return wrapped._delegate_type
return DelegateTypes.Unknown
To Reproduce
What I've added as a native function is:
import os
import aiofiles
from semantic_kernel.orchestration.sk_context import SKContext
from semantic_kernel.orchestration.context_variables import ContextVariables
from semantic_kernel.skill_definition import sk_function
class ChatHistoryProcessingSkill:
@sk_function(description="save chat history")
async def save_chat(self, context_vars: ContextVariables):
chat_id = context_vars.get("chat_id")
chat_history = context_vars.get("chat_history")
async with aiofiles.open(f"chat_history_{chat_id}.txt", "w") as f:
await f.write(chat_history)
@sk_function(description="recall chat history")
async def recall_chat(self, input: str) -> str:
if not os.path.exists(f"chat_history_{input}.txt"):
return ''
async with aiofiles.open(f"chat_history_{input}.txt", "r") as f:
content = await f.read()
return content
Then, I've run code:
import semantic_kernel as sk
from semantic_kernel.skills.ChatHistorySkill.chat_history_skill import ChatHistoryProcessingSkill
kernel = sk.Kernel()
kernel.import_skill(ChatHistoryProcessingSkill())
(I think FunctionTypeNotSupported error is raised since the input type is ContextVariables.
When I modified it to SKContext, it works well.)
Expected behavior
Thus, awaitable should be added like: def infer_unknown(signature: Signature, awaitable: bool) -> NoReturn:
Or, Exclude the 'infer_unknown' such as : if name.startswith("infer_") and not name.endswith("unknown") and hasattr(wrapped, "_delegate_type"):
Screenshots
Desktop (please complete the following information):
OS: Mac M1
IDE: VSCode
NuGet Package Version [e.g. 0.1.0]
Additional context
The text was updated successfully, but these errors were encountered:
### Motivation and Context
#691#1053
### Description
1. Added an argument to prevent TypeError when inferring an unknown
type.
2. Fixed a bug in the process of checking parameters when inferring the
InStringAndContext type.
shawncal
pushed a commit
to shawncal/semantic-kernel
that referenced
this issue
Jul 6, 2023
### Motivation and Context
microsoft#691microsoft#1053
### Description
1. Added an argument to prevent TypeError when inferring an unknown
type.
2. Fixed a bug in the process of checking parameters when inferring the
InStringAndContext type.
Describe the bug
During calling my own native function which is not properly designed,
the error should be raised via
infer_unknown
below.However, the type error is raised since awaitable parameter is not included in the infer_unknown function.
TypeError: DelegateInference.infer_unknown() takes 1 positional argument but 2 were given
To Reproduce
What I've added as a native function is:
Then, I've run code:
(I think FunctionTypeNotSupported error is raised since the input type is ContextVariables.
When I modified it to SKContext, it works well.)
Expected behavior
Thus, awaitable should be added like:
def infer_unknown(signature: Signature, awaitable: bool) -> NoReturn:
Or, Exclude the 'infer_unknown' such as :
if name.startswith("infer_") and not name.endswith("unknown") and hasattr(wrapped, "_delegate_type"):
Screenshots
Desktop (please complete the following information):
Additional context
The text was updated successfully, but these errors were encountered: