Files
semantic-kernel/dotnet/samples/KernelSyntaxExamples/Example27_PromptFunctionsUsingChatGPT.cs
T
Roger Barreto b99b780eca .Net Kernel Examples as tests (#4526)
### Motivation and Context

Convert Kernel Examples as Integration Tests.
2024-01-16 19:16:24 +00:00

45 lines
1.3 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System.Threading.Tasks;
using Microsoft.SemanticKernel;
using Xunit;
using Xunit.Abstractions;
namespace Examples;
/// <summary>
/// This example shows how to use GPT3.5 Chat model for prompts and prompt functions.
/// </summary>
public class Example27_PromptFunctionsUsingChatGPT : BaseTest
{
[Fact]
public async Task RunAsync()
{
WriteLine("======== Using Chat GPT model for text generation ========");
Kernel kernel = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(
deploymentName: TestConfiguration.AzureOpenAI.ChatDeploymentName,
endpoint: TestConfiguration.AzureOpenAI.Endpoint,
apiKey: TestConfiguration.AzureOpenAI.ApiKey,
modelId: TestConfiguration.AzureOpenAI.ChatModelId)
.Build();
var func = kernel.CreateFunctionFromPrompt(
"List the two planets closest to '{{$input}}', excluding moons, using bullet points.");
var result = await func.InvokeAsync(kernel, new() { ["input"] = "Jupiter" });
WriteLine(result.GetValue<string>());
/*
Output:
- Saturn
- Uranus
*/
}
public Example27_PromptFunctionsUsingChatGPT(ITestOutputHelper output) : base(output)
{
}
}