Encamina.Enmarcha.SemanticKernel.Plugins.Chat
8.1.6-preview-05
See the version list below for details.
dotnet add package Encamina.Enmarcha.SemanticKernel.Plugins.Chat --version 8.1.6-preview-05
NuGet\Install-Package Encamina.Enmarcha.SemanticKernel.Plugins.Chat -Version 8.1.6-preview-05
<PackageReference Include="Encamina.Enmarcha.SemanticKernel.Plugins.Chat" Version="8.1.6-preview-05" />
paket add Encamina.Enmarcha.SemanticKernel.Plugins.Chat --version 8.1.6-preview-05
#r "nuget: Encamina.Enmarcha.SemanticKernel.Plugins.Chat, 8.1.6-preview-05"
// Install Encamina.Enmarcha.SemanticKernel.Plugins.Chat as a Cake Addin #addin nuget:?package=Encamina.Enmarcha.SemanticKernel.Plugins.Chat&version=8.1.6-preview-05&prerelease // Install Encamina.Enmarcha.SemanticKernel.Plugins.Chat as a Cake Tool #tool nuget:?package=Encamina.Enmarcha.SemanticKernel.Plugins.Chat&version=8.1.6-preview-05&prerelease
Semantic Kernel - Chat Plugin
Chat Plugin is a project that provides Chat functionality in the form of a Semantic Kernel Plugin. It allows users to interact while chatting and asking questions to an Artificial Intelligence, usually a Large Language Model (LLM). Additionally, it stores the conversation history.
Setup
Nuget package
First, install NuGet. Then, install Encamina.Enmarcha.SemanticKernel.Plugins.Chat from the package manager console:
PM> Install-Package Encamina.Enmarcha.SemanticKernel.Plugins.Chat
.NET CLI:
First, install .NET CLI. Then, install Encamina.Enmarcha.SemanticKernel.Plugins.Chat from the .NET CLI:
dotnet add package Encamina.Enmarcha.SemanticKernel.Plugins.Chat
How to use
To use ChatWithHistoryPlugin, the usual approach is to import it as a plugin within Semantic Kernel. The simplest way to do this is by using the extension method ImportChatWithHistoryPlugin, which handles the import of the Plugin into Semantic Kernel. However, some previous configuration is required before importing it.
First, you need to add the SemanticKernelOptions, ChatWithHistoryPluginOptions and ChatHistoryProviderOptions to your project configuration. You can achieve this by using any configuration provider. The followng code is an example of how the settings should look like using the appsettings.json
file:
{
// ...
"SemanticKernelOptions": {
"ChatModelName": "gpt-35-turbo", // Name (sort of a unique identifier) of the model to use for chat
"ChatModelDeploymentName": "gpt-35-turbo", // Model deployment name on the LLM (for example OpenAI) to use for chat
"EmbeddingsModelName": "text-embedding-ada-002", // Name (sort of a unique identifier) of the model to use for embeddings
"EmbeddingsModelDeploymentName": "text-embedding-ada-002", // Model deployment name on the LLM (for example OpenAI) to use for embeddings
"Endpoint": "https://your-url.openai.azure.com/", // Uri for an LLM resource (like OpenAI). This should include protocol and hostname.
"Key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", // Key credential used to authenticate to an LLM resource
},
"ChatWithHistoryPluginOptions": {
"ChatRequestSettings": {
"MaxTokens": 1000, // Maximum number of tokens to generate in the completion
"Temperature": 0.8, // Controls the randomness of the completion. The higher the temperature, the more random the completion
"TopP": 0.5, // Controls the diversity of the completion. The higher the TopP, the more diverse the completion.
}
},
"ChatHistoryProviderOptions": {
HistoryMaxMessages": 12,
}
// ...
}
Next, in Program.cs
or a similar entry point file in your project, add the following code.
// Entry point
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
// ...
});
// ...
var tokenLengthFunction = ILengthFunctions.LengthByTokenCount;
string cosmosContainer = "cosmosDbContainer"; // You probably want to save this in the appsettings or similar
// Or others configuration providers...
builder.Configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
// Requires Encamina.Enmarcha.SemanticKernel.Abstractions nuget
builder.Services.AddOptions<SemanticKernelOptions>().Bind(builder.Configuration.GetSection(nameof(SemanticKernelOptions)))
.ValidateDataAnnotations()
.ValidateOnStart();
builder.Services.AddOptions<ChatWithHistoryPluginOptions>().Bind(builder.Configuration.GetSection(nameof(ChatWithHistoryPluginOptions)))
.ValidateDataAnnotations()
.ValidateOnStart();
builder.Services.AddOptions<ChatHistoryProviderOptions>().Bind(builder.Configuration.GetSection(nameof(ChatHistoryProviderOptions)))
.ValidateDataAnnotations()
.ValidateOnStart();
// Requieres Encamina.Enmarcha.Data.Cosmos
builder.Services.AddCosmos(builder.Configuration);
builder.Services.AddCosmosChatHistoryProvider(cosmosContainer, tokenLengthFunction);
builder.Services.AddScoped(sp =>
{
var kernel = new KernelBuilder()
.WithAzureChatCompletionService("<YOUR DEPLOYMENT NAME>", "<YOUR AZURE ENDPOINT>", "<YOUR API KEY>")
//.WithOpenAIChatCompletionService("<YOUR MODEL ID>", "<YOUR API KEY>", "<YOUR API KEY>")
/// ...
.Build();
// ...
kernel.ImportChatWithHistoryPlugin(sp, openAIOptions, tokenLengthFunction);
return kernel;
});
Now you can inject the kernel via constructor, and the chat capabilities are already available.
public class MyClass
{
private readonly Kernel kernel;
public MyClass(Kernel kernel)
{
this.kernel = kernel;
}
public async Task TestChatAsync()
{
var contextVariables = new ContextVariables();
contextVariables.Set(PluginsInfo.ChatWithHistoryPlugin.Functions.Chat.Parameters.Ask, "What is the weather like in Madrid?");
contextVariables.Set(PluginsInfo.ChatWithHistoryPlugin.Functions.Chat.Parameters.UserId, "123456");
contextVariables.Set(PluginsInfo.ChatWithHistoryPlugin.Functions.Chat.Parameters.UserName, "John Doe");
contextVariables.Set(PluginsInfo.ChatWithHistoryPlugin.Functions.Chat.Parameters.Locale, "en");
var functionChat = kernel.Func(PluginsInfo.ChatWithHistoryPlugin.Name, PluginsInfo.ChatWithHistoryPlugin.Functions.Chat.Name);
var resultContext = await kernel.RunAsync(contextVariables, functionChat);
}
}
Advanced configurations
If you want to disable chat history, simply configure the HistoryMaxMessages of ChatHistoryProviderOptions with a value of 0.
You can also inherit from the ChatWithHistoryPlugin class and add the customizations you need.
public class MyCustomChatWithHistoryPlugin : ChatWithHistoryPlugin
{
public MyCustomChatWithHistoryPlugin(Kernel kernel, string chatModelName, Func<string, int> tokensLengthFunction, IChatHistoryProvider chatHistoryProvider, IOptionsMonitor<ChatWithHistoryPluginOptions> options)
: base(kernel, chatModelName, tokensLengthFunction, chatHistoryProvider, options)
{
}
protected override string SystemPrompt => "You are a Virtual Assistant who only talks about the weather.";
// There are more overridable methods/properties
}
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.Abstractions (>= 8.1.6-preview-05)
- Encamina.Enmarcha.AI.OpenAI.Azure (>= 8.1.6-preview-05)
- Encamina.Enmarcha.Core (>= 8.1.6-preview-05)
- Encamina.Enmarcha.Data.Abstractions (>= 8.1.6-preview-05)
- Encamina.Enmarcha.Data.Cosmos (>= 8.1.6-preview-05)
- Encamina.Enmarcha.Entities.Abstractions (>= 8.1.6-preview-05)
- Encamina.Enmarcha.SemanticKernel.Abstractions (>= 8.1.6-preview-05)
- Microsoft.Extensions.Options (>= 8.0.2)
- Microsoft.SemanticKernel.Abstractions (>= 1.7.1)
- Newtonsoft.Json (>= 13.0.3)
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 | 406 | 10/22/2024 |
8.2.0-preview-01-m01 | 97 | 9/17/2024 |
8.1.9-preview-03 | 55 | 11/19/2024 |
8.1.9-preview-02 | 67 | 10/22/2024 |
8.1.9-preview-01 | 292 | 10/4/2024 |
8.1.8 | 225 | 9/23/2024 |
8.1.8-preview-07 | 629 | 9/12/2024 |
8.1.8-preview-06 | 219 | 9/11/2024 |
8.1.8-preview-05 | 79 | 9/10/2024 |
8.1.8-preview-04 | 357 | 8/16/2024 |
8.1.8-preview-03 | 176 | 8/13/2024 |
8.1.8-preview-02 | 100 | 8/13/2024 |
8.1.8-preview-01 | 100 | 8/12/2024 |
8.1.7 | 98 | 8/7/2024 |
8.1.7-preview-09 | 153 | 7/3/2024 |
8.1.7-preview-08 | 95 | 7/2/2024 |
8.1.7-preview-07 | 93 | 6/10/2024 |
8.1.7-preview-06 | 94 | 6/10/2024 |
8.1.7-preview-05 | 105 | 6/6/2024 |
8.1.7-preview-04 | 95 | 6/6/2024 |
8.1.7-preview-03 | 88 | 5/24/2024 |
8.1.7-preview-02 | 94 | 5/10/2024 |
8.1.7-preview-01 | 103 | 5/8/2024 |
8.1.6 | 1,269 | 5/7/2024 |
8.1.6-preview-08 | 62 | 5/2/2024 |
8.1.6-preview-07 | 92 | 4/29/2024 |
8.1.6-preview-06 | 372 | 4/26/2024 |
8.1.6-preview-05 | 89 | 4/24/2024 |
8.1.6-preview-04 | 106 | 4/22/2024 |
8.1.6-preview-03 | 94 | 4/22/2024 |
8.1.6-preview-02 | 125 | 4/17/2024 |
8.1.6-preview-01 | 184 | 4/15/2024 |
8.1.5 | 118 | 4/15/2024 |
8.1.5-preview-15 | 115 | 4/10/2024 |
8.1.5-preview-14 | 136 | 3/20/2024 |
8.1.5-preview-13 | 83 | 3/18/2024 |
8.1.5-preview-12 | 100 | 3/13/2024 |
8.1.5-preview-11 | 87 | 3/13/2024 |
8.1.5-preview-10 | 113 | 3/13/2024 |
8.1.5-preview-09 | 97 | 3/12/2024 |
8.1.5-preview-08 | 93 | 3/12/2024 |
8.1.5-preview-07 | 106 | 3/8/2024 |
8.1.5-preview-06 | 208 | 3/8/2024 |
8.1.5-preview-05 | 95 | 3/7/2024 |
8.1.5-preview-04 | 101 | 3/7/2024 |
8.1.5-preview-03 | 78 | 3/7/2024 |
8.1.5-preview-02 | 136 | 2/28/2024 |
8.1.5-preview-01 | 114 | 2/19/2024 |
8.1.4 | 155 | 2/15/2024 |
8.1.3 | 124 | 2/13/2024 |
8.1.3-preview-07 | 70 | 2/13/2024 |
8.1.3-preview-06 | 95 | 2/12/2024 |
8.1.3-preview-05 | 105 | 2/9/2024 |
8.1.3-preview-04 | 91 | 2/8/2024 |
8.1.3-preview-03 | 87 | 2/7/2024 |
8.1.3-preview-02 | 92 | 2/2/2024 |
8.1.3-preview-01 | 87 | 2/2/2024 |
8.1.2 | 128 | 2/1/2024 |
8.1.2-preview-9 | 107 | 1/22/2024 |
8.1.2-preview-8 | 89 | 1/19/2024 |
8.1.2-preview-7 | 92 | 1/19/2024 |
8.1.2-preview-6 | 86 | 1/19/2024 |
8.1.2-preview-5 | 97 | 1/19/2024 |
8.1.2-preview-4 | 87 | 1/19/2024 |
8.1.2-preview-3 | 91 | 1/18/2024 |
8.1.2-preview-2 | 88 | 1/18/2024 |
8.1.2-preview-16 | 90 | 1/31/2024 |
8.1.2-preview-15 | 85 | 1/31/2024 |
8.1.2-preview-14 | 191 | 1/25/2024 |
8.1.2-preview-13 | 88 | 1/25/2024 |
8.1.2-preview-12 | 99 | 1/23/2024 |
8.1.2-preview-11 | 108 | 1/23/2024 |
8.1.2-preview-10 | 96 | 1/22/2024 |
8.1.2-preview-1 | 85 | 1/18/2024 |
8.1.1 | 141 | 1/18/2024 |
8.1.0 | 107 | 1/18/2024 |
8.0.3 | 160 | 12/29/2023 |
8.0.1 | 134 | 12/14/2023 |
8.0.0 | 160 | 12/7/2023 |
6.0.4.3 | 158 | 12/29/2023 |
6.0.4.2 | 151 | 12/20/2023 |
6.0.4.1 | 220 | 12/19/2023 |
6.0.4 | 176 | 12/4/2023 |
6.0.3.20 | 149 | 11/27/2023 |
6.0.3.19 | 151 | 11/22/2023 |