mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 02:19:06 +00:00
45 lines
1.3 KiB
C#
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)
|
|
{
|
|
}
|
|
}
|