SemanticValidation is a library that integrates OpenAI’s powerful language models with validation systems. It allows you to perform semantic checks on your data and queries using natural language understanding.
It brings the power of OpenAI into the validation systems as easily as this:
var result = Semantic.AreSimilar("This automobile is red", "The car is red");
Console.WriteLine(result.IsValid);
// true
The interesting part is that: When it fails, it explains why! (thanks to OpenAI)
var result = Semantic.AreSimilar("This bicycle is red", "The car is red");
Console.WriteLine(result.IsValid);
// false
Console.WriteLine(result.Reason);
// The first text describes a red bicycle, while the second text describes a red car. They are not semantically equivalent.
Under the hood, it uses OpenAI and SemanticKernel to do all the semantic stuff.
There are other semantic methods available too. The HasConditoin
checks if a text
meets a special condition
. And again watch how
great it describes the reason for semantic validation failure.
var result = Semantic.HasCondition(
text: "This car is red",
condition: "It talks about trees"
Console.WriteLine(result.IsValid);
// false
Console.WriteLine(result.Reason);
// The input text does not talk about trees
Semantic Validation is available as a NuGet package that you can easily install in your project. To do so, run the following command in your terminal:
dotnet add package SemanticValidation
Next, you need to create an instance of the Semantic
class and pass your OpenAI subscription details as parameters:
var semantic = new Semantic(deployment, endpoint, apiKey);
That's it! You are ready to use Semantic Validation in your code. 😊