Encamina.Enmarcha.SemanticKernel.Plugins.QuestionAnswering
8.1.8
See the version list below for details.
dotnet add package Encamina.Enmarcha.SemanticKernel.Plugins.QuestionAnswering --version 8.1.8
NuGet\Install-Package Encamina.Enmarcha.SemanticKernel.Plugins.QuestionAnswering -Version 8.1.8
<PackageReference Include="Encamina.Enmarcha.SemanticKernel.Plugins.QuestionAnswering" Version="8.1.8" />
paket add Encamina.Enmarcha.SemanticKernel.Plugins.QuestionAnswering --version 8.1.8
#r "nuget: Encamina.Enmarcha.SemanticKernel.Plugins.QuestionAnswering, 8.1.8"
// Install Encamina.Enmarcha.SemanticKernel.Plugins.QuestionAnswering as a Cake Addin #addin nuget:?package=Encamina.Enmarcha.SemanticKernel.Plugins.QuestionAnswering&version=8.1.8 // Install Encamina.Enmarcha.SemanticKernel.Plugins.QuestionAnswering as a Cake Tool #tool nuget:?package=Encamina.Enmarcha.SemanticKernel.Plugins.QuestionAnswering&version=8.1.8
Semantic Kernel - Question Answering Plugin
The Question Answering Plugin is a project that provides functionality as a plugin for answering questions based on a given context or based on the information stored in the Semantic Kernel's memory.
Setup
Nuget package
First, install NuGet. Then, install Encamina.Enmarcha.SemanticKernel.QuestionAnswering.Plugins from the package manager console:
PM> Install-Package Encamina.Enmarcha.SemanticKernel.QuestionAnswering.Plugins
.NET CLI:
Install .NET CLI. Next, install Encamina.Enmarcha.SemanticKernel.QuestionAnswering.Plugins from the .NET CLI:
dotnet add package Encamina.Enmarcha.SemanticKernel.QuestionAnswering.Plugins
How to use
Within the QuestionAnsweringPlugin
, there are two available functions for answering questions. On the one hand, there is a function in QuestionAnsweringFromContext, which, given a context and a question, it answers the question based on the provided context. On the other hand, the plugin QuestionAnsweringFromMemoryQuery searches within Semantic Kernel's memory for the most relevant results to the posed question, which are provided as the context to answer the question.
QuestionAnsweringFromContext Function
This is a semantic function (skprompt.txt/config.json) within Semantic Kernel that provides an answer to a question based on a provided context using Language Model Models (LLMs) such as OpenAI, Azure OpenAI, to name but a few.
To use it, the first step is to import it into Semantic Kernel.
// Entry point
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
// ...
});
// ...
builder.Services.AddScoped(sp =>
{
var kernel = new KernelBuilder()
.WithAzureChatCompletionService("<YOUR DEPLOYMENT NAME>", "<YOUR AZURE ENDPOINT>", "<YOUR API KEY>", alsoAsTextCompletion: true)
//.WithAzureTextCompletionService("<YOUR DEPLOYMENT NAME>", "<YOUR AZURE ENDPOINT>", "<YOUR API KEY>")
/// ...
.Build();
// ...
kernel.ImportQuestionAnsweringPlugin(sp, ILengthFunctions.LengthByTokenCount);
return kernel;
});
Now you can inject the kernel via constructor, and the question capabilities are already available.
public class MyClass
{
private readonly Kernel kernel;
public MyClass(Kernel kernel)
{
this.kernel = kernel;
}
public async Task TestQuestionAnsweringFromContextAsync()
{
var contextVariables = new ContextVariables();
contextVariables.Set(PluginsInfo.QuestionAnsweringPlugin.Functions.QuestionAnsweringFromContext.Parameters.Input, "What year was the French Revolution?");
contextVariables.Set(PluginsInfo.QuestionAnsweringPlugin.Functions.QuestionAnsweringFromContext.Parameters.Context,
@"The French Revolution[a] was a period of radical political and societal change in France that began with the Estates General of 1789,
and ended with the formation of the French Consulate in November 1799. Many of its ideas are considered fundamental principles of liberal democracy,
while the values and institutions it created remain central to French political discourse. Its causes are generally agreed to be a combination of social,
political and economic factors, which the Ancien Régime proved unable to manage. In May 1789, widespread social distress led to the convocation of the Estates General,
which was converted into a National Assembly in June. Continuing unrest culminated in the Storming of the Bastille on 14 July, which led to a series of radical
measures by the Assembly, including the abolition of feudalism, the imposition of state control over the Catholic Church in France, and extension of the right
to vote.");
var functionQuestionAnswering = kernel.Func(PluginsInfo.QuestionAnsweringPlugin.Name, PluginsInfo.QuestionAnsweringPlugin.Functions.QuestionAnsweringFromContext.Name);
var resultContext = await kernel.RunAsync(contextVariables, functionQuestionAnswering);
}
}
In the previous example, the question has been included within the Input
parameter, and the context from which the answer is derived is in the Context
parameter. Within resultContext
, you will find texts that say something like The French Revolution began in 1789.
QuestionAnsweringFromMemoryQuery Function
This is a native function of Semantic Kernel that, given a question, searches for the most relevant result within Semantic Kernel's memory and uses that context to call the semantic function QuestionAnsweringFromContext
in order to generate a response.
To use it, the first step is to import it into Semantic Kernel.
// Entry point
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
// ...
});
// ...
builder.Services.AddScoped(sp =>
{
var kernel = new KernelBuilder()
.WithAzureChatCompletionService("<YOUR DEPLOYMENT NAME>", "<YOUR AZURE ENDPOINT>", "<YOUR API KEY>", alsoAsTextCompletion: true)
.WithAzureTextEmbeddingGenerationService("<YOUR DEPLOYMENT NAME>", "<YOUR AZURE ENDPOINT>", "<YOUR API KEY>")
//.WithAzureTextCompletionService("<YOUR DEPLOYMENT NAME>", "<YOUR AZURE ENDPOINT>", "<YOUR API KEY>")
//.WithOpenAITextEmbeddingGenerationService("<YOUR MODEL ID>", "<YOUR API KEY>", "<YOUR API KEY>")
/// ...
.Build();
// ...
var questionAnsweringPlugin = new QuestionAnsweringPlugin(kernel, "<YOUR DEPLOYMENT NAME>", ILengthFunctions.LengthByTokenCount);
kernel.ImportQuestionAnsweringPlugin(sp, ILengthFunctions.LengthByTokenCount);
// Requires Encamina.Enmarcha.SemanticKernel.Plugins.Memory nuget
kernel.ImportMemoryPlugin(ILengthFunctions.LengthByTokenCount);
return kernel;
});
Now you can inject the kernel via constructor, and the memory question capabilities are already available.
public class MyClass
{
private readonly Kernel kernel;
public MyClass(Kernel kernel)
{
this.kernel = kernel;
}
public async Task TestQuestionAnsweringFromMemoryAsync()
{
var contextVariables = new ContextVariables();
contextVariables.Set(PluginsInfo.QuestionAnsweringPlugin.Functions.QuestionAnsweringFromMemoryQuery.Parameters.Question, "What year was the French Revolution?");
contextVariables.Set(PluginsInfo.QuestionAnsweringPlugin.Functions.QuestionAnsweringFromMemoryQuery.Parameters.CollectionSeparator, ",");
contextVariables.Set(PluginsInfo.QuestionAnsweringPlugin.Functions.QuestionAnsweringFromMemoryQuery.Parameters.CollectionsStr, "collection-1,collection-2");
contextVariables.Set(PluginsInfo.QuestionAnsweringPlugin.Functions.QuestionAnsweringFromMemoryQuery.Parameters.MinRelevance, "0.8");
contextVariables.Set(PluginsInfo.QuestionAnsweringPlugin.Functions.QuestionAnsweringFromMemoryQuery.Parameters.ResultsLimit, "1");
contextVariables.Set(PluginsInfo.QuestionAnsweringPlugin.Functions.QuestionAnsweringFromMemoryQuery.Parameters.ResponseTokenLimit, "300");
var functionQuestionAnswering = kernel.Func(PluginsInfo.QuestionAnsweringPlugin.Name, PluginsInfo.QuestionAnsweringPlugin.Functions.QuestionAnsweringFromMemoryQuery.Name);
var resultContext = await kernel.RunAsync(contextVariables, functionQuestionAnswering);
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- CommunityToolkit.Diagnostics (>= 8.2.2)
- Encamina.Enmarcha.AI.OpenAI.Azure (>= 8.1.8)
- Encamina.Enmarcha.SemanticKernel (>= 8.1.8)
- Encamina.Enmarcha.SemanticKernel.Plugins.Memory (>= 8.1.8)
- Microsoft.SemanticKernel.Abstractions (>= 1.17.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
8.2.0 | 151 | 10/22/2024 |
8.2.0-preview-01-m01 | 94 | 9/17/2024 |
8.1.9-preview-03 | 58 | 11/19/2024 |
8.1.9-preview-02 | 62 | 10/22/2024 |
8.1.9-preview-01 | 187 | 10/4/2024 |
8.1.8 | 153 | 9/23/2024 |
8.1.8-preview-07 | 226 | 9/12/2024 |
8.1.8-preview-06 | 148 | 9/11/2024 |
8.1.8-preview-05 | 94 | 9/10/2024 |
8.1.8-preview-04 | 213 | 8/16/2024 |
8.1.8-preview-03 | 133 | 8/13/2024 |
8.1.8-preview-02 | 98 | 8/13/2024 |
8.1.8-preview-01 | 98 | 8/12/2024 |
8.1.7 | 100 | 8/7/2024 |
8.1.7-preview-09 | 115 | 7/3/2024 |
8.1.7-preview-08 | 73 | 7/2/2024 |
8.1.7-preview-07 | 88 | 6/10/2024 |
8.1.7-preview-06 | 92 | 6/10/2024 |
8.1.7-preview-05 | 108 | 6/6/2024 |
8.1.7-preview-04 | 101 | 6/6/2024 |
8.1.7-preview-03 | 94 | 5/24/2024 |
8.1.7-preview-02 | 95 | 5/10/2024 |
8.1.7-preview-01 | 108 | 5/8/2024 |
8.1.6 | 143 | 5/7/2024 |
8.1.6-preview-08 | 60 | 5/2/2024 |
8.1.6-preview-07 | 97 | 4/29/2024 |
8.1.6-preview-06 | 259 | 4/26/2024 |
8.1.6-preview-05 | 92 | 4/24/2024 |
8.1.6-preview-04 | 152 | 4/22/2024 |
8.1.6-preview-03 | 87 | 4/22/2024 |
8.1.6-preview-02 | 121 | 4/17/2024 |
8.1.6-preview-01 | 97 | 4/15/2024 |
8.1.5 | 127 | 4/15/2024 |
8.1.5-preview-15 | 92 | 4/10/2024 |
8.1.5-preview-14 | 126 | 3/20/2024 |
8.1.5-preview-13 | 84 | 3/18/2024 |
8.1.5-preview-12 | 109 | 3/13/2024 |
8.1.5-preview-11 | 100 | 3/13/2024 |
8.1.5-preview-10 | 121 | 3/13/2024 |
8.1.5-preview-09 | 95 | 3/12/2024 |
8.1.5-preview-08 | 87 | 3/12/2024 |
8.1.5-preview-07 | 103 | 3/8/2024 |
8.1.5-preview-06 | 213 | 3/8/2024 |
8.1.5-preview-05 | 105 | 3/7/2024 |
8.1.5-preview-04 | 96 | 3/7/2024 |
8.1.5-preview-03 | 91 | 3/7/2024 |
8.1.5-preview-02 | 157 | 2/28/2024 |
8.1.5-preview-01 | 135 | 2/19/2024 |
8.1.4 | 184 | 2/15/2024 |
8.1.3 | 131 | 2/13/2024 |
8.1.3-preview-07 | 80 | 2/13/2024 |
8.1.3-preview-06 | 84 | 2/12/2024 |
8.1.3-preview-05 | 96 | 2/9/2024 |
8.1.3-preview-04 | 88 | 2/8/2024 |
8.1.3-preview-03 | 87 | 2/7/2024 |
8.1.3-preview-02 | 90 | 2/2/2024 |
8.1.3-preview-01 | 92 | 2/2/2024 |
8.1.2 | 131 | 2/1/2024 |
8.1.2-preview-9 | 103 | 1/22/2024 |
8.1.2-preview-8 | 93 | 1/19/2024 |
8.1.2-preview-7 | 84 | 1/19/2024 |
8.1.2-preview-6 | 92 | 1/19/2024 |
8.1.2-preview-5 | 87 | 1/19/2024 |
8.1.2-preview-4 | 93 | 1/19/2024 |
8.1.2-preview-3 | 86 | 1/18/2024 |
8.1.2-preview-2 | 90 | 1/18/2024 |
8.1.2-preview-16 | 72 | 1/31/2024 |
8.1.2-preview-15 | 94 | 1/31/2024 |
8.1.2-preview-14 | 168 | 1/25/2024 |
8.1.2-preview-13 | 91 | 1/25/2024 |
8.1.2-preview-12 | 104 | 1/23/2024 |
8.1.2-preview-11 | 102 | 1/23/2024 |
8.1.2-preview-10 | 94 | 1/22/2024 |
8.1.2-preview-1 | 78 | 1/18/2024 |
8.1.1 | 135 | 1/18/2024 |
8.1.0 | 97 | 1/18/2024 |
8.0.3 | 152 | 12/29/2023 |
8.0.1 | 162 | 12/14/2023 |
8.0.0 | 163 | 12/7/2023 |
6.0.4.3 | 148 | 12/29/2023 |
6.0.4.2 | 151 | 12/20/2023 |
6.0.4.1 | 113 | 12/19/2023 |
6.0.4 | 180 | 12/4/2023 |
6.0.3.20 | 157 | 11/27/2023 |
6.0.3.19 | 144 | 11/22/2023 |