Ollama + KernelFunctions + EntityFramework

Author:

First of all, what is KernelFunctions?

In the context of Semantic Kernel, a kernel function is a fundamental concept that enables the orchestration of AI operations. It creates the Single Responsibility of a certain functionality of AI method.

What is Ollama

Ollama it’s a tool that helps developers to work on an AI environment without having to depending use OpenAI (or any other AI cloud provider service like Azure). It’s like having a chatgpt running on localhost.

The sample

This sample contains:

  • Minimal API – .NET 9
  • Ollama running on localhost:11343
  • A Docker SQL Server Image
  • Entity Framework with the following entities
    • Student
    • Class
    • Teacher

Program.cs

General view of Program.cs

This is my local config, note that Ollama is running on http://localhost:11434 and the model I’m using is llama3.2

Note that I’m injecting the dbContext on the KernelBuilder

Running the project and executing

Here I’m calling /ask endpoint the request of “Create new student called Renyo Borges.”. This will make the KernelFunction get triggered due to the description

The the request above is gonna call the code below

The record was added to the DB

Conclusion

Kernel Function works really and it enables developers to easily build AI-powered applications by orchestrating AI functions.

It’s a start point to build your application towards a business logic.

Code

Leave a Reply

Your email address will not be published. Required fields are marked *