Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory extraction json format issue #1193

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 9 additions & 1 deletion webapi/Plugins/Chat/SemanticChatMemoryExtractor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -11,6 +12,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 +80,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
Loading