Friday, 21 February 2025

Invoking Prompt Functions in Semantic Kernal

 using Microsoft.SemanticKernel;


// Populate values from your OpenAI deployment
var modelId = "";
var endpoint = "";
var apiKey = "";

// Create a kernel with Azure OpenAI chat completion
var builder = Kernel.CreateBuilder().AddAzureOpenAIChatCompletion(modelId, endpoint, apiKey);

// Build the kernel
Kernel kernel = builder.Build();

string prompt = """
    You are a helpful travel guide.
    I'm visiting {{$city}}. {{$background}}. What are some activities I should do today?
    """;
string city = "Barcelona";
string background = "I really enjoy art and dance.";

// Create the kernel function from the prompt
var activitiesFunction = kernel.CreateFunctionFromPrompt(prompt);

// Create the kernel arguments
var arguments = new KernelArguments { ["city"] = city, ["background"] = background };

// InvokeAsync on the kernel object
var result = await kernel.InvokeAsync(activitiesFunction, arguments);
Console.WriteLine(result);

No comments:

Post a Comment

Using Handlebar Prompt in Semantic Kernal

> dotnet add package Microsoft.SemanticKernel.PromptTemplates.Handlebars --version 1.30.0 using Microsoft . SemanticKernel ; using Micr...