From f128d41de2d1c51c261e209fe099ac18d5e2dfd2 Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Thu, 24 Oct 2024 15:11:03 -0700 Subject: [PATCH 1/2] Fix memory extraction json format issue --- webapi/Controllers/ChatMemoryController.cs | 2 +- webapi/Plugins/Chat/SemanticChatMemoryExtractor.cs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/webapi/Controllers/ChatMemoryController.cs b/webapi/Controllers/ChatMemoryController.cs index cda7de4c7..adc57ae74 100644 --- a/webapi/Controllers/ChatMemoryController.cs +++ b/webapi/Controllers/ChatMemoryController.cs @@ -97,7 +97,7 @@ await memoryClient.SearchMemoryAsync( this._promptOptions.MemoryIndexName, "*", relevanceThreshold: 0, - resultCount: 1, + resultCount: -1, chatId, memoryContainerName); diff --git a/webapi/Plugins/Chat/SemanticChatMemoryExtractor.cs b/webapi/Plugins/Chat/SemanticChatMemoryExtractor.cs index 6c7f1d90f..8011d2568 100644 --- a/webapi/Plugins/Chat/SemanticChatMemoryExtractor.cs +++ b/webapi/Plugins/Chat/SemanticChatMemoryExtractor.cs @@ -1,7 +1,9 @@ // Copyright (c) Microsoft. All rights reserved. using System; +using System.Collections.Generic; using System.Globalization; +using System.Linq; using System.Threading; using System.Threading.Tasks; using CopilotChat.WebApi.Extensions; @@ -11,6 +13,7 @@ using Microsoft.Extensions.Logging; using Microsoft.KernelMemory; using Microsoft.SemanticKernel; +using Microsoft.SemanticKernel.Connectors.OpenAI; namespace CopilotChat.WebApi.Plugins.Chat; @@ -78,7 +81,13 @@ async Task ExtractCognitiveMemoryAsync(string memoryType, st options.ResponseTokenLimit - TokenUtils.TokenCount(memoryPrompt); - var memoryExtractionArguments = new KernelArguments(kernelArguments); +#pragma warning disable SKEXP0010 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. + var memoryExtractionArguments = new KernelArguments(kernelArguments, executionSettings: new Dictionary + { + { PromptExecutionSettings.DefaultServiceId, new OpenAIPromptExecutionSettings { ResponseFormat = "json_object" } } + }); +#pragma warning restore SKEXP0010 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. + memoryExtractionArguments["tokenLimit"] = remainingToken.ToString(new NumberFormatInfo()); memoryExtractionArguments["memoryName"] = memoryName; memoryExtractionArguments["format"] = options.MemoryFormat; From fb9cc244c3688772540bffd61f64564b69db80f9 Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Thu, 24 Oct 2024 15:16:29 -0700 Subject: [PATCH 2/2] Fix .Net format --- webapi/Plugins/Chat/SemanticChatMemoryExtractor.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/webapi/Plugins/Chat/SemanticChatMemoryExtractor.cs b/webapi/Plugins/Chat/SemanticChatMemoryExtractor.cs index 8011d2568..ecf0eb26e 100644 --- a/webapi/Plugins/Chat/SemanticChatMemoryExtractor.cs +++ b/webapi/Plugins/Chat/SemanticChatMemoryExtractor.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.Globalization; -using System.Linq; using System.Threading; using System.Threading.Tasks; using CopilotChat.WebApi.Extensions;