#r "nuget: Microsoft.SemanticKernel, 1.23.0" #r "nuget: Microsoft.SemanticKernel.Plugins.Web, 1.23.0-alpha" #r "nuget: Microsoft.SemanticKernel.Plugins.Core, 1.23.0-alpha" #r "nuget: Microsoft.SemanticKernel.PromptTemplates.Handlebars, 1.23.0-alpha" #!import config/Settings.cs #!import config/Utils.cs using InteractiveKernel = Microsoft.DotNet.Interactive.Kernel; string BING_KEY = (await InteractiveKernel.GetPasswordAsync("Please enter your Bing Search Key")).GetClearTextPassword(); using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.Data; using Microsoft.SemanticKernel.Plugins.Web.Bing; using Kernel = Microsoft.SemanticKernel.Kernel; // Create a kernel with OpenAI chat completion var builder = Kernel.CreateBuilder(); // Configure AI backend used by the kernel var (useAzureOpenAI, model, azureEndpoint, apiKey, orgId) = Settings.LoadFromFile(); if (useAzureOpenAI) builder.AddAzureOpenAIChatCompletion(model, azureEndpoint, apiKey); else builder.AddOpenAIChatCompletion(model, apiKey, orgId); var kernel = builder.Build(); // Create a text search using Bing search #pragma warning disable SKEXP0050 var textSearch = new BingTextSearch(apiKey: BING_KEY); // Build a text search plugin with Bing search and add to the kernel var searchPlugin = textSearch.CreateWithSearch("SearchPlugin"); kernel.Plugins.Add(searchPlugin); // Invoke prompt and use text search plugin to provide grounding information var query = "What is the Semantic Kernel?"; var prompt = "{{SearchPlugin.Search $query}}. {{$query}}"; KernelArguments arguments = new() { { "query", query } }; Console.WriteLine(await kernel.InvokePromptAsync(prompt, arguments)); using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.Data; using Microsoft.SemanticKernel.Plugins.Web.Bing; using Microsoft.SemanticKernel.PromptTemplates.Handlebars; using Kernel = Microsoft.SemanticKernel.Kernel; // Create a kernel with OpenAI chat completion var builder = Kernel.CreateBuilder(); // Configure AI backend used by the kernel var (useAzureOpenAI, model, azureEndpoint, apiKey, orgId) = Settings.LoadFromFile(); if (useAzureOpenAI) builder.AddAzureOpenAIChatCompletion(model, azureEndpoint, apiKey); else builder.AddOpenAIChatCompletion(model, apiKey, orgId); var kernel = builder.Build(); // Create a text search using Bing search #pragma warning disable SKEXP0050 var textSearch = new BingTextSearch(apiKey: BING_KEY); // Build a text search plugin with Bing search and add to the kernel var searchPlugin = textSearch.CreateWithGetTextSearchResults("SearchPlugin"); kernel.Plugins.Add(searchPlugin); // Invoke prompt and use text search plugin to provide grounding information var query = "What is the Semantic Kernel?"; string promptTemplate = """ {{#with (SearchPlugin-GetTextSearchResults query)}} {{#each this}} Name: {{Name}} Value: {{Value}} Link: {{Link}} ----------------- {{/each}} {{/with}} {{query}} Include citations to the relevant information where it is referenced in the response. """; KernelArguments arguments = new() { { "query", query } }; HandlebarsPromptTemplateFactory promptTemplateFactory = new(); Console.WriteLine(await kernel.InvokePromptAsync( promptTemplate, arguments, templateFormat: HandlebarsPromptTemplateFactory.HandlebarsTemplateFormat, promptTemplateFactory: promptTemplateFactory )); using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.Data; using Microsoft.SemanticKernel.PromptTemplates.Handlebars; using Microsoft.SemanticKernel.Plugins.Web.Bing; // Create a kernel with OpenAI chat completion var builder = Kernel.CreateBuilder(); // Configure AI backend used by the kernel var (useAzureOpenAI, model, azureEndpoint, apiKey, orgId) = Settings.LoadFromFile(); if (useAzureOpenAI) builder.AddAzureOpenAIChatCompletion(model, azureEndpoint, apiKey); else builder.AddOpenAIChatCompletion(model, apiKey, orgId); var kernel = builder.Build(); // Create a text search using Bing search #pragma warning disable SKEXP0050 var textSearch = new BingTextSearch(apiKey: BING_KEY); // Create a filter to search only the Microsoft Developer Blogs site #pragma warning disable SKEXP0001 var filter = new TextSearchFilter().Equality("site", "devblogs.microsoft.com"); var searchOptions = new TextSearchOptions() { Filter = filter }; // Build a text search plugin with Bing search and add to the kernel var searchPlugin = KernelPluginFactory.CreateFromFunctions( "SearchPlugin", "Search Microsoft Developer Blogs site only", [textSearch.CreateGetTextSearchResults(searchOptions: searchOptions)]); kernel.Plugins.Add(searchPlugin); // Invoke prompt and use text search plugin to provide grounding information var query = "What is the Semantic Kernel?"; string promptTemplate = """ {{#with (SearchPlugin-GetTextSearchResults query)}} {{#each this}} Name: {{Name}} Value: {{Value}} Link: {{Link}} ----------------- {{/each}} {{/with}} {{query}} Include citations to the relevant information where it is referenced in the response. """; KernelArguments arguments = new() { { "query", query } }; HandlebarsPromptTemplateFactory promptTemplateFactory = new(); Console.WriteLine(await kernel.InvokePromptAsync( promptTemplate, arguments, templateFormat: HandlebarsPromptTemplateFactory.HandlebarsTemplateFormat, promptTemplateFactory: promptTemplateFactory ));