feat: Optimize langchain calls in batching mode (#15011)

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Benjamin Schroth
2025-05-02 17:09:31 +02:00
committed by GitHub
parent a4290dcb78
commit f3e29d25ed
12 changed files with 632 additions and 205 deletions

View File

@@ -7,6 +7,11 @@ import { makeZodSchemaFromAttributes } from '../helpers';
import { InformationExtractor } from '../InformationExtractor.node';
import type { AttributeDefinition } from '../types';
jest.mock('n8n-workflow', () => ({
...jest.requireActual('n8n-workflow'),
sleep: jest.fn(),
}));
const mockPersonAttributes: AttributeDefinition[] = [
{
name: 'name',
@@ -91,7 +96,12 @@ describe('InformationExtractor', () => {
attributes: {
attributes: mockPersonAttributes,
},
options: {},
options: {
batching: {
batchSize: 1,
delayBetweenBatches: 100,
},
},
schemaType: 'fromAttributes',
},
new FakeLLM({ response: formatFakeLlmResponse({ name: 'John', age: 30 }) }),
@@ -111,7 +121,12 @@ describe('InformationExtractor', () => {
attributes: {
attributes: mockPersonAttributes,
},
options: {},
options: {
batching: {
batchSize: 1,
delayBetweenBatches: 100,
},
},
schemaType: 'fromAttributes',
},
new FakeLLM({ response: formatFakeLlmResponse({ name: 'John' }) }),
@@ -132,7 +147,12 @@ describe('InformationExtractor', () => {
attributes: {
attributes: mockPersonAttributesRequired,
},
options: {},
options: {
batching: {
batchSize: 1,
delayBetweenBatches: 100,
},
},
schemaType: 'fromAttributes',
},
new FakeLLM({ response: formatFakeLlmResponse({ name: 'John' }) }),
@@ -154,7 +174,12 @@ describe('InformationExtractor', () => {
attributes: {
attributes: mockPersonAttributes,
},
options: {},
options: {
batching: {
batchSize: 1,
delayBetweenBatches: 100,
},
},
schemaType: 'fromAttributes',
},
new FakeLLM({ response: formatFakeLlmResponse({ name: 'John', age: '30' }) }),
@@ -175,7 +200,12 @@ describe('InformationExtractor', () => {
attributes: {
attributes: mockPersonAttributesRequired,
},
options: {},
options: {
batching: {
batchSize: 1,
delayBetweenBatches: 100,
},
},
schemaType: 'fromAttributes',
},
new FakeListChatModel({
@@ -200,7 +230,12 @@ describe('InformationExtractor', () => {
attributes: {
attributes: mockPersonAttributesRequired,
},
options: {},
options: {
batching: {
batchSize: 1,
delayBetweenBatches: 100,
},
},
schemaType: 'fromAttributes',
},
new FakeListChatModel({