Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ async function executeSimpleChain({
const chain = prompt.pipe(llm).pipe(outputParser).withConfig(getTracingConfig(context));

// Execute the chain
const response = await chain.invoke({
query,
signal: context.getExecutionCancelSignal(),
});
const response = await chain.invoke({ query }, { signal: context.getExecutionCancelSignal() });

// Ensure response is always returned as an array
return [response];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,10 @@ describe('chainExecutor', () => {
expect(tracing.getTracingConfig).toHaveBeenCalledWith(mockContext);
});

it('should execute a chain with a single output parser', async () => {
it('should execute a chain with a single output parser and pass signal as config', async () => {
const abortController = new AbortController();
mockContext.getExecutionCancelSignal.mockReturnValue(abortController.signal);

const fakeLLM = new FakeLLM({ response: 'Test response' });
const mockPromptTemplate = new PromptTemplate({
template: '{query}\n{formatInstructions}',
Expand Down Expand Up @@ -306,6 +309,11 @@ describe('chainExecutor', () => {
});

expect(result).toEqual([{ result: 'Test response' }]);
// Signal must be in the config (2nd arg), NOT bundled in the input (1st arg)
expect(mockChain.invoke).toHaveBeenCalledWith(
{ query: 'Hello' },
{ signal: abortController.signal },
);
});

it('should wrap non-array responses in an array', async () => {
Expand Down Expand Up @@ -345,8 +353,10 @@ describe('chainExecutor', () => {
expect(result).toEqual([{ result: 'Test response' }]);
});

it('should pass the execution cancel signal to the chain', async () => {
// For this test, we'll just verify that getExecutionCancelSignal is called
it('should pass the execution cancel signal as config, not as input', async () => {
const abortController = new AbortController();
mockContext.getExecutionCancelSignal.mockReturnValue(abortController.signal);

const fakeLLM = new FakeLLM({ response: 'Test response' });
const mockPromptTemplate = new PromptTemplate({
template: '{query}',
Expand Down Expand Up @@ -377,7 +387,11 @@ describe('chainExecutor', () => {
});

expect(mockContext.getExecutionCancelSignal).toHaveBeenCalled();
expect(mockChain.invoke).toHaveBeenCalled();
// Signal must be in the config (2nd arg), NOT bundled in the input (1st arg)
expect(mockChain.invoke).toHaveBeenCalledWith(
{ query: 'Hello' },
{ signal: abortController.signal },
);
});

it('should support chat models', async () => {
Expand Down
Loading