mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
85 lines
3.7 KiB
JavaScript
85 lines
3.7 KiB
JavaScript
|
|
let addImages = require('./addImages');
|
||
|
|
|
||
|
|
describe('addImages', () => {
|
||
|
|
let intermediateSteps;
|
||
|
|
let responseMessage;
|
||
|
|
let options;
|
||
|
|
|
||
|
|
beforeEach(() => {
|
||
|
|
intermediateSteps = [];
|
||
|
|
responseMessage = { text: '' };
|
||
|
|
options = { debug: false };
|
||
|
|
this.options = options;
|
||
|
|
addImages = addImages.bind(this);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should handle null or undefined parameters', () => {
|
||
|
|
addImages(null, responseMessage);
|
||
|
|
expect(responseMessage.text).toBe('');
|
||
|
|
|
||
|
|
addImages(intermediateSteps, null);
|
||
|
|
expect(responseMessage.text).toBe('');
|
||
|
|
|
||
|
|
addImages(null, null);
|
||
|
|
expect(responseMessage.text).toBe('');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should append correct image markdown if not present in responseMessage', () => {
|
||
|
|
intermediateSteps.push({ observation: '' });
|
||
|
|
addImages(intermediateSteps, responseMessage);
|
||
|
|
expect(responseMessage.text).toBe('\n');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should not append image markdown if already present in responseMessage', () => {
|
||
|
|
responseMessage.text = '';
|
||
|
|
intermediateSteps.push({ observation: '' });
|
||
|
|
addImages(intermediateSteps, responseMessage);
|
||
|
|
expect(responseMessage.text).toBe('');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should correct and append image markdown with erroneous URL', () => {
|
||
|
|
responseMessage.text = '';
|
||
|
|
intermediateSteps.push({ observation: '' });
|
||
|
|
addImages(intermediateSteps, responseMessage);
|
||
|
|
expect(responseMessage.text).toBe('');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should correct multiple erroneous URLs in responseMessage', () => {
|
||
|
|
responseMessage.text =
|
||
|
|
' ';
|
||
|
|
intermediateSteps.push({ observation: '' });
|
||
|
|
intermediateSteps.push({ observation: '' });
|
||
|
|
addImages(intermediateSteps, responseMessage);
|
||
|
|
expect(responseMessage.text).toBe(' ');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should not append non-image markdown observations', () => {
|
||
|
|
intermediateSteps.push({ observation: '[desc](/images/test.png)' });
|
||
|
|
addImages(intermediateSteps, responseMessage);
|
||
|
|
expect(responseMessage.text).toBe('');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should handle multiple observations', () => {
|
||
|
|
intermediateSteps.push({ observation: '' });
|
||
|
|
intermediateSteps.push({ observation: '' });
|
||
|
|
addImages(intermediateSteps, responseMessage);
|
||
|
|
expect(responseMessage.text).toBe('\n\n');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should not append if observation does not contain image markdown', () => {
|
||
|
|
intermediateSteps.push({ observation: 'This is a test observation without image markdown.' });
|
||
|
|
addImages(intermediateSteps, responseMessage);
|
||
|
|
expect(responseMessage.text).toBe('');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should append correctly from a real scenario', () => {
|
||
|
|
responseMessage.text =
|
||
|
|
'Here is the generated image based on your request. It depicts a surreal landscape filled with floating musical notes. The style is impressionistic, with vibrant sunset hues dominating the scene. At the center, there\'s a silhouette of a grand piano, adding a dreamy emotion to the overall image. This could serve as a unique and creative music album cover. Would you like to make any changes or generate another image?';
|
||
|
|
const originalText = responseMessage.text;
|
||
|
|
const imageMarkdown = '';
|
||
|
|
intermediateSteps.push({ observation: imageMarkdown });
|
||
|
|
addImages(intermediateSteps, responseMessage);
|
||
|
|
expect(responseMessage.text).toBe(`${originalText}\n${imageMarkdown}`);
|
||
|
|
});
|
||
|
|
});
|