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

core[patch]: Fix #5873 (LCEL issue when streaming from LLMs) #5874

Merged
merged 3 commits into from
Jun 25, 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 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");
});
Loading