Skip to content

Commit

Permalink
core[patch]: Fix #5873 (LCEL issue when streaming from LLMs) (#5874)
Browse files Browse the repository at this point in the history
* Fix #5873 (LCEL issue when streaming from LLMs)

Fix #5873.

* Add test

---------

Co-authored-by: jacoblee93 <jacoblee93@gmail.com>
  • Loading branch information
welljsjs and jacoblee93 committed Jun 25, 2024
1 parent 16fed47 commit 4604a41
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion langchain-core/src/language_models/llms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export abstract class BaseLLM<
});
try {
for await (const chunk of this._streamResponseChunks(
input.toString(),
prompt.toString(),
callOptions,
runManagers?.[0]
)) {
Expand Down
16 changes: 15 additions & 1 deletion langchain-core/src/language_models/tests/llms.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable no-promise-executor-return */

import { test } from "@jest/globals";
import { FakeLLM } from "../../utils/testing/index.js";
import { FakeLLM, FakeStreamingLLM } from "../../utils/testing/index.js";
import { HumanMessagePromptTemplate } from "../../prompts/chat.js";

test("Test FakeLLM uses callbacks", async () => {
const model = new FakeLLM({});
Expand Down Expand Up @@ -40,3 +41,16 @@ test("Test FakeLLM uses callbacks with a cache", async () => {
expect(response).toEqual(response2);
expect(response2).toEqual(acc);
});

test("Test FakeStreamingLLM works when streaming through a prompt", async () => {
const prompt = HumanMessagePromptTemplate.fromTemplate("hello there {name}");
const model = new FakeStreamingLLM({});
const chain = prompt.pipe(model);
const stream = await chain.stream({ name: "test" });
const chunks = [];
for await (const chunk of stream) {
chunks.push(chunk);
}
expect(chunks.length).toBeGreaterThan(1);
expect(chunks.join("")).toEqual("Human: hello there test");
});

0 comments on commit 4604a41

Please sign in to comment.