fix: passing right llm setting from SimpleChatEngine to ChatMemoryBuffer (#1798)

This commit is contained in:
Marcus Schiesser
2025-03-28 13:20:52 +02:00
committed by GitHub
parent fc1bedf438
commit eaf326ee90
3 changed files with 25 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@llamaindex/core": patch
---
Fix passing right llm setting from SimpleChatEngine to ChatMemoryBuffer
@@ -24,8 +24,12 @@ export class SimpleChatEngine implements BaseChatEngine {
}
constructor(init?: Partial<SimpleChatEngine>) {
this.memory = init?.memory ?? new ChatMemoryBuffer();
this.llm = init?.llm ?? Settings.llm;
this.memory =
init?.memory ??
new ChatMemoryBuffer({
llm: this.llm,
});
}
chat(params: NonStreamingChatEngineParams): Promise<EngineResponse>;
@@ -40,6 +44,7 @@ export class SimpleChatEngine implements BaseChatEngine {
const chatHistory = params.chatHistory
? new ChatMemoryBuffer({
llm: this.llm,
chatHistory:
params.chatHistory instanceof BaseMemory
? await params.chatHistory.getMessages()
@@ -0,0 +1,14 @@
import { SimpleChatEngine } from "@llamaindex/core/chat-engine";
import { ChatMemoryBuffer } from "@llamaindex/core/memory";
import { MockLLM } from "@llamaindex/core/utils";
import { describe, expect, test } from "vitest";
describe("SimpleChatEngine", () => {
test("constructor initializes with provided LLM", () => {
const llm = new MockLLM();
const engine = new SimpleChatEngine({ llm });
expect(engine.llm).toBe(llm);
expect(engine.memory).toBeInstanceOf(ChatMemoryBuffer);
expect((engine.memory as ChatMemoryBuffer).tokenLimit).toBe(768);
});
});