Skip to content

Commit 7642e84

Browse files
committed
Added ollama example
1 parent d911530 commit 7642e84

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

SemanticKernel.Ollama/Program.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Microsoft.SemanticKernel.ChatCompletion;
2+
using Microsoft.SemanticKernel.Connectors.Ollama;
3+
4+
var chatService = new OllamaChatCompletionService(modelId: "phi3", endpoint: new Uri("http://localhost:11434"));
5+
6+
var chatHistory = new ChatHistory("You are a helpful assistant that knows about AI.");
7+
8+
string message = string.Empty;
9+
while (message != "stop")
10+
{
11+
message = Console.ReadLine();
12+
if (message != "stop")
13+
{
14+
chatHistory.AddUserMessage(message);
15+
var reply = await chatService.GetChatMessageContentAsync(chatHistory);
16+
chatHistory.AddAssistantMessage(reply.Content);
17+
Console.WriteLine(reply.Content);
18+
}
19+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<UserSecretsId>d8a0c0b0-0450-40df-90f1-7459475d065a</UserSecretsId>
9+
<NoWarn>$(NoWarn);CS8618,IDE0009,CA1051,CA1050,CA1707,CA1054,CA2007,VSTHRD111,CS1591,RCS1110,RCS1243,CA5394,SKEXP0001,SKEXP0010,SKEXP0020,SKEXP0040,SKEXP0050,SKEXP0060,SKEXP0070,SKEXP0101</NoWarn>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.SemanticKernel" Version="1.18.2" />
14+
<PackageReference Include="Microsoft.SemanticKernel.Connectors.Ollama" Version="1.19.0-alpha" />
15+
</ItemGroup>
16+
17+
</Project>

SemanticKernel.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SemanticKernel.KernelMemory
3535
EndProject
3636
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SemanticKernel.Prompty", "SemanticKernel.Prompty\SemanticKernel.Prompty.csproj", "{6377072C-AC5F-43CF-933C-24E03B0A4044}"
3737
EndProject
38-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SemanticKernel.Agents", "SemanticKernel.Agents\SemanticKernel.Agents.csproj", "{7940E7EA-5E5D-40FA-9F87-10A8D0B5D31B}"
38+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SemanticKernel.Agents", "SemanticKernel.Agents\SemanticKernel.Agents.csproj", "{7940E7EA-5E5D-40FA-9F87-10A8D0B5D31B}"
3939
EndProject
4040
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5A15B935-B600-44E7-B376-CE0F92941340}"
4141
EndProject
42+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SemanticKernel.Ollama", "SemanticKernel.Ollama\SemanticKernel.Ollama.csproj", "{FE8D561E-5482-4DF6-B51D-0B315FC330F7}"
43+
EndProject
4244
Global
4345
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4446
Debug|Any CPU = Debug|Any CPU
@@ -113,6 +115,10 @@ Global
113115
{7940E7EA-5E5D-40FA-9F87-10A8D0B5D31B}.Debug|Any CPU.Build.0 = Debug|Any CPU
114116
{7940E7EA-5E5D-40FA-9F87-10A8D0B5D31B}.Release|Any CPU.ActiveCfg = Release|Any CPU
115117
{7940E7EA-5E5D-40FA-9F87-10A8D0B5D31B}.Release|Any CPU.Build.0 = Release|Any CPU
118+
{FE8D561E-5482-4DF6-B51D-0B315FC330F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
119+
{FE8D561E-5482-4DF6-B51D-0B315FC330F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
120+
{FE8D561E-5482-4DF6-B51D-0B315FC330F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
121+
{FE8D561E-5482-4DF6-B51D-0B315FC330F7}.Release|Any CPU.Build.0 = Release|Any CPU
116122
EndGlobalSection
117123
GlobalSection(SolutionProperties) = preSolution
118124
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)