From 80316264a1060292825707cc0c6ec9b3916d80be Mon Sep 17 00:00:00 2001 From: Ashish Reddy Podduturi Date: Thu, 17 Apr 2025 23:42:23 -0700 Subject: [PATCH] fix for history overload issue --- packages/core/src/codewhispererChat/constants.ts | 2 ++ .../core/src/codewhispererChat/controllers/chat/controller.ts | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/core/src/codewhispererChat/constants.ts b/packages/core/src/codewhispererChat/constants.ts index 093b7e1a1d2..f1b1c5f235c 100644 --- a/packages/core/src/codewhispererChat/constants.ts +++ b/packages/core/src/codewhispererChat/constants.ts @@ -56,6 +56,8 @@ export const defaultContextLengths: ContextLengths = { export const defaultStreamingResponseTimeoutInMs = 180_000 +export const maxHistoryMessages = 100 + export const ignoredDirectoriesAndFiles = [ // Dependency directories 'node_modules', diff --git a/packages/core/src/codewhispererChat/controllers/chat/controller.ts b/packages/core/src/codewhispererChat/controllers/chat/controller.ts index 573a26fc5e2..92756f60cd1 100644 --- a/packages/core/src/codewhispererChat/controllers/chat/controller.ts +++ b/packages/core/src/codewhispererChat/controllers/chat/controller.ts @@ -92,6 +92,7 @@ import { additionalContentInnerContextLimit, workspaceChunkMaxSize, defaultContextLengths, + maxHistoryMessages, } from '../../constants' import { ChatSession } from '../../clients/chat/v0/chat' import { amazonQTabSuffix } from '../../../shared/constants' @@ -1601,7 +1602,7 @@ export class ChatController { // Do not include chatHistory for requests going to Mynah request.conversationState.history = request.conversationState.currentMessage?.userInputMessage?.userIntent ? [] - : this.chatHistoryDb.getMessages(tabID).map((chat) => messageToChatMessage(chat)) + : this.chatHistoryDb.getMessages(tabID, maxHistoryMessages).map((chat) => messageToChatMessage(chat)) request.conversationState.conversationId = session.sessionIdentifier triggerPayload.documentReferences = this.mergeRelevantTextDocuments(triggerPayload.relevantTextDocuments)