Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions dotnet/samples/Concepts/TextGeneration/Ollama_TextGeneration.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.HuggingFace;
using Microsoft.SemanticKernel.TextGeneration;
using xRetry;

Expand Down Expand Up @@ -62,19 +61,14 @@ public async Task RunStreamingExampleAsync()
Console.WriteLine($"\n======== HuggingFace {model} streaming example ========\n");

Kernel kernel = Kernel.CreateBuilder()
.AddHuggingFaceTextGeneration(
model: model,
apiKey: TestConfiguration.HuggingFace.ApiKey)
.AddOllamaTextGeneration(
endpoint: new Uri(TestConfiguration.Ollama.Endpoint),
modelId: TestConfiguration.Ollama.ModelId)
.Build();

var settings = new HuggingFacePromptExecutionSettings { UseCache = false };

var questionAnswerFunction = kernel.CreateFunctionFromPrompt("Question: {{$input}}; Answer:", new HuggingFacePromptExecutionSettings
{
UseCache = false
});
var questionAnswerFunction = kernel.CreateFunctionFromPrompt("Question: {{$input}}; Answer:");

await foreach (string text in kernel.InvokePromptStreamingAsync<string>("Question: {{$input}}; Answer:", new(settings) { ["input"] = "What is New York?" }))
await foreach (string text in kernel.InvokePromptStreamingAsync<string>("Question: {{$input}}; Answer:", new() { ["input"] = "What is New York?" }))
{
Console.Write(text);
}
Expand Down