From 174ba5e7932f6ec1fd48f6771461d0be1f3bdaa5 Mon Sep 17 00:00:00 2001 From: Shoumik Chakravarty Date: Sun, 12 Jul 2026 20:31:20 -0500 Subject: [PATCH 1/2] DOC: add Example sections to KernelFunction.from_prompt and invoke Add illustrative code examples to two public methods in KernelFunction: - from_prompt: shows creating a prompt-based function and registering it with the kernel - invoke: shows async invocation with KernelArguments using OpenAIChatCompletion Both examples follow the existing Google-style docstring convention used throughout the module. --- .../functions/kernel_function.py | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/python/semantic_kernel/functions/kernel_function.py b/python/semantic_kernel/functions/kernel_function.py index 15f2ab34c6b7..4753cb8ac793 100644 --- a/python/semantic_kernel/functions/kernel_function.py +++ b/python/semantic_kernel/functions/kernel_function.py @@ -138,7 +138,26 @@ def from_prompt( "PromptExecutionSettings | Sequence[PromptExecutionSettings] | Mapping[str, PromptExecutionSettings] | None" ) = None, ) -> "KernelFunctionFromPrompt": - """Create a new instance of the KernelFunctionFromPrompt class.""" + """Create a new instance of the KernelFunctionFromPrompt class. + + Example: + Create a prompt-based function and register it with the kernel: + + from semantic_kernel import Kernel + from semantic_kernel.functions import KernelFunction + + kernel = Kernel() + func = KernelFunction.from_prompt( + function_name="summarize", + plugin_name="WriterPlugin", + description="Summarizes the provided text in one sentence.", + prompt="Summarize the following in one sentence: {{$input}}", + ) + kernel.add_function(plugin_name="WriterPlugin", function=func) + print(func.name) # summarize + print(func.plugin_name) # WriterPlugin + print(func.is_prompt) # True + """ from semantic_kernel.functions.kernel_function_from_prompt import KernelFunctionFromPrompt return KernelFunctionFromPrompt( @@ -255,6 +274,32 @@ async def invoke( Returns: FunctionResult: The result of the function + + Example: + Invoke a prompt function with arguments: + + import asyncio + from semantic_kernel import Kernel + from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion + from semantic_kernel.functions import KernelArguments, KernelFunction + + async def main(): + kernel = Kernel() + kernel.add_service(OpenAIChatCompletion(service_id="default")) + func = KernelFunction.from_prompt( + function_name="summarize", + plugin_name="WriterPlugin", + prompt="Summarize the following in one sentence: {{$input}}", + ) + result = await func.invoke( + kernel=kernel, + arguments=KernelArguments( + input="Azure API Management is a fully managed gateway service." + ), + ) + print(result) + + asyncio.run(main()) """ if arguments is None: arguments = KernelArguments(**kwargs) From 105b2618f66053d41135332da31be4131f9e1ea7 Mon Sep 17 00:00:00 2001 From: Shoumik Chakravarty Date: Sun, 12 Jul 2026 20:50:00 -0500 Subject: [PATCH 2/2] =?UTF-8?q?DOC:=20address=20Copilot=20review=20?= =?UTF-8?q?=E2=80=94=20add=20ai=5Fmodel=5Fid=20and=20API=20key=20note=20to?= =?UTF-8?q?=20invoke=20example?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/semantic_kernel/functions/kernel_function.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/semantic_kernel/functions/kernel_function.py b/python/semantic_kernel/functions/kernel_function.py index 4753cb8ac793..6213d38040a3 100644 --- a/python/semantic_kernel/functions/kernel_function.py +++ b/python/semantic_kernel/functions/kernel_function.py @@ -285,7 +285,8 @@ async def invoke( async def main(): kernel = Kernel() - kernel.add_service(OpenAIChatCompletion(service_id="default")) + # Requires OPENAI_API_KEY env var (or pass api_key explicitly). + kernel.add_service(OpenAIChatCompletion(ai_model_id="gpt-4o-mini", service_id="default")) func = KernelFunction.from_prompt( function_name="summarize", plugin_name="WriterPlugin",