@@ -58,6 +58,7 @@ Complete the following steps to create a .NET console app that will connect to y
5858
5959 ` ` ` dotnetcli
6060 dotnet add package Microsoft.SemanticKernel
61+ dotnet add package Microsoft.SemanticKernel.Connectors.Ollama
6162 ` ` `
6263
63641. Open the new app in your editor of choice, such as Visual Studio Code.
@@ -72,45 +73,7 @@ The Semantic Kernel SDK provides many services and features to connect to AI mod
7273
73741. Open the _Program.cs_ file and replace the contents of the file with the following code:
7475
75- ```csharp
76- using Microsoft.SemanticKernel;
77- using Microsoft.SemanticKernel.ChatCompletion;
78-
79- // Create a kernel with OpenAI chat completion
80- #pragma warning disable SKEXP0010
81- Kernel kernel = Kernel.CreateBuilder()
82- .AddOpenAIChatCompletion(
83- modelId: "phi3:mini",
84- endpoint: new Uri("http://localhost:11434"),
85- apiKey: "")
86- .Build();
87-
88- var aiChatService = kernel.GetRequiredService<IChatCompletionService>();
89- var chatHistory = new ChatHistory();
90-
91- while (true)
92- {
93- // Get user prompt and add to chat history
94- Console.WriteLine("Your prompt:");
95- var userPrompt = Console.ReadLine();
96- chatHistory.Add(new ChatMessageContent(AuthorRole.User, userPrompt));
97-
98- // Stream the AI response and add to chat history
99- Console.WriteLine("AI Response:");
100- var response = "";
101- await foreach(var item in
102- aiChatService.GetStreamingChatMessageContentsAsync(chatHistory))
103- {
104- Console.Write(item.Content);
105- response += item.Content;
106- }
107- chatHistory.Add(new ChatMessageContent(AuthorRole.Assistant, response));
108- Console.WriteLine();
109- }
110- ```
111-
112- > [!NOTE]
113- > The `#pragma warning disable SKEXP0010` line is included due to the experimental state of some Semantic Kernel SDK features.
76+ :::code language="csharp" source="snippets/local-ai/program.cs" :::
11477
11578 The preceding code accomplishes the following tasks:
11679 - Creates a `Kernel` object and uses it to retrieve a chat completion service.
0 commit comments