mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 11:19:56 +00:00
### Motivation and Context In addition to the Python local process runtime, we're adding the ability to congfigure the Dapr runtime for Python SK processes. <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> ### Description The PR introduces: - The ability to configure the Dapr Runtime for Python processes - Adds a sample FastAPI app showing how to configure the Dapr runtime with a sample SK Python process (see the README for details on setup) - Adds some unit test coverage for the Dapr runtime - Closes #9355 <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [X] The code builds clean without any errors or warnings - [X] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [X] All unit tests pass, and I have added new tests where possible - [X] I didn't break anyone 😄
37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
# Copyright (c) Microsoft. All rights reserved.
|
|
|
|
from typing import Any
|
|
|
|
from semantic_kernel.functions.kernel_function import KernelFunction
|
|
from semantic_kernel.processes.kernel_process.kernel_process_message_channel import KernelProcessMessageChannel
|
|
from semantic_kernel.processes.kernel_process.kernel_process_step_context import KernelProcessStepContext
|
|
|
|
|
|
def find_input_channels(
|
|
channel: KernelProcessMessageChannel, functions: dict[str, KernelFunction]
|
|
) -> dict[str, dict[str, Any | None]]:
|
|
"""Finds and creates input channels."""
|
|
if not functions:
|
|
raise ValueError("The step has not been initialized.")
|
|
|
|
inputs: dict[str, Any] = {}
|
|
for name, function in functions.items():
|
|
inputs[name] = {}
|
|
for param in function.metadata.parameters:
|
|
# Check for Kernel, and skip if necessary, since it is populated later on
|
|
if param.type_ == "Kernel":
|
|
continue
|
|
if not param.is_required:
|
|
continue
|
|
if param.type_ == "KernelProcessStepContext":
|
|
inputs[name][param.name] = KernelProcessStepContext(channel)
|
|
else:
|
|
inputs[name][param.name] = None
|
|
|
|
return inputs
|
|
|
|
|
|
def get_fully_qualified_name(cls) -> str:
|
|
"""Gets the fully qualified name of a class."""
|
|
return f"{cls.__module__}.{cls.__name__}"
|