diff --git a/server/parsers/visualization_card_parser.test.ts b/server/parsers/visualization_card_parser.test.ts index 63fd66fe..32aa0757 100644 --- a/server/parsers/visualization_card_parser.test.ts +++ b/server/parsers/visualization_card_parser.test.ts @@ -113,4 +113,37 @@ describe('VisualizationCardParser', () => { }, ]); }); + + it('filter duplicate visualization id in a single interaction', async () => { + expect( + await VisualizationCardParser.parserProvider({ + input: 'input', + response: 'response', + conversation_id: '', + interaction_id: 'interaction_id', + create_time: '', + additional_info: { + 'VisualizationTool.output': [ + 'row_number,Id,title\n' + + '1,id1,[Flights] Total Flights\n' + + '2,id2,[Flights] Total Flights\n', + 'row_number,Id,title\n' + '2,id2,[Flights] Controls\n', + ], + }, + }) + ).toEqual([ + { + content: 'id1', + contentType: 'visualization', + suggestedActions: [{ actionType: 'view_in_dashboards', message: 'View in Visualize' }], + type: 'output', + }, + { + content: 'id2', + contentType: 'visualization', + suggestedActions: [{ actionType: 'view_in_dashboards', message: 'View in Visualize' }], + type: 'output', + }, + ]); + }); }); diff --git a/server/parsers/visualization_card_parser.ts b/server/parsers/visualization_card_parser.ts index b6afb731..7b4c9898 100644 --- a/server/parsers/visualization_card_parser.ts +++ b/server/parsers/visualization_card_parser.ts @@ -26,7 +26,7 @@ export const VisualizationCardParser = { await Promise.all(visualizationOutputs.map((output) => extractIdsFromCsvString(output))) ).flatMap((id) => id); - const visOutputs: IMessage[] = visualizationIds + const visOutputs: IMessage[] = [...new Set(visualizationIds)] /** * Empty id will be filtered */