Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/mehrandvd/skunit
Browse files Browse the repository at this point in the history
  • Loading branch information
mehrandvd committed Jan 9, 2025
2 parents 6b9d6aa + 2b49446 commit d0847ca
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,13 @@
[![NuGet version (skUnit)](https://img.shields.io/nuget/v/skUnit.svg?style=flat)](https://www.nuget.org/packages/skUnit/)
[![NuGet downloads](https://img.shields.io/nuget/dt/skUnit.svg?style=flat)](https://www.nuget.org/packages/skUnit)

**skUnit** is a testing tool for [SemanticKernel](https://github.com/microsoft/semantic-kernel) units, such as _plugin functions_, _kernels_, _chat services_ and ...
**skUnit** is a testing tool for any `IChatClient` and [SemanticKernel](https://github.com/microsoft/semantic-kernel) units, such as _kernels_, _chat services_ and ...

For example, you can use skUnit to test a `GetSentiment` function that analyzes a text and returns its sentiment, such as _"Happy"_ or _"Sad"_.
You can write different scenarios to check how the function behaves with various inputs, such as:

```md
## PARAMETER input
Such a beautiful day it is

## ANSWER Equals
Happy
```

This scenario verifies that the function returns _"Happy"_ when the input is _"Such a beautiful day it is"_.

This is an [**Invocation Scenario**](https://github.com/mehrandvd/skunit/blob/main/docs/invocation-scenario-spec.md), which tests a single function call. You can also write [**Chat Scenarios**](https://github.com/mehrandvd/skunit/blob/main/docs/chat-scenario-spec.md), which test a sequence of interactions between the user and the SemanticKernel.
You can write [**Chat Scenarios**](https://github.com/mehrandvd/skunit/blob/main/docs/chat-scenario-spec.md), which test a sequence of interactions between the user and an `IChatClient` or a SemanticKernel.

# Chat Scenarios

A chat scenario is a way of testing how SemanticKernel units, such as plugin functions and kernels, respond to user inputs in skUnit.
A chat scenario is a way of testing how an `IChatClient`, responds to user inputs in skUnit.
A chat scenario consists of one or more sub-scenarios, each representing a dialogue turn between the user and the agent.

## Example
Expand Down Expand Up @@ -93,6 +80,10 @@ Executing tests is a straightforward process. You have the flexibility to utiliz
```csharp
var markdown = // Load it from .md file
var scenarios = await ChatScenario.LoadFromText(markdown);
var chatClient = CreateChatClient();
await ScenarioAssert.PassAsync(scenarios, chatClient);

// Or configure your way of processing the chat.
await ScenarioAssert.PassAsync(scenarios,
getAnswerFunc: async history =>
{
Expand Down Expand Up @@ -182,7 +173,6 @@ This output is generated line by line as the test is executed:

## Documents
To better understand skUnit, Check these documents:
- [Invocation Scenario Spec](https://github.com/mehrandvd/skunit/blob/main/docs/invocation-scenario-spec.md): The details of writing an InvocationScenario.
- [Chat Scenario Spec](https://github.com/mehrandvd/skunit/blob/main/docs/chat-scenario-spec.md): The details of writing an ChatScenario.
- [CHECK Statement Spec](https://github.com/mehrandvd/skunit/blob/main/docs/check-statements-spec.md): The various `CHECK` statements that you can use for assertion.

Expand Down Expand Up @@ -212,11 +202,13 @@ public class MyTest
{
var scenario = // Load your markdown.
var scenarios = await ChatScenario.LoadFromTest(scenario);
await SemanticAssert.PassAsync(scenarios, async history =>
{
var result = // your logic to be tested;
return result;
});
await ScenarioAssert.PassAsync(
scenarios,
getAnswerFunc: async history =>
{
var result = // your logic to be tested;
return result;
});
}
}
```
Expand Down

0 comments on commit d0847ca

Please sign in to comment.