fixed lint issues

This commit is contained in:
Ofer Mendelevitch 2023-11-21 09:14:12 -08:00
parent 1810b8718b
commit a4c3250a67
2 changed files with 30 additions and 33 deletions

View File

@ -7,39 +7,32 @@ import fetch from 'node-fetch'
// functionality based on https://github.com/vectara/vectara-answer // functionality based on https://github.com/vectara/vectara-answer
const reorderCitations = (unorderedSummary: string) => { const reorderCitations = (unorderedSummary: string) => {
const allCitations = unorderedSummary.match(/\[\d+\]/g) || []; const allCitations = unorderedSummary.match(/\[\d+\]/g) || []
const uniqueCitations = [...new Set(allCitations)]; const uniqueCitations = [...new Set(allCitations)]
const citationToReplacement: { [key: string]: string } = {}; const citationToReplacement: { [key: string]: string } = {}
uniqueCitations.forEach((citation, index) => { uniqueCitations.forEach((citation, index) => {
citationToReplacement[citation] = `[${index + 1}]`; citationToReplacement[citation] = `[${index + 1}]`
}); })
return unorderedSummary.replace( return unorderedSummary.replace(/\[\d+\]/g, (match) => citationToReplacement[match])
/\[\d+\]/g, }
(match) => citationToReplacement[match] const applyCitationOrder = (searchResults: any[], unorderedSummary: string) => {
); const orderedSearchResults: any[] = []
}; const allCitations = unorderedSummary.match(/\[\d+\]/g) || []
const applyCitationOrder = (
searchResults: any[], const addedIndices = new Set<number>()
unorderedSummary: string
) => {
const orderedSearchResults: any[] = [];
const allCitations = unorderedSummary.match(/\[\d+\]/g) || [];
const addedIndices = new Set<number>();
for (let i = 0; i < allCitations.length; i++) { for (let i = 0; i < allCitations.length; i++) {
const citation = allCitations[i]; const citation = allCitations[i]
const index = Number(citation.slice(1, citation.length - 1)) - 1; const index = Number(citation.slice(1, citation.length - 1)) - 1
if (addedIndices.has(index)) continue; if (addedIndices.has(index)) continue
orderedSearchResults.push(searchResults[index]); orderedSearchResults.push(searchResults[index])
addedIndices.add(index); addedIndices.add(index)
} }
return orderedSearchResults; return orderedSearchResults
}; }
class VectaraChain_Chains implements INode { class VectaraChain_Chains implements INode {
label: string label: string
@ -325,9 +318,9 @@ class VectaraChain_Chains implements INode {
rawSummarizedText = result.responseSet[0].summary[0]?.text rawSummarizedText = result.responseSet[0].summary[0]?.text
let summarizedText = reorderCitations(rawSummarizedText); let summarizedText = reorderCitations(rawSummarizedText)
let summaryResponses = applyCitationOrder(responses, rawSummarizedText); let summaryResponses = applyCitationOrder(responses, rawSummarizedText)
const sourceDocuments: Document[] = summaryResponses.map( const sourceDocuments: Document[] = summaryResponses.map(
(response: { text: string; metadata: Record<string, unknown>; score: number }) => (response: { text: string; metadata: Record<string, unknown>; score: number }) =>
new Document({ new Document({

View File

@ -47,6 +47,7 @@
"google-auth-library": "^9.0.0", "google-auth-library": "^9.0.0",
"graphql": "^16.6.0", "graphql": "^16.6.0",
"html-to-text": "^9.0.5", "html-to-text": "^9.0.5",
"husky": "^8.0.3",
"ioredis": "^5.3.2", "ioredis": "^5.3.2",
"langchain": "^0.0.165", "langchain": "^0.0.165",
"langfuse-langchain": "^1.0.31", "langfuse-langchain": "^1.0.31",
@ -82,6 +83,9 @@
"@types/object-hash": "^3.0.2", "@types/object-hash": "^3.0.2",
"@types/pg": "^8.10.2", "@types/pg": "^8.10.2",
"@types/ws": "^8.5.3", "@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", "gulp": "^4.0.2",
"typescript": "^4.8.4" "typescript": "^4.8.4"
} }