Skip to content

Commit 3034075

Browse files
joowon-dm-snudluc
authored andcommitted
fix: delegate compatibility issue for python 3.9 (microsoft#183)
### Motivation and Context 1. Why is this change required? compatibility for python 3.9 2. What problem does it solve? if user use PromptTemplateEngine with skills inside, it does not work. 3. What scenario does it contribute to? PromptTemplateEngine will work 4. If it fixes an open issue, please link to the issue here. microsoft#182 ### Description detailed in microsoft#182 similar concept with microsoft#169 ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows SK Contribution Guidelines (https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) - [x] The code follows the .NET coding conventions (https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions) verified with `dotnet format` - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄 <!-- Thank you for your contribution to the semantic-kernel repo! -->
1 parent 043890e commit 3034075

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

python/semantic_kernel/orchestration/delegate_handlers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,9 @@ async def handle_unknown(function, context):
141141
@staticmethod
142142
def get_handler(delegate_type):
143143
for name, value in DelegateHandlers.__dict__.items():
144-
if name.startswith("handle_") and hasattr(
145-
value.__wrapped__, "_delegate_type"
146-
):
147-
if value.__wrapped__._delegate_type == delegate_type:
144+
wrapped = getattr(value, "__wrapped__", getattr(value, "__func__", None))
145+
if name.startswith("handle_") and hasattr(wrapped, "_delegate_type"):
146+
if wrapped._delegate_type == delegate_type:
148147
return value
149148

150149
return DelegateHandlers.handle_unknown

python/semantic_kernel/orchestration/sk_function.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ async def _invoke_native_async(self, context):
256256
self._ensure_context_has_skills(context)
257257

258258
delegate = DelegateHandlers.get_handler(self._delegate_type)
259+
# for python3.9 compatibility (staticmethod is not callable)
260+
if not hasattr(delegate, "__call__"):
261+
delegate = delegate.__func__
259262
new_context = await delegate(self._function, context)
260263

261264
return new_context

0 commit comments

Comments
 (0)