Skip to content

Commit

Permalink
Fix memory extraction json format issue
Browse files Browse the repository at this point in the history
  • Loading branch information
TaoChenOSU committed Oct 24, 2024
1 parent 5ce1686 commit f128d41
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion webapi/Controllers/ChatMemoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ await memoryClient.SearchMemoryAsync(
this._promptOptions.MemoryIndexName,
"*",
relevanceThreshold: 0,
resultCount: 1,
resultCount: -1,
chatId,
memoryContainerName);

Expand Down
11 changes: 10 additions & 1 deletion webapi/Plugins/Chat/SemanticChatMemoryExtractor.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

Check warning on line 6 in webapi/Plugins/Chat/SemanticChatMemoryExtractor.cs

View workflow job for this annotation

GitHub Actions / check-format

Using directive is unnecessary.
using System.Threading;
using System.Threading.Tasks;
using CopilotChat.WebApi.Extensions;
Expand All @@ -11,6 +13,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.KernelMemory;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;

namespace CopilotChat.WebApi.Plugins.Chat;

Expand Down Expand Up @@ -78,7 +81,13 @@ async Task<SemanticChatMemory> 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<string, PromptExecutionSettings>
{
{ 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;
Expand Down

0 comments on commit f128d41

Please sign in to comment.