Logo

dev-resources.site

for different kinds of informations.

Semantic Tests for SemanticKernel Plugins using skUnit

Published at
1/4/2024
Categories
openai
semantickernel
csharp
dotnet
Author
mehrandvd
Author
9 person written this
mehrandvd
open
Semantic Tests for SemanticKernel Plugins using skUnit

Exploring SemanticKernel

This week, I had the chance to explore the SemanticKernel code base, particularly the core plugins. SemanticKernel comes equipped with these built-in plugins:

  • ConversationSummaryPlugin
  • FilePlugin
  • HttpPlugin
  • MathPlugin
  • TextPlugin
  • TimePlugin
  • WaitPlugin

When I looked at the Plugins.UnitTests project, I noticed that all the unit tests are passing. But there's something interesting:

Each plugin has a corresponding test file, except for ConversationSummaryPlugin.

You might wonder why!?

Here's the thing. All the other plugins have outputs that can be tested because they're deterministic. But ConversationSummaryPlugin is a different story.

For instance, it has a function called SummarizeConversation that does exactly what it says - it summarizes a conversation. But how do you test something like that? You need to check the meaning of the output, not just if the strings are identical.

Let's consider this test case:

USER: Is Eiffel tall?
AGENT: Yes it is
USER: What about Everest mountain?
AGENT: Yes it is tall too
USER: What about a mouse?
AGENT: No it is not tall.
Enter fullscreen mode Exit fullscreen mode

If you call SummarizeConversation with this input, you should get something like:

Expected output: The conversation is about the heights of different things. Both the Eiffel Tower and Mount Everest are considered tall, while a mouse is not.

But how do you write a test for that? You need to use semantic assertions, something like:

SemanticAssert.HasCondition(
   output, 
   "It mentions that both the Eiffel Tower and Mount Everest are tall.")
Enter fullscreen mode Exit fullscreen mode

While you can do this now with the SemanticValidation library, I'm going to introduce an even simpler way in this post: using the skUnit library for semantic unit testing. Sounds exciting, right?

Let's Dive into Testing with skUnit

With skUnit, you can whip up scenarios in markdown files. Here's an example:

# SCENARIO Height Discussion

## PARAMETER input
USER: Is Eiffel tall?
AGENT: Yes it is
USER: What about Everest mountain?
AGENT: Yes it is tall too
USER: What about a mouse?
AGENT: No it is not tall.


## ANSWER
The conversation revolves around the heights of different things. Both the Eiffel Tower and Mount Everest get the tall vote, while a mouse doesn't.

## CHECK SemanticCondition
It mentions that both the Eiffel Tower and Mount Everest are tall.

## CHECK SemanticCondition
It mentions that a mouse isn't tall.
Enter fullscreen mode Exit fullscreen mode

As you can see, in a scenario, you can set the parameters and the expected answer. Then, you can specify the semantic conditions that the output should meet. The best part? skUnit can run this test for you automatically, and you can see it acing the test. How cool is that?

Test result

What’s great is that these scenarios are valid .md files. This means they’re not just for the tech-savvy among us - anyone can read and understand them! Isn’t that neat?

Markdown

Finally

I enjoy writing semantic tests for SemanticKernel plugins, and I have created a repository to share some of them: https://github.com/mehrandvd/semantic-kernel-skunit-tests

You can see an example of a test scenario for the SummarizeConversationPlugin here.

semantickernel Article's
25 articles in total
Favicon
Semantic Kernel: Crea un API para Generación de Texto con Ollama y Aspire
Favicon
Azure OpenAI Error Handling in Semantic Kernel
Favicon
Local AI apps with C#, Semantic Kernel and Ollama
Favicon
Working with multiple language models in Semantic Kernel
Favicon
Lightweight AI Evaluation with SemanticKernel
Favicon
Chatbot with Semantic Kernel - Part 4: Whisper 👂
Favicon
Step-by-Step Guide: Write Your First AI Storyteller with Ollama (llama3.2) and Semantic Kernel in C#
Favicon
Run LLMs Locally with Ollama & Semantic Kernel in .NET: A Quick Start
Favicon
OpenAI chat completion with Json output format
Favicon
Chatbot with Semantic Kernel - Part 3: Inspector & tokens 🔎
Favicon
Building a Digital Dungeon Master with Semantic Kernel, C#, and Azure
Favicon
Chatbot with Semantic Kernel - Part 2: Plugins 🧩
Favicon
Chatbot with Semantic Kernel - Part 1: Setup and first steps 👣
Favicon
Building a Semantic Kernel with F# for Enhanced AI Interaction
Favicon
Smooth Streaming Control with System.Threading.Channels in GPT API Programming
Favicon
Discover the Future of AI with My New Book: Developing GenAI Applications with LangChain, Semantic Kernel and Powered by LLMs
Favicon
Introducing Semantic Kernel
Favicon
Natural Programming ❤️️ with TypeChat & Semantic Kernel
Favicon
How to Use #SemanticKernel, Plugins – 2/N
Favicon
#SemanticKernel – 📎Chat Service demo running Phi-2 LLM locally with #LMStudio
Favicon
Harnessing Semantic Kernel for LLM Integration
Favicon
A Quick Walkthrough of Semantic Kernel's Kusto Connector for Vector Database Integration
Favicon
Semantic Tests for SemanticKernel Plugins using skUnit
Favicon
SemanticValidation: A Library for Semantic Checks with OpenAI
Favicon
Getting Started with Semantic Kernel and C#

Featured ones: