mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 11:19:56 +00:00
"KernelSyntaxExamples" is the only outstanding project under /samples that still uses project references to access the kernel libraries. This change consolidates all the building, linked dotnet SDK code in SK-dotnet.sln into a single top-level folder. This will simplify build jobs, automatic code owner assignment, and other dev ops tasks. Coming next: other projects in samples will get removed from the dotnet/SK-dotnet.sln solution, and a new solution with dedicated builds created for the /samples folder. TBD: - Language-specific code "samples" will move into a similar subfolder for each language. - The current "/samples" folder (at the root) will likely become something like "apps", with the demo apps promoted to the top-level folder for better discoverability. - notebooks may also move to this folder in the future. Co-authored-by: name <email>
64 lines
1.9 KiB
C#
64 lines
1.9 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.SemanticKernel.AI.TextCompletion;
|
|
using Microsoft.SemanticKernel.Connectors.AI.OpenAI.TextCompletion;
|
|
using RepoUtils;
|
|
|
|
/**
|
|
* The following example shows how to use Semantic Kernel with Text Completion as streaming
|
|
*/
|
|
// ReSharper disable once InconsistentNaming
|
|
public static class Example32_StreamingCompletion
|
|
{
|
|
public static async Task RunAsync()
|
|
{
|
|
await AzureOpenAITextCompletionStreamAsync();
|
|
await OpenAITextCompletionStreamAsync();
|
|
}
|
|
|
|
private static async Task AzureOpenAITextCompletionStreamAsync()
|
|
{
|
|
Console.WriteLine("======== Azure OpenAI - Text Completion - Raw Streaming ========");
|
|
|
|
var textCompletion = new AzureTextCompletion(
|
|
Env.Var("AZURE_OPENAI_DEPLOYMENT_NAME"),
|
|
Env.Var("AZURE_OPENAI_ENDPOINT"),
|
|
Env.Var("AZURE_OPENAI_KEY"));
|
|
|
|
await TextCompletionStreamAsync(textCompletion);
|
|
}
|
|
|
|
private static async Task OpenAITextCompletionStreamAsync()
|
|
{
|
|
Console.WriteLine("======== Open AI - Text Completion - Raw Streaming ========");
|
|
|
|
var textCompletion = new OpenAITextCompletion("text-davinci-003", Env.Var("OPENAI_API_KEY"));
|
|
|
|
await TextCompletionStreamAsync(textCompletion);
|
|
}
|
|
|
|
private static async Task TextCompletionStreamAsync(ITextCompletion textCompletion)
|
|
{
|
|
var requestSettings = new CompleteRequestSettings()
|
|
{
|
|
MaxTokens = 100,
|
|
FrequencyPenalty = 0,
|
|
PresencePenalty = 0,
|
|
Temperature = 1,
|
|
TopP = 0.5
|
|
};
|
|
|
|
var prompt = "Write one paragraph why AI is awesome";
|
|
|
|
Console.WriteLine("Prompt: " + prompt);
|
|
await foreach (string message in textCompletion.CompleteStreamAsync(prompt, requestSettings))
|
|
{
|
|
Console.Write(message);
|
|
}
|
|
|
|
Console.WriteLine();
|
|
}
|
|
}
|