Skip to content

Commit

Permalink
Upgrade CC to use SK 1.0 Beta 5 (microsoft#586)
Browse files Browse the repository at this point in the history
### Motivation and Context
In anticipation of SK 1.0, we need to make some changes to CC.

### Description

- Upgraded SK to 1.0 Beta 5
- Upgraded other NuGets to higher versions
- Changed references to Semantic Memory to be to Kernel Memory instead
- Switched from using BasicPromptTemplateEngine to
BasicPromptTemplateFactory
- Changed some "Copilot Chat" strings to "Chat Copilot" in the frontend


### Contribution Checklist
- [ ] The code builds clean without any errors or warnings
- [ ] The PR follows the [Contribution
Guidelines](https://github.com/microsoft/chat-copilot/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/chat-copilot/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄
  • Loading branch information
glahaye authored Nov 8, 2023
1 parent 10ed612 commit 609edcd
Show file tree
Hide file tree
Showing 27 changed files with 71 additions and 79 deletions.
6 changes: 3 additions & 3 deletions integration-tests/ChatCopilotIntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions memorypipeline/CopilotChatMemoryPipeline.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Microsoft.KernelMemory.Core" Version="0.7.231106.1-preview" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.0.0-beta4" />
<PackageReference Include="Microsoft.KernelMemory.Core" Version="0.8.231108.1-preview" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.0.0-beta5" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion memorypipeline/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Importing documents enables Copilot Chat to have up-to-date knowledge of specifi

### Memory pipeline in Chat Copilot

Chat copilot integrates [Semantic Memory](https://github.com/microsoft/semantic-memory) as the memory solution provider. The memory pipeline is designed to be run as an asynchronous service. If you are expecting to import big documents that can require minutes to process or planning to carry long conversations with the bot, then you can deploy the memory pipeline as a separate service along with the [chat copilot webapi](https://github.com/microsoft/chat-copilot/tree/main/webapi).
Chat copilot integrates [Kernel Memory](https://github.com/microsoft/kernel-memory) as the memory solution provider. The memory pipeline is designed to be run as an asynchronous service. If you are expecting to import big documents that can require minutes to process or planning to carry long conversations with the bot, then you can deploy the memory pipeline as a separate service along with the [chat copilot webapi](https://github.com/microsoft/chat-copilot/tree/main/webapi).

### Configuration

Expand Down
2 changes: 1 addition & 1 deletion memorypipeline/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"EmbeddingGeneratorType": "AzureOpenAIEmbedding"
},
//
// Configuration for the various services used by semantic memory and semantic kernel.
// Configuration for the various services used by kernel memory and semantic kernel.
// Section names correspond to type specified in SemanticMemory section. All supported
// sections are listed below for reference. Only referenced sections are required.
//
Expand Down
6 changes: 3 additions & 3 deletions plugins/web-searcher/WebSearcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.OpenApi" Version="1.5.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.13.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.18.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.19.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion shared/CopilotChatShared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.KernelMemory.Core" Version="0.7.231106.1-preview" />
<PackageReference Include="Microsoft.KernelMemory.Core" Version="0.8.231108.1-preview" />
<PackageReference Include="Tesseract" Version="5.2.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion shared/MemoryClientBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace CopilotChat.Shared;

/// <summary>
/// Dependency injection for semantic-memory using custom OCR configuration defined in appsettings.json
/// Dependency injection for kernel memory using custom OCR configuration defined in appsettings.json
/// </summary>
public static class MemoryClientBuilderExtensions
{
Expand Down
2 changes: 1 addition & 1 deletion shared/MemoryConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace CopilotChat.Shared;

/// <summary>
/// Configuration constants for semantic-memory.
/// Configuration constants for kernel memory.
/// </summary>
public static class MemoryConfiguration
{
Expand Down
2 changes: 1 addition & 1 deletion shared/Ocr/ConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace CopilotChat.Shared.Ocr;

/// <summary>
/// Dependency injection for semantic-memory using configuration defined in appsettings.json
/// Dependency injection for kernel memory using configuration defined in appsettings.json
/// </summary>
public static class ConfigurationExtensions
{
Expand Down
2 changes: 1 addition & 1 deletion tools/importdocument/ImportDocument.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0-preview.3.23174.8" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0-preview.3.23174.8" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.54.1" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.57.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>

Expand Down
7 changes: 3 additions & 4 deletions webapi/Controllers/ChatMemoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace CopilotChat.WebApi.Controllers;

/// <summary>
/// Controller for retrieving semantic memory data of chat sessions.
/// Controller for retrieving kernel memory data of chat sessions.
/// </summary>
[ApiController]
public class ChatMemoryController : ControllerBase
Expand Down Expand Up @@ -47,7 +47,7 @@ public ChatMemoryController(
}

/// <summary>
/// Gets the semantic memory for the chat session.
/// Gets the kernel memory for the chat session.
/// </summary>
/// <param name="semanticTextMemory">The semantic text memory instance.</param>
/// <param name="chatId">The chat id.</param>
Expand Down Expand Up @@ -81,7 +81,7 @@ public async Task<IActionResult> GetSemanticMemoriesAsync(
return this.BadRequest($"Chat session: {sanitizedChatId} does not exist.");
}

// Gather the requested semantic memory.
// Gather the requested kernel memory.
// Will use a dummy query since we don't care about relevance.
// minRelevanceScore is set to 0.0 to return all memories.
List<string> memories = new();
Expand All @@ -91,7 +91,6 @@ public async Task<IActionResult> GetSemanticMemoriesAsync(
var filter = new MemoryFilter();
filter.ByTag("chatid", chatId);
filter.ByTag("memory", memoryContainerName);
filter.MinRelevance = 0;

var searchResult =
await memoryClient.SearchMemoryAsync(
Expand Down
2 changes: 1 addition & 1 deletion webapi/Controllers/DocumentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace CopilotChat.WebApi.Controllers;
/// Controller for importing documents.
/// </summary>
/// <remarks>
/// This controller is responsible for contracts that are not possible to fulfill by semantic-memory components.
/// This controller is responsible for contracts that are not possible to fulfill by kernel memory components.
/// </remarks>
[ApiController]
public class DocumentController : ControllerBase
Expand Down
26 changes: 13 additions & 13 deletions webapi/CopilotChatWebApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.2.2" />
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.3.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.36.0" />
<PackageReference Include="Microsoft.Identity.Web" Version="2.15.3" />
<PackageReference Include="Microsoft.KernelMemory.Core" Version="0.7.231106.1-preview" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.0.0-beta4" />
<PackageReference Include="Microsoft.SemanticKernel.Abstractions" Version="1.0.0-beta4" />
<PackageReference Include="Microsoft.SemanticKernel.Connectors.AI.OpenAI" Version="1.0.0-beta4" />
<PackageReference Include="Microsoft.SemanticKernel.Connectors.Memory.AzureCognitiveSearch" Version="1.0.0-beta4" />
<PackageReference Include="Microsoft.SemanticKernel.Connectors.Memory.Qdrant" Version="1.0.0-beta4" />
<PackageReference Include="Microsoft.SemanticKernel.Functions.OpenAPI" Version="1.0.0-beta4" />
<PackageReference Include="Microsoft.SemanticKernel.Planners.Core" Version="1.0.0-beta4" />
<PackageReference Include="Microsoft.SemanticKernel.Plugins.Core" Version="1.0.0-beta4" />
<PackageReference Include="Microsoft.SemanticKernel.Plugins.MsGraph" Version="1.0.0-beta4" />
<PackageReference Include="Microsoft.SemanticKernel.Plugins.Web" Version="1.0.0-beta4" />
<PackageReference Include="Microsoft.SemanticKernel.TemplateEngine.Basic" Version="1.0.0-beta4" />
<PackageReference Include="Microsoft.KernelMemory.Core" Version="0.8.231108.1-preview" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.0.0-beta5" />
<PackageReference Include="Microsoft.SemanticKernel.Abstractions" Version="1.0.0-beta5" />
<PackageReference Include="Microsoft.SemanticKernel.Connectors.AI.OpenAI" Version="1.0.0-beta5" />
<PackageReference Include="Microsoft.SemanticKernel.Connectors.Memory.AzureCognitiveSearch" Version="1.0.0-beta5" />
<PackageReference Include="Microsoft.SemanticKernel.Connectors.Memory.Qdrant" Version="1.0.0-beta5" />
<PackageReference Include="Microsoft.SemanticKernel.Functions.OpenAPI" Version="1.0.0-beta5" />
<PackageReference Include="Microsoft.SemanticKernel.Planners.Core" Version="1.0.0-beta5" />
<PackageReference Include="Microsoft.SemanticKernel.Plugins.Core" Version="1.0.0-beta5" />
<PackageReference Include="Microsoft.SemanticKernel.Plugins.MsGraph" Version="1.0.0-beta5" />
<PackageReference Include="Microsoft.SemanticKernel.Plugins.Web" Version="1.0.0-beta5" />
<PackageReference Include="Microsoft.SemanticKernel.TemplateEngine.Basic" Version="1.0.0-beta5" />
<PackageReference Include="SharpToken" Version="1.2.12" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
Expand Down
7 changes: 2 additions & 5 deletions webapi/Extensions/ISemanticMemoryClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ public static async Task<SearchResult> SearchMemoryAsync(
string? memoryName = null,
CancellationToken cancellationToken = default)
{
var filter =
new MemoryFilter
{
MinRelevance = relevanceThreshold,
};
var filter = new MemoryFilter();

filter.ByTag(MemoryTags.TagChatId, chatId);

Expand All @@ -100,6 +96,7 @@ await memoryClient.SearchAsync(
indexName,
filter,
null,
0,
resultCount,
cancellationToken);

Expand Down
4 changes: 2 additions & 2 deletions webapi/Models/Storage/CitationSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace CopilotChat.WebApi.Models.Storage;

/// <summary>
/// Information about a citation source.
/// This is a replica of the <see cref="Citation"/> class in Semantic Memory.
/// Creating a replica here is to avoid taking a direct dependency on Semantic Memory in our data model.
/// This is a replica of the <see cref="Citation"/> class in Kernel Memory.
/// Creating a replica here is to avoid taking a direct dependency on Kernel Memory in our data model.
/// </summary>
public class CitationSource
{
Expand Down
2 changes: 1 addition & 1 deletion webapi/Models/Storage/MemoryTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace CopilotChat.WebApi.Models.Storage;

/// <summary>
/// Tag names for semantic memory.
/// Tag names for kernel memory.
/// </summary>
internal static class MemoryTags
{
Expand Down
4 changes: 2 additions & 2 deletions webapi/Options/PromptsOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public class PromptsOptions
internal double ExternalInformationContextWeight { get; } = 0.3;

/// <summary>
/// Upper bound of the relevancy score of a semantic memory to be included in the final prompt.
/// Upper bound of the relevancy score of a kernel memory to be included in the final prompt.
/// The actual relevancy score is determined by the memory balance.
/// </summary>
internal float SemanticMemoryRelevanceUpper { get; } = 0.9F;

/// <summary>
/// Lower bound of the relevancy score of a semantic memory to be included in the final prompt.
/// Lower bound of the relevancy score of a kernel memory to be included in the final prompt.
/// The actual relevancy score is determined by the memory balance.
/// </summary>
internal float SemanticMemoryRelevanceLower { get; } = 0.6F;
Expand Down
4 changes: 2 additions & 2 deletions webapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ The following material is under development and may not be complete or accurate.
- **Azure Form Recognizer** we have included the [Azure.AI.FormRecognizer](https://www.nuget.org/packages/Azure.AI.FormRecognizer) nuget package.
- You will need to obtain an [Azure Form Recognizer](https://azure.microsoft.com/en-us/services/form-recognizer/) resource and add the `SemanticMemory:Services:AzureFormRecognizer:Endpoint` and `SemanticMemory:Services:AzureFormRecognizer:Key` values to the `./appsettings.json` file.

## Running [Memory Service](https://github.com/microsoft/semantic-memory)
## Running [Memory Service](https://github.com/microsoft/kernel-memory)

The memory service handles the creation and querying of semantic memory, including cognitive memory and documents.
The memory service handles the creation and querying of kernel memory, including cognitive memory and documents.

### InProcess Processing (Default)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace CopilotChat.WebApi.Services.MemoryMigration;
public interface IChatMemoryMigrationService
{
/// <summary>
/// Migrates all non-document memory to the semantic-memory index.
/// Migrates all non-document memory to the kernel memory index.
/// Subsequent/redunant migration is non-destructive/no-impact to migrated index.
/// </summary>
Task MigrateAsync(CancellationToken cancellationToken = default);
Expand Down
2 changes: 1 addition & 1 deletion webapi/Services/SemanticKernelProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public SemanticKernelProvider(IServiceProvider serviceProvider, IConfiguration c
public IKernel GetPlannerKernel() => this._builderPlanner.Build();

/// <summary>
/// Produce semantic-kernel with semantic-memory.
/// Produce semantic-kernel with kernel memory.
/// </summary>
public ISemanticTextMemory GetMigrationMemory() => this._builderMemory.Build();

Expand Down
29 changes: 13 additions & 16 deletions webapi/Skills/ChatSkills/ChatSkill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using Microsoft.SemanticKernel.Diagnostics;
using Microsoft.SemanticKernel.Orchestration;
using Microsoft.SemanticKernel.Planning;
using Microsoft.SemanticKernel.TemplateEngine;
using Microsoft.SemanticKernel.TemplateEngine.Basic;
using ChatCompletionContextMessages = Microsoft.SemanticKernel.AI.ChatCompletion.ChatHistory;

Expand All @@ -46,7 +47,7 @@ public class ChatSkill
private readonly IKernel _kernel;

/// <summary>
/// Client for the semantic-memory service.
/// Client for the kernel memory service.
/// </summary>
private readonly IKernelMemory _memoryClient;

Expand Down Expand Up @@ -76,7 +77,7 @@ public class ChatSkill
private readonly PromptsOptions _promptOptions;

/// <summary>
/// A semantic memory retriever instance to query semantic memories.
/// A kernel memory retriever instance to query semantic memories.
/// </summary>
private readonly SemanticMemoryRetriever _semanticMemoryRetriever;

Expand Down Expand Up @@ -436,11 +437,9 @@ await this.SaveNewResponseAsync(

// Add bot message proposal as prompt context message
chatContext.Variables.Set("planFunctions", this._externalInformationSkill.FormattedFunctionsString(deserializedPlan.Plan));
var promptRenderer = new BasicPromptTemplateEngine();
var proposedPlanBotMessage = await promptRenderer.RenderAsync(
this._promptOptions.ProposedPlanBotMessage,
chatContext,
cancellationToken);
var promptTemplateFactory = new BasicPromptTemplateFactory();
var proposedPlanTemplate = promptTemplateFactory.Create(this._promptOptions.ProposedPlanBotMessage, new PromptTemplateConfig());
var proposedPlanBotMessage = await proposedPlanTemplate.RenderAsync(chatContext, cancellationToken);
promptTemplate.AddAssistantMessage(proposedPlanBotMessage);
chatHistoryString += "\n" + PromptUtils.FormatChatHistoryMessage(ChatMessage.AuthorRoles.Bot, proposedPlanBotMessage);

Expand All @@ -453,10 +452,8 @@ await this.SaveNewResponseAsync(
promptTemplate.AddSystemMessage(deserializedPlan.UserIntent);

// Render system supplement to help guide model in using data.
var promptSupplement = await promptRenderer.RenderAsync(
this._promptOptions.PlanResultsDescription,
chatContext,
cancellationToken);
var promptSupplementTemplate = promptTemplateFactory.Create(this._promptOptions.PlanResultsDescription, new PromptTemplateConfig());
var promptSupplement = await promptSupplementTemplate.RenderAsync(chatContext, cancellationToken);

// Calculate remaining token budget and execute plan
await this.UpdateBotResponseStatusOnClientAsync(chatId, "Executing plan", cancellationToken);
Expand Down Expand Up @@ -627,11 +624,11 @@ private async Task<string> RenderSystemInstructions(string chatId, SKContext con
{
// Render system instruction components
await this.UpdateBotResponseStatusOnClientAsync(chatId, "Initializing prompt", cancellationToken);
var promptRenderer = new BasicPromptTemplateEngine();
return await promptRenderer.RenderAsync(
this._promptOptions.SystemPersona,
context,
cancellationToken);

var promptTemplateFactory = new BasicPromptTemplateFactory();
var template = promptTemplateFactory.Create(this._promptOptions.SystemPersona, new PromptTemplateConfig());

return await template.RenderAsync(context, cancellationToken);
}

/// <summary>
Expand Down
9 changes: 4 additions & 5 deletions webapi/Skills/ChatSkills/ExternalInformationSkill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Microsoft.SemanticKernel.Orchestration;
using Microsoft.SemanticKernel.Planners;
using Microsoft.SemanticKernel.Planning;
using Microsoft.SemanticKernel.TemplateEngine;
using Microsoft.SemanticKernel.TemplateEngine.Basic;

namespace CopilotChat.WebApi.Skills.ChatSkills;
Expand Down Expand Up @@ -252,11 +253,9 @@ private async Task<string> RunStepwisePlannerAsync(string goal, SKContext contex
}

// Render the supplement to guide the model in using the result.
var promptRenderer = new BasicPromptTemplateEngine();
var resultSupplement = await promptRenderer.RenderAsync(
this._promptOptions.StepwisePlannerSupplement,
plannerContext,
cancellationToken);
var promptTemplateFactory = new BasicPromptTemplateFactory();
var promptTemplate = promptTemplateFactory.Create(this._promptOptions.StepwisePlannerSupplement, new PromptTemplateConfig());
var resultSupplement = await promptTemplate.RenderAsync(plannerContext, cancellationToken);

return $"{resultSupplement}\n\nResult:\n\"{plannerResult}\"";
}
Expand Down
Loading

0 comments on commit 609edcd

Please sign in to comment.