dev-resources.site
for different kinds of informations.
Local AI apps with C#, Semantic Kernel and Ollama
Published at
1/1/2025
Categories
ollama
semantickernel
csharp
dotnet
Author
skriyas
Author
7 person written this
skriyas
open
Welcome to my first post ever! Enough talk. Let's get started.
Impatient? GitHub.
Make sure that you have the following things with you in your local:
Project Setup
This is going to be a quick console app. Make sure to install all the nugets mentioned below.
dotnet new console -n sk-console -o sk-console
cd sk-console\
dotnet add package Microsoft.SemanticKernel
dotnet add package Microsoft.SemanticKernel.Connectors.Ollama --prerelease
*At the time of this writing, Semantic Kernel's Ollama connector is still in preview. So you might want to update the package command.
Coding Time
In your program.cs file
- use the necessary packages
- create a builder for Semantic Kernel using the
Kernel
class and inject theAddOllamaChatCompletion()
service.
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
var builder = Kernel.CreateBuilder();
var uri = new Uri("http://localhost:11434");
#pragma warning disable SKEXP0070 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
builder.Services.AddOllamaChatCompletion("llama3.2", uri);
#pragma warning restore SKEXP0070 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
- Once after building the kernel get the chatCompletionService using which the chat invoked.
var kernel = builder.Build();
var chatCompletionService = kernel.GetRequiredService<IChatCompletionService>();
try
{
ChatMessageContent chatMessage = await chatCompletionService
.GetChatMessageContentAsync("Hi, can you tell me a dad joke");
Console.WriteLine(chatMessage.ToString());
}
For my next post, Iβll implement use the same implementation in a WebAPI project.
That's it. Good day!
semantickernel Article's
25 articles in total
Semantic Kernel: Crea un API para GeneraciΓ³n de Texto con Ollama y Aspire
read article
Azure OpenAI Error Handling in Semantic Kernel
read article
Local AI apps with C#, Semantic Kernel and Ollama
currently reading
Working with multiple language models in Semantic Kernel
read article
Lightweight AI Evaluation with SemanticKernel
read article
Chatbot with Semantic Kernel - Part 4: Whisper π
read article
Step-by-Step Guide: Write Your First AI Storyteller with Ollama (llama3.2) and Semantic Kernel in C#
read article
Run LLMs Locally with Ollama & Semantic Kernel in .NET: A Quick Start
read article
OpenAI chat completion with Json output format
read article
Chatbot with Semantic Kernel - Part 3: Inspector & tokens π
read article
Building a Digital Dungeon Master with Semantic Kernel, C#, and Azure
read article
Chatbot with Semantic Kernel - Part 2: Plugins π§©
read article
Chatbot with Semantic Kernel - Part 1: Setup and first steps π£
read article
Building a Semantic Kernel with F# for Enhanced AI Interaction
read article
Smooth Streaming Control with System.Threading.Channels in GPT API Programming
read article
Discover the Future of AI with My New Book: Developing GenAI Applications with LangChain, Semantic Kernel and Powered by LLMs
read article
Introducing Semantic Kernel
read article
Natural Programming β€οΈοΈ with TypeChat & Semantic Kernel
read article
How to Use #SemanticKernel, Plugins β 2/N
read article
#SemanticKernel β πChat Service demo running Phi-2 LLM locally with #LMStudio
read article
Harnessing Semantic Kernel for LLM Integration
read article
A Quick Walkthrough of Semantic Kernel's Kusto Connector for Vector Database Integration
read article
Semantic Tests for SemanticKernel Plugins using skUnit
read article
SemanticValidation: A Library for Semantic Checks with OpenAI
read article
Getting Started with Semantic Kernel and C#
read article
Featured ones: