Files
semantic-kernel/dotnet/samples/KernelSyntaxExamples/Example04_CombineLLMPromptsAndNativeCode.cs
T
01afd3f128 .Net: Update KernelSyntaxExamples env variables (#1832)
### Description
Updating KernelSyntaxExamples to use the same environment variable keys
as the Integration tests. This is a step toward making these tests
simpler to run, and even running them as automation in CI tests.

This is a first pass -- more cleanup to be done.

### Contribution Checklist
<!-- Before submitting this PR, please make sure: -->
- [X] The code builds clean without any errors or warnings
- [X] The PR follows SK Contribution Guidelines
(https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
- [X] The code follows the .NET coding conventions
(https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions)
verified with `dotnet format`
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄

---------

Co-authored-by: name <email>
Co-authored-by: Dmytro Struk <[email protected]>
2023-07-17 17:36:06 +00:00

77 lines
2.2 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Threading.Tasks;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Skills.Web;
using Microsoft.SemanticKernel.Skills.Web.Bing;
using RepoUtils;
// ReSharper disable once InconsistentNaming
public static class Example04_CombineLLMPromptsAndNativeCode
{
public static async Task RunAsync()
{
Console.WriteLine("======== LLMPrompts ========");
string openAIApiKey = TestConfiguration.OpenAI.ApiKey;
if (openAIApiKey == null)
{
Console.WriteLine("OpenAI credentials not found. Skipping example.");
return;
}
IKernel kernel = new KernelBuilder()
.WithLogger(ConsoleLogger.Log)
.WithOpenAITextCompletionService("text-davinci-002", openAIApiKey, serviceId: "text-davinci-002")
.WithOpenAITextCompletionService("text-davinci-003", openAIApiKey)
.Build();
// Load native skill
string bingApiKey = TestConfiguration.Bing.ApiKey;
if (bingApiKey == null)
{
Console.WriteLine("Bing credentials not found. Skipping example.");
return;
}
var bingConnector = new BingConnector(bingApiKey);
var bing = new WebSearchEngineSkill(bingConnector);
var search = kernel.ImportSkill(bing, "bing");
// Load semantic skill defined with prompt templates
string folder = RepoFiles.SampleSkillsPath();
var sumSkill = kernel.ImportSemanticSkillFromDirectory(
folder,
"SummarizeSkill");
// Run
var ask = "What's the tallest building in South America";
var result1 = await kernel.RunAsync(
ask,
search["Search"]
);
var result2 = await kernel.RunAsync(
ask,
search["Search"],
sumSkill["Summarize"]
);
var result3 = await kernel.RunAsync(
ask,
search["Search"],
sumSkill["Notegen"]
);
Console.WriteLine(ask + "\n");
Console.WriteLine("Bing Answer: " + result1 + "\n");
Console.WriteLine("Summary: " + result2 + "\n");
Console.WriteLine("Notes: " + result3 + "\n");
}
}