From a4c3250a67ea7a2de10b289b4bc842cd19e194f2 Mon Sep 17 00:00:00 2001 From: Ofer Mendelevitch Date: Tue, 21 Nov 2023 09:14:12 -0800 Subject: [PATCH] fixed lint issues --- .../nodes/chains/VectaraChain/VectaraChain.ts | 59 ++++++++----------- packages/components/package.json | 4 ++ 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/packages/components/nodes/chains/VectaraChain/VectaraChain.ts b/packages/components/nodes/chains/VectaraChain/VectaraChain.ts index 2f7d09a2b..3799d062f 100644 --- a/packages/components/nodes/chains/VectaraChain/VectaraChain.ts +++ b/packages/components/nodes/chains/VectaraChain/VectaraChain.ts @@ -7,39 +7,32 @@ import fetch from 'node-fetch' // functionality based on https://github.com/vectara/vectara-answer const reorderCitations = (unorderedSummary: string) => { - const allCitations = unorderedSummary.match(/\[\d+\]/g) || []; - - const uniqueCitations = [...new Set(allCitations)]; - const citationToReplacement: { [key: string]: string } = {}; + const allCitations = unorderedSummary.match(/\[\d+\]/g) || [] + + const uniqueCitations = [...new Set(allCitations)] + const citationToReplacement: { [key: string]: string } = {} uniqueCitations.forEach((citation, index) => { - citationToReplacement[citation] = `[${index + 1}]`; - }); - - return unorderedSummary.replace( - /\[\d+\]/g, - (match) => citationToReplacement[match] - ); -}; -const applyCitationOrder = ( - searchResults: any[], - unorderedSummary: string - ) => { - const orderedSearchResults: any[] = []; - const allCitations = unorderedSummary.match(/\[\d+\]/g) || []; - - const addedIndices = new Set(); + citationToReplacement[citation] = `[${index + 1}]` + }) + + return unorderedSummary.replace(/\[\d+\]/g, (match) => citationToReplacement[match]) +} +const applyCitationOrder = (searchResults: any[], unorderedSummary: string) => { + const orderedSearchResults: any[] = [] + const allCitations = unorderedSummary.match(/\[\d+\]/g) || [] + + const addedIndices = new Set() for (let i = 0; i < allCitations.length; i++) { - const citation = allCitations[i]; - const index = Number(citation.slice(1, citation.length - 1)) - 1; - - if (addedIndices.has(index)) continue; - orderedSearchResults.push(searchResults[index]); - addedIndices.add(index); + const citation = allCitations[i] + const index = Number(citation.slice(1, citation.length - 1)) - 1 + + if (addedIndices.has(index)) continue + orderedSearchResults.push(searchResults[index]) + addedIndices.add(index) } - - return orderedSearchResults; -}; - + + return orderedSearchResults +} class VectaraChain_Chains implements INode { label: string @@ -325,9 +318,9 @@ class VectaraChain_Chains implements INode { rawSummarizedText = result.responseSet[0].summary[0]?.text - let summarizedText = reorderCitations(rawSummarizedText); - let summaryResponses = applyCitationOrder(responses, rawSummarizedText); - + let summarizedText = reorderCitations(rawSummarizedText) + let summaryResponses = applyCitationOrder(responses, rawSummarizedText) + const sourceDocuments: Document[] = summaryResponses.map( (response: { text: string; metadata: Record; score: number }) => new Document({ diff --git a/packages/components/package.json b/packages/components/package.json index c7a29a9ff..1d4cea573 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -47,6 +47,7 @@ "google-auth-library": "^9.0.0", "graphql": "^16.6.0", "html-to-text": "^9.0.5", + "husky": "^8.0.3", "ioredis": "^5.3.2", "langchain": "^0.0.165", "langfuse-langchain": "^1.0.31", @@ -82,6 +83,9 @@ "@types/object-hash": "^3.0.2", "@types/pg": "^8.10.2", "@types/ws": "^8.5.3", + "eslint-plugin-markdown": "^3.0.1", + "eslint-plugin-react": "^7.33.2", + "eslint-plugin-react-hooks": "^4.6.0", "gulp": "^4.0.2", "typescript": "^4.8.4" }