fix(Basic LLM Chain Node): Prevent stringifying of structured output on previous versions (#14200)

This commit is contained in:
oleg
2025-03-27 11:48:17 +01:00
committed by GitHub
parent a4a34a2745
commit bbd6e8ee41
6 changed files with 375 additions and 19 deletions

View File

@@ -3,14 +3,14 @@ import { formatResponse } from '../methods/responseFormatter';
describe('responseFormatter', () => {
describe('formatResponse', () => {
it('should format string responses', () => {
const result = formatResponse('Test response', 1.6);
const result = formatResponse('Test response', true);
expect(result).toEqual({
text: 'Test response',
});
});
it('should trim string responses', () => {
const result = formatResponse(' Test response with whitespace ', 1.6);
const result = formatResponse(' Test response with whitespace ', true);
expect(result).toEqual({
text: 'Test response with whitespace',
});
@@ -18,24 +18,70 @@ describe('responseFormatter', () => {
it('should handle array responses', () => {
const testArray = [{ item: 1 }, { item: 2 }];
const result = formatResponse(testArray, 1.6);
const result = formatResponse(testArray, true);
expect(result).toEqual({ data: testArray });
});
it('should handle object responses', () => {
it('should handle object responses when unwrapping is enabled', () => {
const testObject = { key: 'value', nested: { key: 'value' } };
const result = formatResponse(testObject, 1.6);
const result = formatResponse(testObject, true);
expect(result).toEqual(testObject);
});
it('should stringify object responses when unwrapping is disabled', () => {
const testObject = { key: 'value', nested: { key: 'value' } };
const result = formatResponse(testObject, false);
expect(result).toEqual({
text: JSON.stringify(testObject),
});
});
it('should handle primitive non-string responses', () => {
const testNumber = 42;
const result = formatResponse(testNumber, 1.6);
const result = formatResponse(testNumber, true);
expect(result).toEqual({
response: {
text: 42,
},
});
});
it('should handle complex object structures when unwrapping is enabled', () => {
const complexObject = {
person: {
name: 'John',
age: 30,
address: {
street: '123 Main St',
city: 'Anytown',
},
},
items: [1, 2, 3],
active: true,
};
const result = formatResponse(complexObject, true);
expect(result).toEqual(complexObject);
});
it('should stringify complex object structures when unwrapping is disabled', () => {
const complexObject = {
person: {
name: 'John',
age: 30,
address: {
street: '123 Main St',
city: 'Anytown',
},
},
items: [1, 2, 3],
active: true,
};
const result = formatResponse(complexObject, false);
expect(result).toEqual({
text: JSON.stringify(complexObject),
});
});
});
});