diff --git a/packages/core/src/Node.ts b/packages/core/src/Node.ts index 538d4a020f99097de364ce3ac2547a53e0baf55f..99ae46af656cbc4a3abbab635a09b1477c86f192 100644 --- a/packages/core/src/Node.ts +++ b/packages/core/src/Node.ts @@ -353,10 +353,10 @@ export function splitNodesByType(nodes: BaseNode[]): { imageNodes: ImageNode[]; textNodes: TextNode[]; } { - let imageNodes: ImageNode[] = []; - let textNodes: TextNode[] = []; + const imageNodes: ImageNode[] = []; + const textNodes: TextNode[] = []; - for (let node of nodes) { + for (const node of nodes) { if (node instanceof ImageNode) { imageNodes.push(node); } else if (node instanceof TextNode) { diff --git a/packages/core/src/TextSplitter.ts b/packages/core/src/TextSplitter.ts index 6f5ecf9e8b07a758ab6eaf4267d8269f934bfc26..94c7816762ce8f44afb57854d9eec6b3d3206a76 100644 --- a/packages/core/src/TextSplitter.ts +++ b/packages/core/src/TextSplitter.ts @@ -130,7 +130,7 @@ export class SentenceSplitter { getParagraphSplits(text: string, effectiveChunkSize?: number): string[] { // get paragraph splits - let paragraphSplits: string[] = text.split(this.paragraphSeparator); + const paragraphSplits: string[] = text.split(this.paragraphSeparator); let idx = 0; if (effectiveChunkSize == undefined) { return paragraphSplits; @@ -155,9 +155,9 @@ export class SentenceSplitter { } getSentenceSplits(text: string, effectiveChunkSize?: number): string[] { - let paragraphSplits = this.getParagraphSplits(text, effectiveChunkSize); + const paragraphSplits = this.getParagraphSplits(text, effectiveChunkSize); // Next we split the text using the chunk tokenizer fn/ - let splits = []; + const splits = []; for (const parText of paragraphSplits) { const sentenceSplits = this.chunkingTokenizerFn(parText); @@ -194,9 +194,9 @@ export class SentenceSplitter { })); } - let newSplits: SplitRep[] = []; + const newSplits: SplitRep[] = []; for (const split of sentenceSplits) { - let splitTokens = this.tokenizer(split); + const splitTokens = this.tokenizer(split); const splitLen = splitTokens.length; if (splitLen <= effectiveChunkSize) { newSplits.push({ text: split, numTokens: splitLen }); @@ -219,7 +219,7 @@ export class SentenceSplitter { // go through sentence splits, combine to chunks that are within the chunk size // docs represents final list of text chunks - let docs: TextSplit[] = []; + const docs: TextSplit[] = []; // curChunkSentences represents the current list of sentence splits (that) // will be merged into a chunk let curChunkSentences: SplitRep[] = []; @@ -287,18 +287,18 @@ export class SentenceSplitter { return []; } - let effectiveChunkSize = this.getEffectiveChunkSize(extraInfoStr); - let sentenceSplits = this.getSentenceSplits(text, effectiveChunkSize); + const effectiveChunkSize = this.getEffectiveChunkSize(extraInfoStr); + const sentenceSplits = this.getSentenceSplits(text, effectiveChunkSize); // Check if any sentences exceed the chunk size. If they don't, // force split by tokenizer - let newSentenceSplits = this.processSentenceSplits( + const newSentenceSplits = this.processSentenceSplits( sentenceSplits, effectiveChunkSize, ); // combine sentence splits into chunks of text that can then be returned - let combinedTextSplits = this.combineTextSplits( + const combinedTextSplits = this.combineTextSplits( newSentenceSplits, effectiveChunkSize, ); diff --git a/packages/core/src/embeddings/utils.ts b/packages/core/src/embeddings/utils.ts index 803701a7b5a58093b42e0d1cb6d9cdaa611dd5ef..ce1848e8716d59cc17489dd4fd927f6a31bc3d87 100644 --- a/packages/core/src/embeddings/utils.ts +++ b/packages/core/src/embeddings/utils.ts @@ -46,7 +46,7 @@ export function similarity( switch (mode) { case SimilarityType.EUCLIDEAN: { - let difference = embedding1.map((x, i) => x - embedding2[i]); + const difference = embedding1.map((x, i) => x - embedding2[i]); return -norm(difference); } case SimilarityType.DOT_PRODUCT: { @@ -94,7 +94,7 @@ export function getTopKEmbeddings( ); } - let similarities: { similarity: number; id: number }[] = []; + const similarities: { similarity: number; id: number }[] = []; for (let i = 0; i < embeddings.length; i++) { const sim = similarity(queryEmbedding, embeddings[i]); @@ -105,8 +105,8 @@ export function getTopKEmbeddings( similarities.sort((a, b) => b.similarity - a.similarity); // Reverse sort - let resultSimilarities: number[] = []; - let resultIds: any[] = []; + const resultSimilarities: number[] = []; + const resultIds: any[] = []; for (let i = 0; i < similarityTopK; i++) { if (i >= similarities.length) { @@ -142,21 +142,21 @@ export function getTopKMMREmbeddings( _similarityCutoff: number | null = null, mmrThreshold: number | null = null, ): [number[], any[]] { - let threshold = mmrThreshold || 0.5; + const threshold = mmrThreshold || 0.5; similarityFn = similarityFn || similarity; if (embeddingIds === null || embeddingIds.length === 0) { embeddingIds = Array.from({ length: embeddings.length }, (_, i) => i); } - let fullEmbedMap = new Map(embeddingIds.map((value, i) => [value, i])); - let embedMap = new Map(fullEmbedMap); - let embedSimilarity: Map<any, number> = new Map(); + const fullEmbedMap = new Map(embeddingIds.map((value, i) => [value, i])); + const embedMap = new Map(fullEmbedMap); + const embedSimilarity: Map<any, number> = new Map(); let score: number = Number.NEGATIVE_INFINITY; let highScoreId: any | null = null; for (let i = 0; i < embeddings.length; i++) { - let emb = embeddings[i]; - let similarity = similarityFn(queryEmbedding, emb); + const emb = embeddings[i]; + const similarity = similarityFn(queryEmbedding, emb); embedSimilarity.set(embeddingIds[i], similarity); if (similarity * threshold > score) { highScoreId = embeddingIds[i]; @@ -164,18 +164,18 @@ export function getTopKMMREmbeddings( } } - let results: [number, any][] = []; + const results: [number, any][] = []; - let embeddingLength = embeddings.length; - let similarityTopKCount = similarityTopK || embeddingLength; + const embeddingLength = embeddings.length; + const similarityTopKCount = similarityTopK || embeddingLength; while (results.length < Math.min(similarityTopKCount, embeddingLength)) { results.push([score, highScoreId]); embedMap.delete(highScoreId!); - let recentEmbeddingId = highScoreId; + const recentEmbeddingId = highScoreId; score = Number.NEGATIVE_INFINITY; - for (let embedId of Array.from(embedMap.keys())) { - let overlapWithRecent = similarityFn( + for (const embedId of Array.from(embedMap.keys())) { + const overlapWithRecent = similarityFn( embeddings[embedMap.get(embedId)!], embeddings[fullEmbedMap.get(recentEmbeddingId!)!], ); @@ -192,8 +192,8 @@ export function getTopKMMREmbeddings( } } - let resultSimilarities = results.map(([s, _]) => s); - let resultIds = results.map(([_, n]) => n); + const resultSimilarities = results.map(([s, _]) => s); + const resultIds = results.map(([_, n]) => n); return [resultSimilarities, resultIds]; } diff --git a/packages/core/src/extractors/MetadataExtractors.ts b/packages/core/src/extractors/MetadataExtractors.ts index 73173bd5ef39c2464a3c9cfdfc4491215c5d28cc..f41e3f8605bc16d416b47c0b9ae7162cc8d472be 100644 --- a/packages/core/src/extractors/MetadataExtractors.ts +++ b/packages/core/src/extractors/MetadataExtractors.ts @@ -172,7 +172,7 @@ export class TitleExtractor extends BaseExtractor { if (nodesToExtractTitle.length === 0) return []; - let titlesCandidates: string[] = []; + const titlesCandidates: string[] = []; let title: string = ""; for (let i = 0; i < nodesToExtractTitle.length; i++) { @@ -411,7 +411,7 @@ export class SummaryExtractor extends BaseExtractor { nodes.map((node) => this.generateNodeSummary(node)), ); - let metadataList: any[] = nodes.map(() => ({})); + const metadataList: any[] = nodes.map(() => ({})); for (let i = 0; i < nodes.length; i++) { if (i > 0 && this._prevSummary && nodeSummaries[i - 1]) { diff --git a/packages/core/src/extractors/types.ts b/packages/core/src/extractors/types.ts index 5e31cab050216042dbcc2eac396cf3ac8c645e49..adac96be438c411151c731c040c8add367bb4b0a 100644 --- a/packages/core/src/extractors/types.ts +++ b/packages/core/src/extractors/types.ts @@ -43,16 +43,16 @@ export abstract class BaseExtractor implements TransformComponent { newNodes = nodes.slice(); } - let curMetadataList = await this.extract(newNodes); + const curMetadataList = await this.extract(newNodes); - for (let idx in newNodes) { + for (const idx in newNodes) { newNodes[idx].metadata = { ...newNodes[idx].metadata, ...curMetadataList[idx], }; } - for (let idx in newNodes) { + for (const idx in newNodes) { if (excludedEmbedMetadataKeys) { newNodes[idx].excludedEmbedMetadataKeys.concat( excludedEmbedMetadataKeys, diff --git a/packages/core/src/indices/keyword/KeywordTableIndex.ts b/packages/core/src/indices/keyword/KeywordTableIndex.ts index 6964ebb2deb4f518d7f4ac8e8331506a5317ebe9..474805d7baee5f82e4df635874e6be87473b565a 100644 --- a/packages/core/src/indices/keyword/KeywordTableIndex.ts +++ b/packages/core/src/indices/keyword/KeywordTableIndex.ts @@ -62,7 +62,7 @@ export class KeywordTableIndex extends BaseIndex<KeywordTable> { const { docStore, indexStore } = storageContext; // Setup IndexStruct from storage - let indexStructs = (await indexStore.getIndexStructs()) as KeywordTable[]; + const indexStructs = (await indexStore.getIndexStructs()) as KeywordTable[]; let indexStruct: KeywordTable | null; if (options.indexStruct && indexStructs.length > 0) { @@ -216,7 +216,7 @@ export class KeywordTableIndex extends BaseIndex<KeywordTable> { } async insertNodes(nodes: BaseNode[]) { - for (let node of nodes) { + for (const node of nodes) { const keywords = await KeywordTableIndex.extractKeywords( node.getContent(MetadataMode.LLM), this.serviceContext, diff --git a/packages/core/src/indices/keyword/KeywordTableIndexRetriever.ts b/packages/core/src/indices/keyword/KeywordTableIndexRetriever.ts index e7bf59416e61e0b12c4437c5e7f5680e48673ec7..b1a27f69916c3e7629459a5d82ac63863c4ea920 100644 --- a/packages/core/src/indices/keyword/KeywordTableIndexRetriever.ts +++ b/packages/core/src/indices/keyword/KeywordTableIndexRetriever.ts @@ -63,8 +63,8 @@ abstract class BaseKeywordTableRetriever implements BaseRetriever { this.indexStruct.table.has(keyword), ); - for (let keyword of filteredKeywords) { - for (let nodeId of this.indexStruct.table.get(keyword) || []) { + for (const keyword of filteredKeywords) { + for (const nodeId of this.indexStruct.table.get(keyword) || []) { chunkIndicesCount[nodeId] = (chunkIndicesCount[nodeId] ?? 0) + 1; } } diff --git a/packages/core/src/indices/keyword/utils.ts b/packages/core/src/indices/keyword/utils.ts index 6a3d1c73676dd60feb329d22722357150508da94..b7e766f042bcaaa826753bb3148b4dce29f131d2 100644 --- a/packages/core/src/indices/keyword/utils.ts +++ b/packages/core/src/indices/keyword/utils.ts @@ -6,11 +6,11 @@ export function expandTokensWithSubtokens(tokens: Set<string>): Set<string> { const results: Set<string> = new Set(); const regex: RegExp = /\w+/g; - for (let token of tokens) { + for (const token of tokens) { results.add(token); const subTokens: RegExpMatchArray | null = token.match(regex); if (subTokens && subTokens.length > 1) { - for (let w of subTokens) { + for (const w of subTokens) { results.add(w); } } @@ -31,7 +31,7 @@ export function extractKeywordsGivenResponse( } const keywords: string[] = response.split(","); - for (let k of keywords) { + for (const k of keywords) { let rk: string = k; if (lowercase) { rk = rk.toLowerCase(); @@ -47,13 +47,13 @@ export function simpleExtractKeywords( maxKeywords?: number, ): Set<string> { const regex: RegExp = /\w+/g; - let tokens: string[] = [...textChunk.matchAll(regex)].map((token) => + const tokens: string[] = [...textChunk.matchAll(regex)].map((token) => token[0].toLowerCase().trim(), ); // Creating a frequency map const valueCounts: { [key: string]: number } = {}; - for (let token of tokens) { + for (const token of tokens) { valueCounts[token] = (valueCounts[token] || 0) + 1; } diff --git a/packages/core/src/indices/summary/SummaryIndex.ts b/packages/core/src/indices/summary/SummaryIndex.ts index adcff31dee32a9d0448a50f6f9dc6637707dfdbe..7223f33edb5e2dd43b5e785a4f4161f7b71ee2fa 100644 --- a/packages/core/src/indices/summary/SummaryIndex.ts +++ b/packages/core/src/indices/summary/SummaryIndex.ts @@ -60,7 +60,7 @@ export class SummaryIndex extends BaseIndex<IndexList> { const { docStore, indexStore } = storageContext; // Setup IndexStruct from storage - let indexStructs = (await indexStore.getIndexStructs()) as IndexList[]; + const indexStructs = (await indexStore.getIndexStructs()) as IndexList[]; let indexStruct: IndexList | null; if (options.indexStruct && indexStructs.length > 0) { @@ -169,7 +169,7 @@ export class SummaryIndex extends BaseIndex<IndexList> { } if (!responseSynthesizer) { - let responseBuilder = new CompactAndRefine(this.serviceContext); + const responseBuilder = new CompactAndRefine(this.serviceContext); responseSynthesizer = new ResponseSynthesizer({ serviceContext: this.serviceContext, responseBuilder, diff --git a/packages/core/src/indices/summary/utils.ts b/packages/core/src/indices/summary/utils.ts index 61fa1589792fb544b2155b67a385ac8812bacd03..af008c42197ced3a2e238d9aa1907073a1afccc7 100644 --- a/packages/core/src/indices/summary/utils.ts +++ b/packages/core/src/indices/summary/utils.ts @@ -32,7 +32,7 @@ export const defaultParseChoiceSelectAnswerFn: ChoiceSelectParserFunction = ( const lineTokens: string[][] = answer .split("\n") .map((line: string) => { - let lineTokens = line.split(","); + const lineTokens = line.split(","); if (lineTokens.length !== 2) { if (raiseErr) { throw new Error( @@ -50,8 +50,8 @@ export const defaultParseChoiceSelectAnswerFn: ChoiceSelectParserFunction = ( return lineTokens.reduce( (parseResult: ChoiceSelectParseResult, lineToken: string[]) => { try { - let docNum = parseInt(lineToken[0].split(":")[1].trim()); - let answerRelevance = parseFloat(lineToken[1].split(":")[1].trim()); + const docNum = parseInt(lineToken[0].split(":")[1].trim()); + const answerRelevance = parseFloat(lineToken[1].split(":")[1].trim()); if (docNum < 1 || docNum > numChoices) { if (raiseErr) { throw new Error( diff --git a/packages/core/src/indices/vectorStore/VectorIndexRetriever.ts b/packages/core/src/indices/vectorStore/VectorIndexRetriever.ts index 04e644809a7aa6dbe63880e5aada3fc302607d9b..5a8e3614fd428907d511ace1d22685c0abf21617 100644 --- a/packages/core/src/indices/vectorStore/VectorIndexRetriever.ts +++ b/packages/core/src/indices/vectorStore/VectorIndexRetriever.ts @@ -120,7 +120,7 @@ export class VectorIndexRetriever implements BaseRetriever { } protected buildNodeListFromQueryResult(result: VectorStoreQueryResult) { - let nodesWithScores: NodeWithScore[] = []; + const nodesWithScores: NodeWithScore[] = []; for (let i = 0; i < result.ids.length; i++) { const nodeFromResult = result.nodes?.[i]; if (!this.index.indexStruct.nodesDict[result.ids[i]] && nodeFromResult) { diff --git a/packages/core/src/indices/vectorStore/VectorStoreIndex.ts b/packages/core/src/indices/vectorStore/VectorStoreIndex.ts index 137d1073a8f0d857abda8610d4d581a90cc48c66..5b29ed6ef95d84de2b9ec450a5bd7c1bd7ba4fd3 100644 --- a/packages/core/src/indices/vectorStore/VectorStoreIndex.ts +++ b/packages/core/src/indices/vectorStore/VectorStoreIndex.ts @@ -130,7 +130,7 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> { indexStore: BaseIndexStore, options: IndexStructOptions, ) { - let indexStructs = (await indexStore.getIndexStructs()) as IndexDict[]; + const indexStructs = (await indexStore.getIndexStructs()) as IndexDict[]; let indexStruct: IndexDict | undefined; if (options.indexStruct && indexStructs.length > 0) { diff --git a/packages/core/src/ingestion/IngestionCache.ts b/packages/core/src/ingestion/IngestionCache.ts index a98459af8b489341e475ceed5b8c48914bcf55aa..f35e3f413e5e4af93074848be293d8fb86ef5b2d 100644 --- a/packages/core/src/ingestion/IngestionCache.ts +++ b/packages/core/src/ingestion/IngestionCache.ts @@ -6,7 +6,7 @@ import { BaseKVStore } from "../storage/kvStore/types"; import { TransformComponent } from "./types"; const transformToJSON = (obj: TransformComponent) => { - let seen: any[] = []; + const seen: any[] = []; const replacer = (key: string, value: any) => { if (value != null && typeof value == "object") { diff --git a/packages/core/src/llm/LLM.ts b/packages/core/src/llm/LLM.ts index 1a3a1ad41e49f946e07e8e3dcbc8287068e425d2..95ddd3ee785e39bc53c524ad0e41035bd07bb7a5 100644 --- a/packages/core/src/llm/LLM.ts +++ b/packages/core/src/llm/LLM.ts @@ -235,7 +235,7 @@ export class OpenAI extends BaseLLM { params: LLMChatParamsNonStreaming | LLMChatParamsStreaming, ): Promise<ChatResponse | AsyncIterable<ChatResponseChunk>> { const { messages, parentEvent, stream, tools, toolChoice } = params; - let baseRequestParams: OpenAILLM.Chat.ChatCompletionCreateParams = { + const baseRequestParams: OpenAILLM.Chat.ChatCompletionCreateParams = { model: this.model, temperature: this.temperature, max_tokens: this.maxTokens, diff --git a/packages/core/src/llm/anthropic.ts b/packages/core/src/llm/anthropic.ts index 4b8dbf0273462e65a587171a801dc8f301834a12..1a3dd0b48914ae7081f0392cdf10f7f748601bf6 100644 --- a/packages/core/src/llm/anthropic.ts +++ b/packages/core/src/llm/anthropic.ts @@ -26,7 +26,7 @@ export class AnthropicSession { // I'm not 100% sure this is necessary vs. just starting a new session // every time we make a call. They say they try to reuse connections // so in theory this is more efficient, but we should test it in the future. -let defaultAnthropicSession: { +const defaultAnthropicSession: { session: AnthropicSession; options: ClientOptions; }[] = []; diff --git a/packages/core/src/llm/open_ai.ts b/packages/core/src/llm/open_ai.ts index e7a6795f583c268f31983fc41a0a5c7fee49c690..e36f05f3af6c6125f174f6938bba224888e457d5 100644 --- a/packages/core/src/llm/open_ai.ts +++ b/packages/core/src/llm/open_ai.ts @@ -35,8 +35,10 @@ export class OpenAISession { // I'm not 100% sure this is necessary vs. just starting a new session // every time we make a call. They say they try to reuse connections // so in theory this is more efficient, but we should test it in the future. -let defaultOpenAISession: { session: OpenAISession; options: ClientOptions }[] = - []; +const defaultOpenAISession: { + session: OpenAISession; + options: ClientOptions; +}[] = []; /** * Get a session for the OpenAI API. If one already exists with the same options, diff --git a/packages/core/src/llm/portkey.ts b/packages/core/src/llm/portkey.ts index 92e65b1a3ebcfebc1d464578687f4705f35ead68..11eb401b358aead314a183fa7417f347c33c67b4 100644 --- a/packages/core/src/llm/portkey.ts +++ b/packages/core/src/llm/portkey.ts @@ -40,7 +40,7 @@ export class PortkeySession { } } -let defaultPortkeySession: { +const defaultPortkeySession: { session: PortkeySession; options: PortkeyOptions; }[] = []; diff --git a/packages/core/src/postprocessors/MetadataReplacementPostProcessor.ts b/packages/core/src/postprocessors/MetadataReplacementPostProcessor.ts index e53a6e43593f854c9f2f9d3783276b1ca9535f63..c15e3971801b45ca37f7ee9d1e4e46568b8ccc23 100644 --- a/packages/core/src/postprocessors/MetadataReplacementPostProcessor.ts +++ b/packages/core/src/postprocessors/MetadataReplacementPostProcessor.ts @@ -9,7 +9,7 @@ export class MetadataReplacementPostProcessor implements BaseNodePostprocessor { } async postprocessNodes(nodes: NodeWithScore[]): Promise<NodeWithScore[]> { - for (let n of nodes) { + for (const n of nodes) { n.node.setContent( n.node.metadata[this.targetMetadataKey] ?? n.node.getContent(MetadataMode.NONE), diff --git a/packages/core/src/prompts/Mixin.ts b/packages/core/src/prompts/Mixin.ts index eac847b916f8f8cb1a2846eeb5e1b3ec54106e2e..b49d2db12dbf7da2ff59695745145de7bdc4d1cb 100644 --- a/packages/core/src/prompts/Mixin.ts +++ b/packages/core/src/prompts/Mixin.ts @@ -8,13 +8,13 @@ export class PromptMixin { * @param moduleDict */ validatePrompts(promptsDict: PromptsDict, moduleDict: ModuleDict): void { - for (let key in promptsDict) { + for (const key in promptsDict) { if (key.includes(":")) { throw new Error(`Prompt key ${key} cannot contain ':'.`); } } - for (let key in moduleDict) { + for (const key in moduleDict) { if (key.includes(":")) { throw new Error(`Module key ${key} cannot contain ':'.`); } @@ -25,16 +25,16 @@ export class PromptMixin { * Returns all prompts from the mixin and its modules */ getPrompts(): PromptsDict { - let promptsDict: PromptsDict = this._getPrompts(); + const promptsDict: PromptsDict = this._getPrompts(); - let moduleDict = this._getPromptModules(); + const moduleDict = this._getPromptModules(); this.validatePrompts(promptsDict, moduleDict); - let allPrompts: PromptsDict = { ...promptsDict }; + const allPrompts: PromptsDict = { ...promptsDict }; - for (let [module_name, prompt_module] of Object.entries(moduleDict)) { - for (let [key, prompt] of Object.entries(prompt_module.getPrompts())) { + for (const [module_name, prompt_module] of Object.entries(moduleDict)) { + for (const [key, prompt] of Object.entries(prompt_module.getPrompts())) { allPrompts[`${module_name}:${key}`] = prompt; } } @@ -46,15 +46,15 @@ export class PromptMixin { * @param promptsDict */ updatePrompts(promptsDict: PromptsDict): void { - let promptModules = this._getPromptModules(); + const promptModules = this._getPromptModules(); this._updatePrompts(promptsDict); - let subPromptDicts: Record<string, PromptsDict> = {}; + const subPromptDicts: Record<string, PromptsDict> = {}; - for (let key in promptsDict) { + for (const key in promptsDict) { if (key.includes(":")) { - let [module_name, sub_key] = key.split(":"); + const [module_name, sub_key] = key.split(":"); if (!subPromptDicts[module_name]) { subPromptDicts[module_name] = {}; @@ -63,12 +63,12 @@ export class PromptMixin { } } - for (let [module_name, subPromptDict] of Object.entries(subPromptDicts)) { + for (const [module_name, subPromptDict] of Object.entries(subPromptDicts)) { if (!promptModules[module_name]) { throw new Error(`Module ${module_name} not found.`); } - let moduleToUpdate = promptModules[module_name]; + const moduleToUpdate = promptModules[module_name]; moduleToUpdate.updatePrompts(subPromptDict); } diff --git a/packages/core/src/readers/AssemblyAIReader.ts b/packages/core/src/readers/AssemblyAIReader.ts index 44d3fa42bc26cd10df2ead6f7532bacb7ecc6bb5..4e45ba866c34006d8f6f75322aa40ed18ed7333b 100644 --- a/packages/core/src/readers/AssemblyAIReader.ts +++ b/packages/core/src/readers/AssemblyAIReader.ts @@ -83,7 +83,7 @@ class AudioTranscriptParagraphsReader extends AssemblyAIReader { * @returns A promise that resolves to an array of documents, each containing a paragraph of the transcript. */ async loadData(params: TranscribeParams | string): Promise<Document[]> { - let transcriptId = await this.getTranscriptId(params); + const transcriptId = await this.getTranscriptId(params); const paragraphsResponse = await this.client.transcripts.paragraphs(transcriptId); return paragraphsResponse.paragraphs.map( @@ -102,7 +102,7 @@ class AudioTranscriptSentencesReader extends AssemblyAIReader { * @returns A promise that resolves to an array of documents, each containing a sentence of the transcript. */ async loadData(params: TranscribeParams | string): Promise<Document[]> { - let transcriptId = await this.getTranscriptId(params); + const transcriptId = await this.getTranscriptId(params); const sentencesResponse = await this.client.transcripts.sentences(transcriptId); return sentencesResponse.sentences.map( @@ -125,7 +125,7 @@ class AudioSubtitlesReader extends AssemblyAIReader { params: TranscribeParams | string, subtitleFormat: SubtitleFormat = "srt", ): Promise<Document[]> { - let transcriptId = await this.getTranscriptId(params); + const transcriptId = await this.getTranscriptId(params); const subtitles = await this.client.transcripts.subtitles( transcriptId, subtitleFormat, diff --git a/packages/core/src/readers/LlamaParseReader.ts b/packages/core/src/readers/LlamaParseReader.ts index ba9c670539afb95a6d8ed8cf53f5bfce669ae1e0..8055f555a8635da3bd0eaf828b61185390adfa14 100644 --- a/packages/core/src/readers/LlamaParseReader.ts +++ b/packages/core/src/readers/LlamaParseReader.ts @@ -74,7 +74,7 @@ export class LlamaParseReader implements FileReader { const resultUrl = `${this.baseUrl}/job/${jobId}/result/${this.resultType}`; - let start = Date.now(); + const start = Date.now(); let tries = 0; while (true) { await new Promise((resolve) => diff --git a/packages/core/src/readers/SimpleDirectoryReader.ts b/packages/core/src/readers/SimpleDirectoryReader.ts index af6ae549ce23290aac03442bf03b56f5e5f41688..81ab8fe79dd7bd2ee27faf0e9ba5f84f90f0db43 100644 --- a/packages/core/src/readers/SimpleDirectoryReader.ts +++ b/packages/core/src/readers/SimpleDirectoryReader.ts @@ -88,7 +88,7 @@ export class SimpleDirectoryReader implements BaseReader { return []; } - let docs: Document[] = []; + const docs: Document[] = []; for await (const filePath of walk(fs, directoryPath)) { try { const fileExt = path.extname(filePath).slice(1).toLowerCase(); diff --git a/packages/core/src/storage/docStore/KVDocumentStore.ts b/packages/core/src/storage/docStore/KVDocumentStore.ts index 8dd008de18c7b5a03e29fa2bbba1685a33bb5e4c..b14ab68bf708eb15df8aadf2fb8f16162a4f4788 100644 --- a/packages/core/src/storage/docStore/KVDocumentStore.ts +++ b/packages/core/src/storage/docStore/KVDocumentStore.ts @@ -22,9 +22,9 @@ export class KVDocumentStore extends BaseDocumentStore { } async docs(): Promise<Record<string, BaseNode>> { - let jsonDict = await this.kvstore.getAll(this.nodeCollection); - let docs: Record<string, BaseNode> = {}; - for (let key in jsonDict) { + const jsonDict = await this.kvstore.getAll(this.nodeCollection); + const docs: Record<string, BaseNode> = {}; + for (const key in jsonDict) { docs[key] = jsonToDoc(jsonDict[key] as Record<string, any>); } return docs; @@ -44,13 +44,15 @@ export class KVDocumentStore extends BaseDocumentStore { `doc_id ${doc.id_} already exists. Set allow_update to True to overwrite.`, ); } - let nodeKey = doc.id_; - let data = docToJson(doc); + const nodeKey = doc.id_; + const data = docToJson(doc); await this.kvstore.put(nodeKey, data, this.nodeCollection); - let metadata: DocMetaData = { docHash: doc.hash }; + const metadata: DocMetaData = { docHash: doc.hash }; if (doc.getType() === ObjectType.TEXT && doc.sourceNode !== undefined) { - let refDocInfo = (await this.getRefDocInfo(doc.sourceNode.nodeId)) || { + const refDocInfo = (await this.getRefDocInfo( + doc.sourceNode.nodeId, + )) || { nodeIds: [], extraInfo: {}, }; @@ -74,7 +76,7 @@ export class KVDocumentStore extends BaseDocumentStore { docId: string, raiseError: boolean = true, ): Promise<BaseNode | undefined> { - let json = await this.kvstore.get(docId, this.nodeCollection); + const json = await this.kvstore.get(docId, this.nodeCollection); if (_.isNil(json)) { if (raiseError) { throw new Error(`docId ${docId} not found.`); @@ -86,12 +88,12 @@ export class KVDocumentStore extends BaseDocumentStore { } async getRefDocInfo(refDocId: string): Promise<RefDocInfo | undefined> { - let refDocInfo = await this.kvstore.get(refDocId, this.refDocCollection); + const refDocInfo = await this.kvstore.get(refDocId, this.refDocCollection); return refDocInfo ? (_.clone(refDocInfo) as RefDocInfo) : undefined; } async getAllRefDocInfo(): Promise<Record<string, RefDocInfo> | undefined> { - let refDocInfos = await this.kvstore.getAll(this.refDocCollection); + const refDocInfos = await this.kvstore.getAll(this.refDocCollection); if (_.isNil(refDocInfos)) { return; } @@ -107,12 +109,12 @@ export class KVDocumentStore extends BaseDocumentStore { } private async removeRefDocNode(docId: string): Promise<void> { - let metadata = await this.kvstore.get(docId, this.metadataCollection); + const metadata = await this.kvstore.get(docId, this.metadataCollection); if (metadata === null) { return; } - let refDocId = metadata.refDocId; + const refDocId = metadata.refDocId; if (_.isNil(refDocId)) { return; } @@ -137,7 +139,7 @@ export class KVDocumentStore extends BaseDocumentStore { await this.removeRefDocNode(docId); } - let deleteSuccess = await this.kvstore.delete(docId, this.nodeCollection); + const deleteSuccess = await this.kvstore.delete(docId, this.nodeCollection); await this.kvstore.delete(docId, this.metadataCollection); if (!deleteSuccess && raiseError) { @@ -149,7 +151,7 @@ export class KVDocumentStore extends BaseDocumentStore { refDocId: string, raiseError: boolean = true, ): Promise<void> { - let refDocInfo = await this.getRefDocInfo(refDocId); + const refDocInfo = await this.getRefDocInfo(refDocId); if (_.isNil(refDocInfo)) { if (raiseError) { throw new Error(`ref_doc_id ${refDocId} not found.`); @@ -158,7 +160,7 @@ export class KVDocumentStore extends BaseDocumentStore { } } - for (let docId of refDocInfo.nodeIds) { + for (const docId of refDocInfo.nodeIds) { await this.deleteDocument(docId, false, false); } @@ -167,17 +169,17 @@ export class KVDocumentStore extends BaseDocumentStore { } async setDocumentHash(docId: string, docHash: string): Promise<void> { - let metadata = { docHash: docHash }; + const metadata = { docHash: docHash }; await this.kvstore.put(docId, metadata, this.metadataCollection); } async getDocumentHash(docId: string): Promise<string | undefined> { - let metadata = await this.kvstore.get(docId, this.metadataCollection); + const metadata = await this.kvstore.get(docId, this.metadataCollection); return _.get(metadata, "docHash"); } async getAllDocumentHashes(): Promise<Record<string, string>> { - let hashes: Record<string, string> = {}; + const hashes: Record<string, string> = {}; const metadataDocs = await this.kvstore.getAll(this.metadataCollection); for (const docId in metadataDocs) { const hash = await this.getDocumentHash(docId); diff --git a/packages/core/src/storage/docStore/types.ts b/packages/core/src/storage/docStore/types.ts index b44ebd845f8597048727c420cb9d927e73489c85..3ac144ae8c92170bff44b85ad81051250ad783f7 100644 --- a/packages/core/src/storage/docStore/types.ts +++ b/packages/core/src/storage/docStore/types.ts @@ -57,7 +57,7 @@ export abstract class BaseDocumentStore { } async getNode(nodeId: string, raiseError: boolean = true): Promise<BaseNode> { - let doc = await this.getDocument(nodeId, raiseError); + const doc = await this.getDocument(nodeId, raiseError); if (!(doc instanceof BaseNode)) { throw new Error(`Document ${nodeId} is not a Node.`); } @@ -67,8 +67,8 @@ export abstract class BaseDocumentStore { async getNodeDict(nodeIdDict: { [index: number]: string; }): Promise<Record<number, BaseNode>> { - let result: Record<number, BaseNode> = {}; - for (let index in nodeIdDict) { + const result: Record<number, BaseNode> = {}; + for (const index in nodeIdDict) { result[index] = await this.getNode(nodeIdDict[index]); } return result; diff --git a/packages/core/src/storage/docStore/utils.ts b/packages/core/src/storage/docStore/utils.ts index 9e74734b48b8ccbcf446047ae98f01dca290411c..e4c77f76a02051f8fbf00275ba5b446069788e02 100644 --- a/packages/core/src/storage/docStore/utils.ts +++ b/packages/core/src/storage/docStore/utils.ts @@ -11,8 +11,8 @@ export function docToJson(doc: BaseNode): Record<string, any> { } export function jsonToDoc(docDict: Record<string, any>): BaseNode { - let docType = docDict[TYPE_KEY]; - let dataDict = JSON.parse(docDict[DATA_KEY]); + const docType = docDict[TYPE_KEY]; + const dataDict = JSON.parse(docDict[DATA_KEY]); let doc: BaseNode; if (docType === ObjectType.DOCUMENT) { diff --git a/packages/core/src/storage/indexStore/KVIndexStore.ts b/packages/core/src/storage/indexStore/KVIndexStore.ts index c2d057700a15f8a02161b47232b5ac1f69273d61..b3744fabf8135c4929760d1d3ebc0ecdd004d4de 100644 --- a/packages/core/src/storage/indexStore/KVIndexStore.ts +++ b/packages/core/src/storage/indexStore/KVIndexStore.ts @@ -15,8 +15,8 @@ export class KVIndexStore extends BaseIndexStore { } async addIndexStruct(indexStruct: IndexStruct): Promise<void> { - let key = indexStruct.indexId; - let data = indexStruct.toJson(); + const key = indexStruct.indexId; + const data = indexStruct.toJson(); await this._kvStore.put(key, data, this._collection); } @@ -26,13 +26,13 @@ export class KVIndexStore extends BaseIndexStore { async getIndexStruct(structId?: string): Promise<IndexStruct | undefined> { if (_.isNil(structId)) { - let structs = await this.getIndexStructs(); + const structs = await this.getIndexStructs(); if (structs.length !== 1) { throw new Error("More than one index struct found"); } return structs[0]; } else { - let json = await this._kvStore.get(structId, this._collection); + const json = await this._kvStore.get(structId, this._collection); if (_.isNil(json)) { return; } @@ -41,7 +41,7 @@ export class KVIndexStore extends BaseIndexStore { } async getIndexStructs(): Promise<IndexStruct[]> { - let jsons = (await this._kvStore.getAll(this._collection)) as { + const jsons = (await this._kvStore.getAll(this._collection)) as { [key: string]: any; }; return _.values(jsons).map((json) => jsonToIndexStruct(json)); diff --git a/packages/core/src/storage/indexStore/SimpleIndexStore.ts b/packages/core/src/storage/indexStore/SimpleIndexStore.ts index faa68ac3f31763d1af80a16439f732cc16cf8249..49ab6f3cc377829078f5d33172aa0fb41efd2676 100644 --- a/packages/core/src/storage/indexStore/SimpleIndexStore.ts +++ b/packages/core/src/storage/indexStore/SimpleIndexStore.ts @@ -32,7 +32,7 @@ export class SimpleIndexStore extends KVIndexStore { persistPath: string, fs: GenericFileSystem = defaultFS, ): Promise<SimpleIndexStore> { - let simpleKVStore = await SimpleKVStore.fromPersistPath(persistPath, fs); + const simpleKVStore = await SimpleKVStore.fromPersistPath(persistPath, fs); return new SimpleIndexStore(simpleKVStore); } @@ -44,7 +44,7 @@ export class SimpleIndexStore extends KVIndexStore { } static fromDict(saveDict: DataType): SimpleIndexStore { - let simpleKVStore = SimpleKVStore.fromDict(saveDict); + const simpleKVStore = SimpleKVStore.fromDict(saveDict); return new SimpleIndexStore(simpleKVStore); } diff --git a/packages/core/src/storage/kvStore/SimpleKVStore.ts b/packages/core/src/storage/kvStore/SimpleKVStore.ts index 30c932debdad9ae390889c4546abd1d9f5040c19..cefa6498ffa915db51075b64c1673834cd25b45a 100644 --- a/packages/core/src/storage/kvStore/SimpleKVStore.ts +++ b/packages/core/src/storage/kvStore/SimpleKVStore.ts @@ -33,7 +33,7 @@ export class SimpleKVStore extends BaseKVStore { key: string, collection: string = DEFAULT_COLLECTION, ): Promise<any> { - let collectionData = this.data[collection]; + const collectionData = this.data[collection]; if (_.isNil(collectionData)) { return null; } @@ -61,7 +61,7 @@ export class SimpleKVStore extends BaseKVStore { async persist(persistPath: string, fs?: GenericFileSystem): Promise<void> { fs = fs || defaultFS; // TODO: decide on a way to polyfill path - let dirPath = path.dirname(persistPath); + const dirPath = path.dirname(persistPath); if (!(await exists(fs, dirPath))) { await fs.mkdir(dirPath); } @@ -73,14 +73,14 @@ export class SimpleKVStore extends BaseKVStore { fs?: GenericFileSystem, ): Promise<SimpleKVStore> { fs = fs || defaultFS; - let dirPath = path.dirname(persistPath); + const dirPath = path.dirname(persistPath); if (!(await exists(fs, dirPath))) { await fs.mkdir(dirPath); } let data: DataType = {}; try { - let fileData = await fs.readFile(persistPath); + const fileData = await fs.readFile(persistPath); data = JSON.parse(fileData.toString()); } catch (e) { console.error( diff --git a/packages/core/src/storage/vectorStore/AstraDBVectorStore.ts b/packages/core/src/storage/vectorStore/AstraDBVectorStore.ts index ef9b3f02c018d2ea72e67e8f5a502a7edee37ed4..fd258c3b8c3ef2cdf36873903866b4fa6d9904c9 100644 --- a/packages/core/src/storage/vectorStore/AstraDBVectorStore.ts +++ b/packages/core/src/storage/vectorStore/AstraDBVectorStore.ts @@ -128,7 +128,7 @@ export class AstraDBVectorStore implements VectorStore { console.debug(`Adding ${dataToInsert.length} rows to table`); // Perform inserts in steps of MAX_INSERT_BATCH_SIZE - let batchData: any[] = []; + const batchData: any[] = []; for (let i = 0; i < dataToInsert.length; i += MAX_INSERT_BATCH_SIZE) { batchData.push(dataToInsert.slice(i, i + MAX_INSERT_BATCH_SIZE)); diff --git a/packages/core/src/storage/vectorStore/PGVectorStore.ts b/packages/core/src/storage/vectorStore/PGVectorStore.ts index 315568ac5b6d8e40d9d50ef0b8bc7d0bd47b5730..ad3b7ca9acf84b3b4947048fecbb150065ec2816 100644 --- a/packages/core/src/storage/vectorStore/PGVectorStore.ts +++ b/packages/core/src/storage/vectorStore/PGVectorStore.ts @@ -154,8 +154,8 @@ export class PGVectorStore implements VectorStore { for (let index = 0; index < embeddingResults.length; index++) { const row = embeddingResults[index]; - let id: any = row.id_.length ? row.id_ : null; - let meta = row.metadata || {}; + const id: any = row.id_.length ? row.id_ : null; + const meta = row.metadata || {}; meta.create_date = new Date(); const params = [ @@ -191,7 +191,7 @@ export class PGVectorStore implements VectorStore { const db = (await this.getDb()) as pg.Client; const data = this.getDataToInsert(embeddingResults); - let ret: string[] = []; + const ret: string[] = []; for (let index = 0; index < data.length; index++) { const params = data[index]; try { diff --git a/packages/core/src/storage/vectorStore/PineconeVectorStore.ts b/packages/core/src/storage/vectorStore/PineconeVectorStore.ts index 08f6384f3daeb0a8ab36b6fe67cb1a98055aa290..42e7ffe9c9ee116c63a16e361d2dc4f1e96896d5 100644 --- a/packages/core/src/storage/vectorStore/PineconeVectorStore.ts +++ b/packages/core/src/storage/vectorStore/PineconeVectorStore.ts @@ -213,7 +213,7 @@ export class PineconeVectorStore implements VectorStore { } nodeToRecord(node: BaseNode<Metadata>) { - let id: any = node.id_.length ? node.id_ : null; + const id: any = node.id_.length ? node.id_ : null; return { id: id, values: node.getEmbedding(), diff --git a/packages/core/src/storage/vectorStore/SimpleVectorStore.ts b/packages/core/src/storage/vectorStore/SimpleVectorStore.ts index 3c9f646060fea10fef5e8c3bf2fa010800b53995..8b995e2c9cab7791bf6b4fb493644c40ffc8ee3e 100644 --- a/packages/core/src/storage/vectorStore/SimpleVectorStore.ts +++ b/packages/core/src/storage/vectorStore/SimpleVectorStore.ts @@ -43,7 +43,7 @@ export class SimpleVectorStore implements VectorStore { persistDir: string = DEFAULT_PERSIST_DIR, fs: GenericFileSystem = defaultFS, ): Promise<SimpleVectorStore> { - let persistPath = `${persistDir}/vector_store.json`; + const persistPath = `${persistDir}/vector_store.json`; return await SimpleVectorStore.fromPersistPath(persistPath, fs); } @@ -56,7 +56,7 @@ export class SimpleVectorStore implements VectorStore { } async add(embeddingResults: BaseNode[]): Promise<string[]> { - for (let node of embeddingResults) { + for (const node of embeddingResults) { this.data.embeddingDict[node.id_] = node.getEmbedding(); if (!node.sourceNode) { @@ -74,10 +74,10 @@ export class SimpleVectorStore implements VectorStore { } async delete(refDocId: string): Promise<void> { - let textIdsToDelete = Object.keys(this.data.textIdToRefDocId).filter( + const textIdsToDelete = Object.keys(this.data.textIdToRefDocId).filter( (textId) => this.data.textIdToRefDocId[textId] === refDocId, ); - for (let textId of textIdsToDelete) { + for (const textId of textIdsToDelete) { delete this.data.embeddingDict[textId]; delete this.data.textIdToRefDocId[textId]; } @@ -91,11 +91,11 @@ export class SimpleVectorStore implements VectorStore { ); } - let items = Object.entries(this.data.embeddingDict); + const items = Object.entries(this.data.embeddingDict); let nodeIds: string[], embeddings: number[][]; if (query.docIds) { - let availableIds = new Set(query.docIds); + const availableIds = new Set(query.docIds); const queriedItems = items.filter((item) => availableIds.has(item[0])); nodeIds = queriedItems.map((item) => item[0]); embeddings = queriedItems.map((item) => item[1]); @@ -105,7 +105,7 @@ export class SimpleVectorStore implements VectorStore { embeddings = items.map((item) => item[1]); } - let queryEmbedding = query.queryEmbedding!; + const queryEmbedding = query.queryEmbedding!; let topSimilarities: number[], topIds: string[]; if (LEARNER_MODES.has(query.mode)) { @@ -116,7 +116,7 @@ export class SimpleVectorStore implements VectorStore { nodeIds, ); } else if (query.mode === MMR_MODE) { - let mmrThreshold = query.mmrThreshold; + const mmrThreshold = query.mmrThreshold; [topSimilarities, topIds] = getTopKMMREmbeddings( queryEmbedding, embeddings, @@ -147,7 +147,7 @@ export class SimpleVectorStore implements VectorStore { fs?: GenericFileSystem, ): Promise<void> { fs = fs || this.fs; - let dirPath = path.dirname(persistPath); + const dirPath = path.dirname(persistPath); if (!(await exists(fs, dirPath))) { await fs.mkdir(dirPath); } @@ -161,14 +161,14 @@ export class SimpleVectorStore implements VectorStore { ): Promise<SimpleVectorStore> { fs = fs || defaultFS; - let dirPath = path.dirname(persistPath); + const dirPath = path.dirname(persistPath); if (!(await exists(fs, dirPath))) { await fs.mkdir(dirPath, { recursive: true }); } let dataDict: any = {}; try { - let fileData = await fs.readFile(persistPath); + const fileData = await fs.readFile(persistPath); dataDict = JSON.parse(fileData.toString()); } catch (e) { console.error( @@ -176,7 +176,7 @@ export class SimpleVectorStore implements VectorStore { ); } - let data = new SimpleVectorStoreData(); + const data = new SimpleVectorStoreData(); data.embeddingDict = dataDict.embeddingDict ?? {}; data.textIdToRefDocId = dataDict.textIdToRefDocId ?? {}; const store = new SimpleVectorStore(data); @@ -186,7 +186,7 @@ export class SimpleVectorStore implements VectorStore { } static fromDict(saveDict: SimpleVectorStoreData): SimpleVectorStore { - let data = new SimpleVectorStoreData(); + const data = new SimpleVectorStoreData(); data.embeddingDict = saveDict.embeddingDict; data.textIdToRefDocId = saveDict.textIdToRefDocId; return new SimpleVectorStore(data); diff --git a/packages/core/src/storage/vectorStore/utils.ts b/packages/core/src/storage/vectorStore/utils.ts index f0c2a512b8935854e6da0b6e9875afa1d0faea6c..0944341ac7ca3ab72a0f269b0e7e956e6461354a 100644 --- a/packages/core/src/storage/vectorStore/utils.ts +++ b/packages/core/src/storage/vectorStore/utils.ts @@ -3,7 +3,7 @@ import { BaseNode, jsonToNode, Metadata, ObjectType } from "../../Node"; const DEFAULT_TEXT_KEY = "text"; export function validateIsFlat(obj: { [key: string]: any }): void { - for (let key in obj) { + for (const key in obj) { if (typeof obj[key] === "object" && obj[key] !== null) { throw new Error(`Value for metadata ${key} must not be another object`); } diff --git a/packages/core/src/synthesizers/MultiModalResponseSynthesizer.ts b/packages/core/src/synthesizers/MultiModalResponseSynthesizer.ts index a6a442a9d30a69a79c35f9c5f7c052d2a23c11fe..849b8ad271f399c3f92e2b41121ad08b863dd835 100644 --- a/packages/core/src/synthesizers/MultiModalResponseSynthesizer.ts +++ b/packages/core/src/synthesizers/MultiModalResponseSynthesizer.ts @@ -82,7 +82,7 @@ export class MultiModalResponseSynthesizer { type: "text", text: textPrompt }, ...images, ]; - let response = await this.serviceContext.llm.complete({ + const response = await this.serviceContext.llm.complete({ prompt, parentEvent, }); diff --git a/packages/core/src/tests/Embedding.test.ts b/packages/core/src/tests/Embedding.test.ts index 4f3b4262b3a97f626240bd69d0280c54738ab9c2..5fa58a6024534a7e22ae446dddd1d23df13ec083 100644 --- a/packages/core/src/tests/Embedding.test.ts +++ b/packages/core/src/tests/Embedding.test.ts @@ -55,7 +55,7 @@ describe("[OpenAIEmbedding]", () => { let embedModel: OpenAIEmbedding; beforeAll(() => { - let openAIEmbedding = new OpenAIEmbedding(); + const openAIEmbedding = new OpenAIEmbedding(); mockEmbeddingModel(openAIEmbedding); diff --git a/packages/core/src/tests/GenericFileSystem.test.ts b/packages/core/src/tests/GenericFileSystem.test.ts index 45be8f5687342f0a24a49d35f566c74200cc68c5..1ebb9da228737c11e5a880caec877a26d3951b84 100644 --- a/packages/core/src/tests/GenericFileSystem.test.ts +++ b/packages/core/src/tests/GenericFileSystem.test.ts @@ -119,7 +119,7 @@ describe("Test walk for Node.js fs", () => { ]); const actualFiles = new Set<string>(); - for await (let file of walk(nodeFS, tempDir)) { + for await (const file of walk(nodeFS, tempDir)) { expect(file).toBeTruthy(); actualFiles.add(file); } diff --git a/packages/core/src/tests/TextSplitter.test.ts b/packages/core/src/tests/TextSplitter.test.ts index 663cc135204fe922279013799008c0a873b5a7fe..baa37cc995be3ca6006ab21672b2119c3c01ed75 100644 --- a/packages/core/src/tests/TextSplitter.test.ts +++ b/packages/core/src/tests/TextSplitter.test.ts @@ -11,7 +11,7 @@ describe("SentenceSplitter", () => { paragraphSeparator: "\n\n\n", }); // generate the same line as above but correct syntax errors - let splits = sentenceSplitter.getParagraphSplits( + const splits = sentenceSplitter.getParagraphSplits( "This is a paragraph.\n\n\nThis is another paragraph.", undefined, ); @@ -26,7 +26,7 @@ describe("SentenceSplitter", () => { paragraphSeparator: "\n", }); // generate the same line as above but correct syntax errors - let splits = sentenceSplitter.getParagraphSplits( + const splits = sentenceSplitter.getParagraphSplits( "This is a paragraph.\nThis is another paragraph.", 1000, ); @@ -37,7 +37,7 @@ describe("SentenceSplitter", () => { test("splits sentences", () => { const sentenceSplitter = new SentenceSplitter(); - let splits = sentenceSplitter.getSentenceSplits( + const splits = sentenceSplitter.getSentenceSplits( "This is a sentence. This is another sentence.", undefined, ); @@ -68,11 +68,11 @@ describe("SentenceSplitter", () => { }); test("doesn't split decimals", () => { - let sentenceSplitter = new SentenceSplitter({ + const sentenceSplitter = new SentenceSplitter({ chunkSize: 5, chunkOverlap: 0, }); - let splits = sentenceSplitter.splitText( + const splits = sentenceSplitter.splitText( "This is a sentence. This is another sentence. 1.0", ); @@ -84,7 +84,7 @@ describe("SentenceSplitter", () => { }); test("splits cjk", () => { - let sentenceSplitter = new SentenceSplitter({ + const sentenceSplitter = new SentenceSplitter({ chunkSize: 12, chunkOverlap: 0, chunkingTokenizerFn: cjkSentenceTokenizer, diff --git a/packages/create-llama/e2e/utils.ts b/packages/create-llama/e2e/utils.ts index 2ec35e40b9f31dc2b82e8f98d5431de3f45c5d7f..87a6df8e00b14b3ee55a7ccce89779997dab2d1d 100644 --- a/packages/create-llama/e2e/utils.ts +++ b/packages/create-llama/e2e/utils.ts @@ -121,7 +121,7 @@ export async function runCreateLlama( "none", ].join(" "); console.log(`running command '${command}' in ${cwd}`); - let appProcess = exec(command, { + const appProcess = exec(command, { cwd, env: { ...process.env, diff --git a/packages/create-llama/helpers/index.ts b/packages/create-llama/helpers/index.ts index 70a112444f03b7c4083e23664b007f9fb50c59b0..21d9f86a45976af0a0d18afe996c17b7a2749289 100644 --- a/packages/create-llama/helpers/index.ts +++ b/packages/create-llama/helpers/index.ts @@ -70,7 +70,7 @@ const createEnvLocalFile = async ( switch (opts?.dataSource?.type) { case "web": { - let webConfig = opts?.dataSource.config as WebSourceConfig; + const webConfig = opts?.dataSource.config as WebSourceConfig; content += `# web loader config\n`; content += `BASE_URL=${webConfig.baseUrl}\n`; content += `URL_PREFIX=${webConfig.baseUrl}\n`; @@ -102,7 +102,7 @@ const generateContextData = async ( if (framework === "fastapi") { if (hasOpenAiKey && !hasVectorDb && isHavingPoetryLockFile()) { console.log(`Running ${runGenerate} to generate the context data.`); - let result = tryPoetryRun("python app/engine/generate.py"); + const result = tryPoetryRun("python app/engine/generate.py"); if (!result) { console.log(`Failed to run ${runGenerate}.`); process.exit(1); @@ -134,7 +134,7 @@ const copyContextData = async ( ) => { const destPath = path.join(root, "data"); - let dataSourceConfig = dataSource?.config as FileSourceConfig; + const dataSourceConfig = dataSource?.config as FileSourceConfig; // Copy file if (dataSource?.type === "file") { @@ -154,7 +154,7 @@ const copyContextData = async ( // Copy folder if (dataSource?.type === "folder") { - let srcPath = + const srcPath = dataSourceConfig.path ?? path.join(templatesDir, "components", "data"); console.log(`\nCopying data to ${cyan(destPath)}\n`); await copy("**", destPath, { diff --git a/packages/create-llama/helpers/python.ts b/packages/create-llama/helpers/python.ts index 39be2f32e8eacbf8b8213558aeb89373770465b8..8047d523543df56fb7eb76130560cad480bad901 100644 --- a/packages/create-llama/helpers/python.ts +++ b/packages/create-llama/helpers/python.ts @@ -244,7 +244,7 @@ export const installPythonTemplate = async ({ const dataSourceType = dataSource?.type; if (dataSourceType !== undefined && dataSourceType !== "none") { - let loaderPath = + const loaderPath = dataSourceType === "folder" ? path.join(compPath, "loaders", "python", "file") : path.join(compPath, "loaders", "python", dataSourceType); diff --git a/packages/create-llama/helpers/run-app.ts b/packages/create-llama/helpers/run-app.ts index dbadda0badb6102b9a0d9efe076b2f720f23f5be..616787a7398af4fed2bada689a07d0944f01cdbd 100644 --- a/packages/create-llama/helpers/run-app.ts +++ b/packages/create-llama/helpers/run-app.ts @@ -33,7 +33,7 @@ export async function runApp( ): Promise<any> { let backendAppProcess: ChildProcess; let frontendAppProcess: ChildProcess | undefined; - let frontendPort = port || 3000; + const frontendPort = port || 3000; let backendPort = externalPort || 8000; // Callback to kill app processes diff --git a/packages/create-llama/helpers/tools.ts b/packages/create-llama/helpers/tools.ts index f7b844cbb195bfc4c69ebf390a78d884887df2e3..49559253776d3fef308b130e14a067fd6481db6a 100644 --- a/packages/create-llama/helpers/tools.ts +++ b/packages/create-llama/helpers/tools.ts @@ -45,7 +45,7 @@ export const getTool = (toolName: string): Tool | undefined => { }; export const getTools = (toolsName: string[]): Tool[] => { - let tools: Tool[] = []; + const tools: Tool[] = []; for (const toolName of toolsName) { const tool = getTool(toolName); if (!tool) { diff --git a/packages/create-llama/questions.ts b/packages/create-llama/questions.ts index c6bf438b0e256055cb3e338e94eed5d65aab8c8e..395773cd0719175a0bf1418a7b6e85cd2004449c 100644 --- a/packages/create-llama/questions.ts +++ b/packages/create-llama/questions.ts @@ -108,7 +108,7 @@ const getVectorDbChoices = (framework: TemplateFramework) => { }; const getDataSourceChoices = (framework: TemplateFramework) => { - let choices = [ + const choices = [ { title: "No data, just a simple chat", value: "simple", @@ -159,7 +159,7 @@ const selectLocalContextData = async (type: TemplateDataSourceType) => { } selectedPath = execSync(execScript, execOpts).toString().trim(); if (type === "file") { - let fileType = path.extname(selectedPath); + const fileType = path.extname(selectedPath); if (!supportedContextFileTypes.includes(fileType)) { console.log( red( @@ -204,7 +204,7 @@ export const askQuestions = async ( if (ciInfo.isCI) { program.postInstallAction = getPrefOrDefault("postInstallAction"); } else { - let actionChoices = [ + const actionChoices = [ { title: "Just generate code (~1 sec)", value: "none", @@ -535,7 +535,7 @@ export const askQuestions = async ( if (!baseUrl.includes("://")) { baseUrl = `https://${baseUrl}`; } - let checkUrl = new URL(baseUrl); + const checkUrl = new URL(baseUrl); if (checkUrl.protocol !== "https:" && checkUrl.protocol !== "http:") { throw new Error("Invalid protocol"); } diff --git a/packages/create-llama/templates/components/vectordbs/typescript/none/index.ts b/packages/create-llama/templates/components/vectordbs/typescript/none/index.ts index c3b65ce2366f26ad74c4a66f9ce53ab9347fafdd..e335446cfd72e9da910eab3228848e32e1e0475a 100644 --- a/packages/create-llama/templates/components/vectordbs/typescript/none/index.ts +++ b/packages/create-llama/templates/components/vectordbs/typescript/none/index.ts @@ -14,7 +14,7 @@ async function getDataSource(llm: LLM) { chunkSize: CHUNK_SIZE, chunkOverlap: CHUNK_OVERLAP, }); - let storageContext = await storageContextFromDefaults({ + const storageContext = await storageContextFromDefaults({ persistDir: `${STORAGE_CACHE_DIR}`, });