Files
semantic-kernel/dotnet/samples/KernelSyntaxExamples/Example27_SemanticFunctionsUsingChatGPT.cs
T
2e84b30e21 .Net: Change public APIs to accept ILoggerFactory (#2472)
### Motivation and Context

Following best practices for libraries outlined at
https://learn.microsoft.com/en-us/dotnet/core/extensions/logging-library-authors,
SK should generally be taking an ILoggerFactory rather than an ILogger.
This allows individual components to each get a logger with its own
category applied.

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄

---------

Co-authored-by: Shawn Callegari <[email protected]>
Co-authored-by: Lee Miller <[email protected]>
2023-08-21 23:39:58 +00:00

37 lines
1.1 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Threading.Tasks;
using Microsoft.SemanticKernel;
using RepoUtils;
/**
* This example shows how to use GPT3.5 Chat model for prompts and semantic functions.
*/
// ReSharper disable once InconsistentNaming
public static class Example27_SemanticFunctionsUsingChatGPT
{
public static async Task RunAsync()
{
Console.WriteLine("======== Using Chat GPT model for text completion ========");
IKernel kernel = new KernelBuilder()
.WithLoggerFactory(ConsoleLogger.LoggerFactory)
.WithAzureChatCompletionService(TestConfiguration.AzureOpenAI.ChatDeploymentName, "https://....openai.azure.com/", "...API KEY...")
.Build();
var func = kernel.CreateSemanticFunction(
"List the two planets closest to '{{$input}}', excluding moons, using bullet points.");
var result = await func.InvokeAsync("Jupiter");
Console.WriteLine(result);
/*
Output:
- Saturn
- Uranus
*/
}
}