Skip to content

Python: Add support for kernel.InvokePromptAsync similar to C# counterpart. #6804

@rogerbarreto

Description

@rogerbarreto

Currently we have Kernel examples that are very simple using C#:

Kernel kernel = Kernel.CreateBuilder()
            .AddOpenAIChatCompletion(modelId:gpt-4o”, apiKey: “…”)
            .Build();

Console.WriteLine(await kernel.InvokePromptAsync("Why is the sky blue?"));

In python there's no way to use it as function_name and plugin_name are required arguments and need to be created manually with a prompttemplateconfig.

Desired but not supported today

kernel = Kernel()
kernel.add_service(OpenAIChatCompletion(ai_model_id="gpt-4o", api_key="..."))

print(asyncio.run(kernel.invoke_prompt("Why is the sky blue")))

Currently to achieve a result all those lines are required in python:

kernel = Kernel()
kernel.add_service(OpenAIChatCompletion(ai_model_id="gpt-4o", api_key="..."))
prompt_template_config = PromptTemplateConfig(template="why is the sky blue")
tldr_function = kernel.add_function(function_name="tldrFunction",plugin_name="tldrPlugin", prompt_template_config = prompt_template_config)
result = asyncio.run(kernel.invoke(tldr_function))
print(result)

Metadata

Metadata

Assignees

Labels

pythonPull requests for the Python Semantic Kernel

Type

No type

Projects

Status

Sprint: Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions