From 3a6e2874434a1f344374fb4b6cbbab19764baabb Mon Sep 17 00:00:00 2001 From: Alex Yang <himself65@outlook.com> Date: Sat, 24 Feb 2024 08:56:44 +0800 Subject: [PATCH] feat: enable `verbatimModuleSyntax` (#562) --- .changeset/pink-bulldogs-exist.md | 5 ++ .eslintrc.js | 2 +- packages/core/src/ChatHistory.ts | 9 ++-- packages/core/src/GlobalsHelper.ts | 10 ++-- packages/core/src/Node.ts | 3 +- packages/core/src/OutputParser.ts | 8 +-- packages/core/src/Prompt.ts | 6 +-- packages/core/src/PromptHelper.ts | 2 +- packages/core/src/QuestionGenerator.ts | 20 ++++--- packages/core/src/Response.ts | 2 +- packages/core/src/Retriever.ts | 6 +-- packages/core/src/ServiceContext.ts | 7 +-- packages/core/src/agent/openai/base.ts | 9 ++-- packages/core/src/agent/openai/utils.ts | 2 +- packages/core/src/agent/openai/worker.ts | 17 +++--- packages/core/src/agent/react/base.ts | 8 +-- packages/core/src/agent/react/formatter.ts | 7 +-- packages/core/src/agent/react/outputParser.ts | 2 +- packages/core/src/agent/react/types.ts | 2 +- packages/core/src/agent/react/worker.ts | 12 +++-- packages/core/src/agent/runner/base.ts | 9 ++-- packages/core/src/agent/runner/types.ts | 5 +- packages/core/src/agent/types.ts | 4 +- packages/core/src/agent/utils.ts | 8 +-- .../core/src/callbacks/CallbackManager.ts | 2 +- packages/core/src/cloud/LlamaCloudIndex.ts | 13 ++--- .../core/src/cloud/LlamaCloudRetriever.ts | 22 ++++---- packages/core/src/cloud/types.ts | 2 +- packages/core/src/cloud/utils.ts | 5 +- packages/core/src/embeddings/ClipEmbedding.ts | 2 +- .../src/embeddings/MultiModalEmbedding.ts | 2 +- .../core/src/embeddings/OllamaEmbedding.ts | 2 +- .../core/src/embeddings/OpenAIEmbedding.ts | 7 +-- packages/core/src/embeddings/types.ts | 5 +- packages/core/src/embeddings/utils.ts | 6 +-- .../chat/CondenseQuestionChatEngine.ts | 19 ++++--- .../src/engines/chat/ContextChatEngine.ts | 23 ++++---- .../engines/chat/DefaultContextGenerator.ts | 16 +++--- .../core/src/engines/chat/SimpleChatEngine.ts | 8 +-- packages/core/src/engines/chat/types.ts | 14 ++--- .../src/engines/query/RetrieverQueryEngine.ts | 20 ++++--- .../src/engines/query/RouterQueryEngine.ts | 13 +++-- .../engines/query/SubQuestionQueryEngine.ts | 19 ++++--- packages/core/src/engines/query/types.ts | 2 +- .../core/src/extractors/MetadataExtractors.ts | 6 ++- packages/core/src/extractors/types.ts | 5 +- packages/core/src/indices/BaseIndex.ts | 18 +++---- .../core/src/indices/json-to-index-struct.ts | 3 +- packages/core/src/indices/keyword/index.ts | 31 ++++++----- packages/core/src/indices/summary/index.ts | 32 ++++++------ packages/core/src/indices/summary/utils.ts | 3 +- .../core/src/indices/vectorStore/index.ts | 52 +++++++++---------- packages/core/src/ingestion/IngestionCache.ts | 7 +-- .../core/src/ingestion/IngestionPipeline.ts | 10 ++-- .../strategies/DuplicatesStrategy.ts | 6 +-- .../strategies/UpsertsAndDeleteStrategy.ts | 4 +- .../ingestion/strategies/UpsertsStrategy.ts | 8 +-- .../core/src/ingestion/strategies/classify.ts | 4 +- .../core/src/ingestion/strategies/index.ts | 6 +-- packages/core/src/ingestion/types.ts | 2 +- packages/core/src/llm/LLM.ts | 27 +++++----- packages/core/src/llm/anthropic.ts | 7 +-- packages/core/src/llm/base.ts | 2 +- packages/core/src/llm/mistral.ts | 6 +-- packages/core/src/llm/ollama.ts | 4 +- packages/core/src/llm/open_ai.ts | 3 +- packages/core/src/llm/portkey.ts | 3 +- packages/core/src/llm/types.ts | 4 +- packages/core/src/llm/utils.ts | 4 +- packages/core/src/memory/ChatMemoryBuffer.ts | 6 +-- packages/core/src/memory/types.ts | 2 +- .../src/nodeParsers/MarkdownNodeParser.ts | 5 +- .../nodeParsers/SentenceWindowNodeParser.ts | 4 +- .../core/src/nodeParsers/SimpleNodeParser.ts | 4 +- packages/core/src/nodeParsers/types.ts | 4 +- packages/core/src/nodeParsers/utils.ts | 2 +- packages/core/src/objects/base.ts | 9 ++-- packages/core/src/outputParsers/selectors.ts | 2 +- .../MetadataReplacementPostProcessor.ts | 5 +- .../postprocessors/SimilarityPostprocessor.ts | 4 +- .../postprocessors/rerankers/CohereRerank.ts | 5 +- packages/core/src/postprocessors/types.ts | 2 +- packages/core/src/readers/AssemblyAIReader.ts | 6 +-- packages/core/src/readers/CSVReader.ts | 7 +-- packages/core/src/readers/DocxReader.ts | 4 +- packages/core/src/readers/HTMLReader.ts | 4 +- packages/core/src/readers/ImageReader.ts | 7 +-- packages/core/src/readers/LlamaParseReader.ts | 4 +- packages/core/src/readers/MarkdownReader.ts | 4 +- packages/core/src/readers/NotionReader.ts | 7 +-- packages/core/src/readers/PDFReader.ts | 4 +- .../core/src/readers/SimpleDirectoryReader.ts | 4 +- .../core/src/readers/SimpleMongoReader.ts | 7 +-- packages/core/src/readers/type.ts | 4 +- packages/core/src/selectors/base.ts | 2 +- packages/core/src/selectors/llmSelectors.ts | 13 ++--- packages/core/src/selectors/utils.ts | 4 +- packages/core/src/storage/FileSystem.ts | 5 +- packages/core/src/storage/StorageContext.ts | 8 +-- .../src/storage/chatStore/SimpleChatStore.ts | 4 +- packages/core/src/storage/chatStore/types.ts | 2 +- .../src/storage/docStore/KVDocumentStore.ts | 10 ++-- .../storage/docStore/SimpleDocumentStore.ts | 2 +- packages/core/src/storage/docStore/types.ts | 2 +- packages/core/src/storage/docStore/utils.ts | 3 +- .../src/storage/indexStore/KVIndexStore.ts | 4 +- .../storage/indexStore/SimpleIndexStore.ts | 7 +-- packages/core/src/storage/indexStore/types.ts | 4 +- .../core/src/storage/kvStore/SimpleKVStore.ts | 2 +- packages/core/src/storage/kvStore/types.ts | 2 +- .../storage/vectorStore/AstraDBVectorStore.ts | 7 +-- .../storage/vectorStore/ChromaVectorStore.ts | 12 ++--- .../vectorStore/MongoDBAtlasVectorStore.ts | 8 +-- .../src/storage/vectorStore/PGVectorStore.ts | 15 +++--- .../vectorStore/PineconeVectorStore.ts | 10 ++-- .../storage/vectorStore/QdrantVectorStore.ts | 4 +- .../storage/vectorStore/SimpleVectorStore.ts | 8 +-- .../core/src/storage/vectorStore/types.ts | 2 +- .../core/src/storage/vectorStore/utils.ts | 3 +- .../MultiModalResponseSynthesizer.ts | 16 +++--- .../src/synthesizers/ResponseSynthesizer.ts | 11 ++-- packages/core/src/synthesizers/builders.ts | 21 ++++---- packages/core/src/synthesizers/types.ts | 8 +-- packages/core/src/tools/QueryEngineTool.ts | 2 +- packages/core/src/tools/functionTool.ts | 2 +- packages/core/src/tools/utils.ts | 2 +- packages/core/src/types.ts | 4 +- packages/core/tests/CallbackManager.test.ts | 10 ++-- .../core/tests/MetadataExtractors.test.ts | 10 ++-- .../tests/ingestion/IngestionCache.test.ts | 5 +- .../tests/mocks/TestableQdrantVectorStore.ts | 2 +- .../core/tests/objects/ObjectIndex.test.ts | 2 +- .../MetadataReplacementPostProcessor.test.ts | 3 +- packages/core/tests/utility/mockOpenAI.ts | 8 +-- .../vectorStores/QdrantVectorStore.test.ts | 6 ++- packages/core/tsconfig.json | 9 ++-- packages/env/src/index.polyfill.ts | 2 +- packages/env/tsconfig.json | 11 ++-- tsconfig.json | 1 + 139 files changed, 527 insertions(+), 491 deletions(-) create mode 100644 .changeset/pink-bulldogs-exist.md diff --git a/.changeset/pink-bulldogs-exist.md b/.changeset/pink-bulldogs-exist.md new file mode 100644 index 000000000..891862ad3 --- /dev/null +++ b/.changeset/pink-bulldogs-exist.md @@ -0,0 +1,5 @@ +--- +"llamaindex": patch +--- + +build: improve tree-shake & reduce unused package import diff --git a/.eslintrc.js b/.eslintrc.js index 52a920c48..4b4b23a92 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -11,5 +11,5 @@ module.exports = { "max-params": ["error", 4], "prefer-const": "error", }, - ignorePatterns: ["dist/"], + ignorePatterns: ["dist/", "lib/"], }; diff --git a/packages/core/src/ChatHistory.ts b/packages/core/src/ChatHistory.ts index 31ff9dd70..ff8155d9c 100644 --- a/packages/core/src/ChatHistory.ts +++ b/packages/core/src/ChatHistory.ts @@ -1,10 +1,7 @@ import { OpenAI } from "./llm/LLM.js"; -import { ChatMessage, LLM, MessageType } from "./llm/types.js"; -import { - defaultSummaryPrompt, - messagesToHistoryStr, - SummaryPrompt, -} from "./Prompt.js"; +import type { ChatMessage, LLM, MessageType } from "./llm/types.js"; +import type { SummaryPrompt } from "./Prompt.js"; +import { defaultSummaryPrompt, messagesToHistoryStr } from "./Prompt.js"; /** * A ChatHistory is used to keep the state of back and forth chat messages diff --git a/packages/core/src/GlobalsHelper.ts b/packages/core/src/GlobalsHelper.ts index 7df884840..97d283d91 100644 --- a/packages/core/src/GlobalsHelper.ts +++ b/packages/core/src/GlobalsHelper.ts @@ -1,7 +1,11 @@ import { encodingForModel } from "js-tiktoken"; import { randomUUID } from "@llamaindex/env"; -import { Event, EventTag, EventType } from "./callbacks/CallbackManager.js"; +import type { + Event, + EventTag, + EventType, +} from "./callbacks/CallbackManager.js"; export enum Tokenizers { CL100K_BASE = "cl100k_base", @@ -32,7 +36,7 @@ class GlobalsHelper { }; } - tokenizer(encoding?: string) { + tokenizer(encoding?: Tokenizers) { if (encoding && encoding !== Tokenizers.CL100K_BASE) { throw new Error(`Tokenizer encoding ${encoding} not yet supported`); } @@ -43,7 +47,7 @@ class GlobalsHelper { return this.defaultTokenizer!.encode.bind(this.defaultTokenizer); } - tokenizerDecoder(encoding?: string) { + tokenizerDecoder(encoding?: Tokenizers) { if (encoding && encoding !== Tokenizers.CL100K_BASE) { throw new Error(`Tokenizer encoding ${encoding} not yet supported`); } diff --git a/packages/core/src/Node.ts b/packages/core/src/Node.ts index b03a6d2c5..bb7e43c69 100644 --- a/packages/core/src/Node.ts +++ b/packages/core/src/Node.ts @@ -65,7 +65,8 @@ export abstract class BaseNode<T extends Metadata = Metadata> { abstract getContent(metadataMode: MetadataMode): string; abstract getMetadataStr(metadataMode: MetadataMode): string; - abstract setContent(value: any): void; + // todo: set value as a generic type + abstract setContent(value: unknown): void; get sourceNode(): RelatedNodeInfo<T> | undefined { const relationship = this.relationships[NodeRelationship.SOURCE]; diff --git a/packages/core/src/OutputParser.ts b/packages/core/src/OutputParser.ts index 37f016f5b..488f33576 100644 --- a/packages/core/src/OutputParser.ts +++ b/packages/core/src/OutputParser.ts @@ -1,5 +1,5 @@ -import { SubQuestion } from "./engines/query/types.js"; -import { BaseOutputParser, StructuredOutput } from "./types.js"; +import type { SubQuestion } from "./engines/query/types.js"; +import type { BaseOutputParser, StructuredOutput } from "./types.js"; /** * Error class for output parsing. Due to the nature of LLMs, anytime we use LLM @@ -44,8 +44,8 @@ export function parseJsonMarkdown(text: string) { const left_square = text.indexOf("["); const left_brace = text.indexOf("{"); - var left: number; - var right: number; + let left: number; + let right: number; if (left_square < left_brace && left_square != -1) { left = left_square; right = text.lastIndexOf("]"); diff --git a/packages/core/src/Prompt.ts b/packages/core/src/Prompt.ts index bf967d15c..3d0cdffef 100644 --- a/packages/core/src/Prompt.ts +++ b/packages/core/src/Prompt.ts @@ -1,6 +1,6 @@ -import { SubQuestion } from "./engines/query/types.js"; -import { ChatMessage } from "./llm/types.js"; -import { ToolMetadata } from "./types.js"; +import type { SubQuestion } from "./engines/query/types.js"; +import type { ChatMessage } from "./llm/types.js"; +import type { ToolMetadata } from "./types.js"; /** * A SimplePrompt is a function that takes a dictionary of inputs and returns a string. diff --git a/packages/core/src/PromptHelper.ts b/packages/core/src/PromptHelper.ts index ff11819d5..289e29835 100644 --- a/packages/core/src/PromptHelper.ts +++ b/packages/core/src/PromptHelper.ts @@ -1,5 +1,5 @@ import { globalsHelper } from "./GlobalsHelper.js"; -import { SimplePrompt } from "./Prompt.js"; +import type { SimplePrompt } from "./Prompt.js"; import { SentenceSplitter } from "./TextSplitter.js"; import { DEFAULT_CHUNK_OVERLAP_RATIO, diff --git a/packages/core/src/QuestionGenerator.ts b/packages/core/src/QuestionGenerator.ts index 1d1053967..4b36174e3 100644 --- a/packages/core/src/QuestionGenerator.ts +++ b/packages/core/src/QuestionGenerator.ts @@ -1,14 +1,18 @@ import { SubQuestionOutputParser } from "./OutputParser.js"; -import { - SubQuestionPrompt, - buildToolsText, - defaultSubQuestionPrompt, -} from "./Prompt.js"; -import { BaseQuestionGenerator, SubQuestion } from "./engines/query/types.js"; +import type { SubQuestionPrompt } from "./Prompt.js"; +import { buildToolsText, defaultSubQuestionPrompt } from "./Prompt.js"; +import type { + BaseQuestionGenerator, + SubQuestion, +} from "./engines/query/types.js"; import { OpenAI } from "./llm/LLM.js"; -import { LLM } from "./llm/types.js"; +import type { LLM } from "./llm/types.js"; import { PromptMixin } from "./prompts/index.js"; -import { BaseOutputParser, StructuredOutput, ToolMetadata } from "./types.js"; +import type { + BaseOutputParser, + StructuredOutput, + ToolMetadata, +} from "./types.js"; /** * LLMQuestionGenerator uses the LLM to generate new questions for the LLM using tools and a user query. diff --git a/packages/core/src/Response.ts b/packages/core/src/Response.ts index 3f6b9b633..be910b021 100644 --- a/packages/core/src/Response.ts +++ b/packages/core/src/Response.ts @@ -1,4 +1,4 @@ -import { BaseNode } from "./Node.js"; +import type { BaseNode } from "./Node.js"; /** * Response is the output of a LLM diff --git a/packages/core/src/Retriever.ts b/packages/core/src/Retriever.ts index f5ed6c15d..516108477 100644 --- a/packages/core/src/Retriever.ts +++ b/packages/core/src/Retriever.ts @@ -1,6 +1,6 @@ -import { Event } from "./callbacks/CallbackManager.js"; -import { NodeWithScore } from "./Node.js"; -import { ServiceContext } from "./ServiceContext.js"; +import type { Event } from "./callbacks/CallbackManager.js"; +import type { NodeWithScore } from "./Node.js"; +import type { ServiceContext } from "./ServiceContext.js"; /** * Retrievers retrieve the nodes that most closely match our query in similarity. diff --git a/packages/core/src/ServiceContext.ts b/packages/core/src/ServiceContext.ts index ba72d2f36..c31b52de1 100644 --- a/packages/core/src/ServiceContext.ts +++ b/packages/core/src/ServiceContext.ts @@ -1,10 +1,11 @@ import { PromptHelper } from "./PromptHelper.js"; import { CallbackManager } from "./callbacks/CallbackManager.js"; import { OpenAIEmbedding } from "./embeddings/OpenAIEmbedding.js"; -import { BaseEmbedding } from "./embeddings/types.js"; -import { LLM, OpenAI } from "./llm/index.js"; +import type { BaseEmbedding } from "./embeddings/types.js"; +import type { LLM } from "./llm/index.js"; +import { OpenAI } from "./llm/index.js"; import { SimpleNodeParser } from "./nodeParsers/SimpleNodeParser.js"; -import { NodeParser } from "./nodeParsers/types.js"; +import type { NodeParser } from "./nodeParsers/types.js"; /** * The ServiceContext is a collection of components that are used in different parts of the application. diff --git a/packages/core/src/agent/openai/base.ts b/packages/core/src/agent/openai/base.ts index a39a4fee7..ff29ed31e 100644 --- a/packages/core/src/agent/openai/base.ts +++ b/packages/core/src/agent/openai/base.ts @@ -1,7 +1,8 @@ -import { CallbackManager } from "../../callbacks/CallbackManager.js"; -import { ChatMessage, OpenAI } from "../../llm/index.js"; -import { ObjectRetriever } from "../../objects/base.js"; -import { BaseTool } from "../../types.js"; +import type { CallbackManager } from "../../callbacks/CallbackManager.js"; +import type { ChatMessage } from "../../llm/index.js"; +import { OpenAI } from "../../llm/index.js"; +import type { ObjectRetriever } from "../../objects/base.js"; +import type { BaseTool } from "../../types.js"; import { AgentRunner } from "../runner/base.js"; import { OpenAIAgentWorker } from "./worker.js"; diff --git a/packages/core/src/agent/openai/utils.ts b/packages/core/src/agent/openai/utils.ts index 4dd913f5b..5f291f44a 100644 --- a/packages/core/src/agent/openai/utils.ts +++ b/packages/core/src/agent/openai/utils.ts @@ -1,4 +1,4 @@ -import { ToolMetadata } from "../../types.js"; +import type { ToolMetadata } from "../../types.js"; export type OpenAIFunction = { type: "function"; diff --git a/packages/core/src/agent/openai/worker.ts b/packages/core/src/agent/openai/worker.ts index 401645ae7..84fd81bfa 100644 --- a/packages/core/src/agent/openai/worker.ts +++ b/packages/core/src/agent/openai/worker.ts @@ -1,25 +1,26 @@ // Assuming that the necessary interfaces and classes (like BaseTool, OpenAI, ChatMessage, CallbackManager, etc.) are defined elsewhere import { randomUUID } from "@llamaindex/env"; -import { CallbackManager } from "../../callbacks/CallbackManager.js"; +import type { CallbackManager } from "../../callbacks/CallbackManager.js"; import { AgentChatResponse, ChatResponseMode, } from "../../engines/chat/types.js"; -import { +import type { ChatMessage, ChatResponse, ChatResponseChunk, - OpenAI, } from "../../llm/index.js"; +import { OpenAI } from "../../llm/index.js"; import { ChatMemoryBuffer } from "../../memory/ChatMemoryBuffer.js"; -import { ObjectRetriever } from "../../objects/base.js"; -import { ToolOutput } from "../../tools/types.js"; +import type { ObjectRetriever } from "../../objects/base.js"; +import type { ToolOutput } from "../../tools/types.js"; import { callToolWithErrorHandling } from "../../tools/utils.js"; -import { BaseTool } from "../../types.js"; -import { AgentWorker, Task, TaskStep, TaskStepOutput } from "../types.js"; +import type { BaseTool } from "../../types.js"; +import type { AgentWorker, Task } from "../types.js"; +import { TaskStep, TaskStepOutput } from "../types.js"; import { addUserStepToMemory, getFunctionByName } from "../utils.js"; -import { OpenAIToolCall } from "./types/chat.js"; +import type { OpenAIToolCall } from "./types/chat.js"; import { toOpenAiTool } from "./utils.js"; const DEFAULT_MAX_FUNCTION_CALLS = 5; diff --git a/packages/core/src/agent/react/base.ts b/packages/core/src/agent/react/base.ts index fa97c3011..a975bf0c4 100644 --- a/packages/core/src/agent/react/base.ts +++ b/packages/core/src/agent/react/base.ts @@ -1,7 +1,7 @@ -import { CallbackManager } from "../../callbacks/CallbackManager.js"; -import { ChatMessage, LLM } from "../../llm/index.js"; -import { ObjectRetriever } from "../../objects/base.js"; -import { BaseTool } from "../../types.js"; +import type { CallbackManager } from "../../callbacks/CallbackManager.js"; +import type { ChatMessage, LLM } from "../../llm/index.js"; +import type { ObjectRetriever } from "../../objects/base.js"; +import type { BaseTool } from "../../types.js"; import { AgentRunner } from "../runner/base.js"; import { ReActAgentWorker } from "./worker.js"; diff --git a/packages/core/src/agent/react/formatter.ts b/packages/core/src/agent/react/formatter.ts index ce2744390..d2ed1e3c3 100644 --- a/packages/core/src/agent/react/formatter.ts +++ b/packages/core/src/agent/react/formatter.ts @@ -1,7 +1,8 @@ -import { ChatMessage } from "../../llm/index.js"; -import { BaseTool } from "../../types.js"; +import type { ChatMessage } from "../../llm/index.js"; +import type { BaseTool } from "../../types.js"; import { getReactChatSystemHeader } from "./prompts.js"; -import { BaseReasoningStep, ObservationReasoningStep } from "./types.js"; +import type { BaseReasoningStep } from "./types.js"; +import { ObservationReasoningStep } from "./types.js"; function getReactToolDescriptions(tools: BaseTool[]): string[] { const toolDescs: string[] = []; diff --git a/packages/core/src/agent/react/outputParser.ts b/packages/core/src/agent/react/outputParser.ts index d1c1d573f..593cdc187 100644 --- a/packages/core/src/agent/react/outputParser.ts +++ b/packages/core/src/agent/react/outputParser.ts @@ -1,7 +1,7 @@ +import type { BaseReasoningStep } from "./types.js"; import { ActionReasoningStep, BaseOutputParser, - BaseReasoningStep, ResponseReasoningStep, } from "./types.js"; diff --git a/packages/core/src/agent/react/types.ts b/packages/core/src/agent/react/types.ts index 660bc1c79..185ec378d 100644 --- a/packages/core/src/agent/react/types.ts +++ b/packages/core/src/agent/react/types.ts @@ -1,4 +1,4 @@ -import { ChatMessage } from "../../llm/index.js"; +import type { ChatMessage } from "../../llm/index.js"; export interface BaseReasoningStep { getContent(): string; diff --git a/packages/core/src/agent/react/worker.ts b/packages/core/src/agent/react/worker.ts index 1af501792..108bfe136 100644 --- a/packages/core/src/agent/react/worker.ts +++ b/packages/core/src/agent/react/worker.ts @@ -1,17 +1,19 @@ import { randomUUID } from "crypto"; import { CallbackManager } from "../../callbacks/CallbackManager.js"; import { AgentChatResponse } from "../../engines/chat/index.js"; -import { ChatResponse, LLM, OpenAI } from "../../llm/index.js"; +import type { ChatResponse, LLM } from "../../llm/index.js"; +import { OpenAI } from "../../llm/index.js"; import { ChatMemoryBuffer } from "../../memory/ChatMemoryBuffer.js"; -import { ObjectRetriever } from "../../objects/base.js"; +import type { ObjectRetriever } from "../../objects/base.js"; import { ToolOutput } from "../../tools/index.js"; -import { BaseTool } from "../../types.js"; -import { AgentWorker, Task, TaskStep, TaskStepOutput } from "../types.js"; +import type { BaseTool } from "../../types.js"; +import type { AgentWorker, Task } from "../types.js"; +import { TaskStep, TaskStepOutput } from "../types.js"; import { ReActChatFormatter } from "./formatter.js"; import { ReActOutputParser } from "./outputParser.js"; +import type { BaseReasoningStep } from "./types.js"; import { ActionReasoningStep, - BaseReasoningStep, ObservationReasoningStep, ResponseReasoningStep, } from "./types.js"; diff --git a/packages/core/src/agent/runner/base.ts b/packages/core/src/agent/runner/base.ts index 5a0764895..80dfd2f71 100644 --- a/packages/core/src/agent/runner/base.ts +++ b/packages/core/src/agent/runner/base.ts @@ -1,14 +1,15 @@ import { randomUUID } from "crypto"; import { CallbackManager } from "../../callbacks/CallbackManager.js"; +import type { ChatEngineAgentParams } from "../../engines/chat/index.js"; import { AgentChatResponse, - ChatEngineAgentParams, ChatResponseMode, } from "../../engines/chat/index.js"; -import { ChatMessage, LLM } from "../../llm/index.js"; +import type { ChatMessage, LLM } from "../../llm/index.js"; import { ChatMemoryBuffer } from "../../memory/ChatMemoryBuffer.js"; -import { BaseMemory } from "../../memory/types.js"; -import { AgentWorker, Task, TaskStep, TaskStepOutput } from "../types.js"; +import type { BaseMemory } from "../../memory/types.js"; +import type { AgentWorker, TaskStepOutput } from "../types.js"; +import { Task, TaskStep } from "../types.js"; import { AgentState, BaseAgentRunner, TaskState } from "./types.js"; const validateStepFromArgs = ( diff --git a/packages/core/src/agent/runner/types.ts b/packages/core/src/agent/runner/types.ts index 3def71e6a..9fc4c5a8b 100644 --- a/packages/core/src/agent/runner/types.ts +++ b/packages/core/src/agent/runner/types.ts @@ -1,5 +1,6 @@ -import { AgentChatResponse } from "../../engines/chat/index.js"; -import { BaseAgent, Task, TaskStep, TaskStepOutput } from "../types.js"; +import type { AgentChatResponse } from "../../engines/chat/index.js"; +import type { Task, TaskStep, TaskStepOutput } from "../types.js"; +import { BaseAgent } from "../types.js"; export class TaskState { task!: Task; diff --git a/packages/core/src/agent/types.ts b/packages/core/src/agent/types.ts index e82060c2e..f861a8488 100644 --- a/packages/core/src/agent/types.ts +++ b/packages/core/src/agent/types.ts @@ -1,8 +1,8 @@ -import { +import type { AgentChatResponse, ChatEngineAgentParams, } from "../engines/chat/index.js"; -import { QueryEngineParamsNonStreaming } from "../types.js"; +import type { QueryEngineParamsNonStreaming } from "../types.js"; export interface AgentWorker { initializeStep(task: Task, kwargs?: any): TaskStep; diff --git a/packages/core/src/agent/utils.ts b/packages/core/src/agent/utils.ts index d1953bf47..858306856 100644 --- a/packages/core/src/agent/utils.ts +++ b/packages/core/src/agent/utils.ts @@ -1,7 +1,7 @@ -import { ChatMessage } from "../llm/index.js"; -import { ChatMemoryBuffer } from "../memory/ChatMemoryBuffer.js"; -import { BaseTool } from "../types.js"; -import { TaskStep } from "./types.js"; +import type { ChatMessage } from "../llm/index.js"; +import type { ChatMemoryBuffer } from "../memory/ChatMemoryBuffer.js"; +import type { BaseTool } from "../types.js"; +import type { TaskStep } from "./types.js"; /** * Adds the user's input to the memory. diff --git a/packages/core/src/callbacks/CallbackManager.ts b/packages/core/src/callbacks/CallbackManager.ts index 038707bf0..a3334504a 100644 --- a/packages/core/src/callbacks/CallbackManager.ts +++ b/packages/core/src/callbacks/CallbackManager.ts @@ -1,5 +1,5 @@ import type { Anthropic } from "@anthropic-ai/sdk"; -import { NodeWithScore } from "../Node.js"; +import type { NodeWithScore } from "../Node.js"; /* An event is a wrapper that groups related operations. diff --git a/packages/core/src/cloud/LlamaCloudIndex.ts b/packages/core/src/cloud/LlamaCloudIndex.ts index ff433c157..8eb65dd41 100644 --- a/packages/core/src/cloud/LlamaCloudIndex.ts +++ b/packages/core/src/cloud/LlamaCloudIndex.ts @@ -1,10 +1,11 @@ -import { BaseRetriever } from "../Retriever.js"; +import type { BaseRetriever } from "../Retriever.js"; import { RetrieverQueryEngine } from "../engines/query/RetrieverQueryEngine.js"; -import { BaseNodePostprocessor } from "../postprocessors/types.js"; -import { BaseSynthesizer } from "../synthesizers/types.js"; -import { BaseQueryEngine } from "../types.js"; -import { LlamaCloudRetriever, RetrieveParams } from "./LlamaCloudRetriever.js"; -import { CloudConstructorParams } from "./types.js"; +import type { BaseNodePostprocessor } from "../postprocessors/types.js"; +import type { BaseSynthesizer } from "../synthesizers/types.js"; +import type { BaseQueryEngine } from "../types.js"; +import type { RetrieveParams } from "./LlamaCloudRetriever.js"; +import { LlamaCloudRetriever } from "./LlamaCloudRetriever.js"; +import type { CloudConstructorParams } from "./types.js"; export class LlamaCloudIndex { params: CloudConstructorParams; diff --git a/packages/core/src/cloud/LlamaCloudRetriever.ts b/packages/core/src/cloud/LlamaCloudRetriever.ts index c3e3613f9..7938a59c0 100644 --- a/packages/core/src/cloud/LlamaCloudRetriever.ts +++ b/packages/core/src/cloud/LlamaCloudRetriever.ts @@ -1,17 +1,13 @@ -import { PlatformApi, PlatformApiClient } from "@llamaindex/cloud"; +import type { PlatformApi, PlatformApiClient } from "@llamaindex/cloud"; import { globalsHelper } from "../GlobalsHelper.js"; -import { NodeWithScore, ObjectType, jsonToNode } from "../Node.js"; -import { BaseRetriever } from "../Retriever.js"; -import { - ServiceContext, - serviceContextFromDefaults, -} from "../ServiceContext.js"; -import { Event } from "../callbacks/CallbackManager.js"; -import { - ClientParams, - CloudConstructorParams, - DEFAULT_PROJECT_NAME, -} from "./types.js"; +import type { NodeWithScore } from "../Node.js"; +import { ObjectType, jsonToNode } from "../Node.js"; +import type { BaseRetriever } from "../Retriever.js"; +import type { ServiceContext } from "../ServiceContext.js"; +import { serviceContextFromDefaults } from "../ServiceContext.js"; +import type { Event } from "../callbacks/CallbackManager.js"; +import type { ClientParams, CloudConstructorParams } from "./types.js"; +import { DEFAULT_PROJECT_NAME } from "./types.js"; import { getClient } from "./utils.js"; export type RetrieveParams = Omit< diff --git a/packages/core/src/cloud/types.ts b/packages/core/src/cloud/types.ts index 3fc118344..a77ec3314 100644 --- a/packages/core/src/cloud/types.ts +++ b/packages/core/src/cloud/types.ts @@ -1,4 +1,4 @@ -import { ServiceContext } from "../ServiceContext.js"; +import type { ServiceContext } from "../ServiceContext.js"; export const DEFAULT_PROJECT_NAME = "default"; export const DEFAULT_BASE_URL = "https://api.cloud.llamaindex.ai"; diff --git a/packages/core/src/cloud/utils.ts b/packages/core/src/cloud/utils.ts index e6a7a1dc5..69a80861f 100644 --- a/packages/core/src/cloud/utils.ts +++ b/packages/core/src/cloud/utils.ts @@ -1,5 +1,6 @@ -import { PlatformApiClient } from "@llamaindex/cloud"; -import { ClientParams, DEFAULT_BASE_URL } from "./types.js"; +import type { PlatformApiClient } from "@llamaindex/cloud"; +import type { ClientParams } from "./types.js"; +import { DEFAULT_BASE_URL } from "./types.js"; export async function getClient({ apiKey, diff --git a/packages/core/src/embeddings/ClipEmbedding.ts b/packages/core/src/embeddings/ClipEmbedding.ts index 6658342cf..bc9a506bf 100644 --- a/packages/core/src/embeddings/ClipEmbedding.ts +++ b/packages/core/src/embeddings/ClipEmbedding.ts @@ -1,4 +1,4 @@ -import { ImageType } from "../Node.js"; +import type { ImageType } from "../Node.js"; import { MultiModalEmbedding } from "./MultiModalEmbedding.js"; import { readImage } from "./utils.js"; diff --git a/packages/core/src/embeddings/MultiModalEmbedding.ts b/packages/core/src/embeddings/MultiModalEmbedding.ts index df1958f6b..e2c7c1434 100644 --- a/packages/core/src/embeddings/MultiModalEmbedding.ts +++ b/packages/core/src/embeddings/MultiModalEmbedding.ts @@ -1,4 +1,4 @@ -import { ImageType } from "../Node.js"; +import type { ImageType } from "../Node.js"; import { BaseEmbedding } from "./types.js"; /* diff --git a/packages/core/src/embeddings/OllamaEmbedding.ts b/packages/core/src/embeddings/OllamaEmbedding.ts index a6c326ef6..5ce8f44c6 100644 --- a/packages/core/src/embeddings/OllamaEmbedding.ts +++ b/packages/core/src/embeddings/OllamaEmbedding.ts @@ -1,5 +1,5 @@ import { Ollama } from "../llm/ollama.js"; -import { BaseEmbedding } from "./types.js"; +import type { BaseEmbedding } from "./types.js"; /** * OllamaEmbedding is an alias for Ollama that implements the BaseEmbedding interface. diff --git a/packages/core/src/embeddings/OpenAIEmbedding.ts b/packages/core/src/embeddings/OpenAIEmbedding.ts index 5402111f9..e46de7c80 100644 --- a/packages/core/src/embeddings/OpenAIEmbedding.ts +++ b/packages/core/src/embeddings/OpenAIEmbedding.ts @@ -1,12 +1,13 @@ -import { ClientOptions as OpenAIClientOptions } from "openai"; +import type { ClientOptions as OpenAIClientOptions } from "openai"; +import type { AzureOpenAIConfig } from "../llm/azure.js"; import { - AzureOpenAIConfig, getAzureBaseUrl, getAzureConfigFromEnv, getAzureModel, shouldUseAzure, } from "../llm/azure.js"; -import { OpenAISession, getOpenAISession } from "../llm/open_ai.js"; +import type { OpenAISession } from "../llm/open_ai.js"; +import { getOpenAISession } from "../llm/open_ai.js"; import { BaseEmbedding } from "./types.js"; export const ALL_OPENAI_EMBEDDING_MODELS = { diff --git a/packages/core/src/embeddings/types.ts b/packages/core/src/embeddings/types.ts index c365dfa1c..9c5892bdb 100644 --- a/packages/core/src/embeddings/types.ts +++ b/packages/core/src/embeddings/types.ts @@ -1,5 +1,6 @@ -import { BaseNode, MetadataMode } from "../Node.js"; -import { TransformComponent } from "../ingestion/types.js"; +import type { BaseNode } from "../Node.js"; +import { MetadataMode } from "../Node.js"; +import type { TransformComponent } from "../ingestion/types.js"; import { SimilarityType, similarity } from "./utils.js"; const DEFAULT_EMBED_BATCH_SIZE = 10; diff --git a/packages/core/src/embeddings/utils.ts b/packages/core/src/embeddings/utils.ts index d69b5c3c1..5c42b83c8 100644 --- a/packages/core/src/embeddings/utils.ts +++ b/packages/core/src/embeddings/utils.ts @@ -1,6 +1,6 @@ import { defaultFS } from "@llamaindex/env"; import _ from "lodash"; -import { ImageType } from "../Node.js"; +import type { ImageType } from "../Node.js"; import { DEFAULT_SIMILARITY_TOP_K } from "../constants.js"; import { VectorStoreQueryMode } from "../storage/vectorStore/types.js"; @@ -171,13 +171,13 @@ export function getTopKMMREmbeddings( while (results.length < Math.min(similarityTopKCount, embeddingLength)) { results.push([score, highScoreId]); - embedMap.delete(highScoreId!); + embedMap.delete(highScoreId); const recentEmbeddingId = highScoreId; score = Number.NEGATIVE_INFINITY; for (const embedId of Array.from(embedMap.keys())) { const overlapWithRecent = similarityFn( embeddings[embedMap.get(embedId)!], - embeddings[fullEmbedMap.get(recentEmbeddingId!)!], + embeddings[fullEmbedMap.get(recentEmbeddingId)!], ); if ( threshold * embedSimilarity.get(embedId)! - diff --git a/packages/core/src/engines/chat/CondenseQuestionChatEngine.ts b/packages/core/src/engines/chat/CondenseQuestionChatEngine.ts index 22524203d..7baf58d73 100644 --- a/packages/core/src/engines/chat/CondenseQuestionChatEngine.ts +++ b/packages/core/src/engines/chat/CondenseQuestionChatEngine.ts @@ -1,19 +1,18 @@ -import { ChatHistory, getHistory } from "../../ChatHistory.js"; +import type { ChatHistory } from "../../ChatHistory.js"; +import { getHistory } from "../../ChatHistory.js"; +import type { CondenseQuestionPrompt } from "../../Prompt.js"; import { - CondenseQuestionPrompt, defaultCondenseQuestionPrompt, messagesToHistoryStr, } from "../../Prompt.js"; -import { Response } from "../../Response.js"; -import { - ServiceContext, - serviceContextFromDefaults, -} from "../../ServiceContext.js"; -import { ChatMessage, LLM } from "../../llm/index.js"; +import type { Response } from "../../Response.js"; +import type { ServiceContext } from "../../ServiceContext.js"; +import { serviceContextFromDefaults } from "../../ServiceContext.js"; +import type { ChatMessage, LLM } from "../../llm/index.js"; import { extractText, streamReducer } from "../../llm/utils.js"; import { PromptMixin } from "../../prompts/index.js"; -import { BaseQueryEngine } from "../../types.js"; -import { +import type { BaseQueryEngine } from "../../types.js"; +import type { ChatEngine, ChatEngineParamsNonStreaming, ChatEngineParamsStreaming, diff --git a/packages/core/src/engines/chat/ContextChatEngine.ts b/packages/core/src/engines/chat/ContextChatEngine.ts index 7d63c74d0..a7889ad49 100644 --- a/packages/core/src/engines/chat/ContextChatEngine.ts +++ b/packages/core/src/engines/chat/ContextChatEngine.ts @@ -1,25 +1,22 @@ import { randomUUID } from "@llamaindex/env"; -import { ChatHistory, getHistory } from "../../ChatHistory.js"; -import { ContextSystemPrompt } from "../../Prompt.js"; +import type { ChatHistory } from "../../ChatHistory.js"; +import { getHistory } from "../../ChatHistory.js"; +import type { ContextSystemPrompt } from "../../Prompt.js"; import { Response } from "../../Response.js"; -import { BaseRetriever } from "../../Retriever.js"; -import { Event } from "../../callbacks/CallbackManager.js"; -import { - ChatMessage, - ChatResponseChunk, - LLM, - OpenAI, -} from "../../llm/index.js"; -import { MessageContent } from "../../llm/types.js"; +import type { BaseRetriever } from "../../Retriever.js"; +import type { Event } from "../../callbacks/CallbackManager.js"; +import type { ChatMessage, ChatResponseChunk, LLM } from "../../llm/index.js"; +import { OpenAI } from "../../llm/index.js"; +import type { MessageContent } from "../../llm/types.js"; import { extractText, streamConverter, streamReducer, } from "../../llm/utils.js"; -import { BaseNodePostprocessor } from "../../postprocessors/index.js"; +import type { BaseNodePostprocessor } from "../../postprocessors/index.js"; import { PromptMixin } from "../../prompts/Mixin.js"; import { DefaultContextGenerator } from "./DefaultContextGenerator.js"; -import { +import type { ChatEngine, ChatEngineParamsNonStreaming, ChatEngineParamsStreaming, diff --git a/packages/core/src/engines/chat/DefaultContextGenerator.ts b/packages/core/src/engines/chat/DefaultContextGenerator.ts index 4c96c744c..7fbb6ab37 100644 --- a/packages/core/src/engines/chat/DefaultContextGenerator.ts +++ b/packages/core/src/engines/chat/DefaultContextGenerator.ts @@ -1,14 +1,12 @@ import { randomUUID } from "@llamaindex/env"; -import { NodeWithScore, TextNode } from "../../Node.js"; -import { - ContextSystemPrompt, - defaultContextSystemPrompt, -} from "../../Prompt.js"; -import { BaseRetriever } from "../../Retriever.js"; -import { Event } from "../../callbacks/CallbackManager.js"; -import { BaseNodePostprocessor } from "../../postprocessors/index.js"; +import type { NodeWithScore, TextNode } from "../../Node.js"; +import type { ContextSystemPrompt } from "../../Prompt.js"; +import { defaultContextSystemPrompt } from "../../Prompt.js"; +import type { BaseRetriever } from "../../Retriever.js"; +import type { Event } from "../../callbacks/CallbackManager.js"; +import type { BaseNodePostprocessor } from "../../postprocessors/index.js"; import { PromptMixin } from "../../prompts/index.js"; -import { Context, ContextGenerator } from "./types.js"; +import type { Context, ContextGenerator } from "./types.js"; export class DefaultContextGenerator extends PromptMixin diff --git a/packages/core/src/engines/chat/SimpleChatEngine.ts b/packages/core/src/engines/chat/SimpleChatEngine.ts index 16617331b..bd1c82f64 100644 --- a/packages/core/src/engines/chat/SimpleChatEngine.ts +++ b/packages/core/src/engines/chat/SimpleChatEngine.ts @@ -1,8 +1,10 @@ -import { ChatHistory, getHistory } from "../../ChatHistory.js"; +import type { ChatHistory } from "../../ChatHistory.js"; +import { getHistory } from "../../ChatHistory.js"; import { Response } from "../../Response.js"; -import { ChatResponseChunk, LLM, OpenAI } from "../../llm/index.js"; +import type { ChatResponseChunk, LLM } from "../../llm/index.js"; +import { OpenAI } from "../../llm/index.js"; import { streamConverter, streamReducer } from "../../llm/utils.js"; -import { +import type { ChatEngine, ChatEngineParamsNonStreaming, ChatEngineParamsStreaming, diff --git a/packages/core/src/engines/chat/types.ts b/packages/core/src/engines/chat/types.ts index 80140fb45..3a8478d0c 100644 --- a/packages/core/src/engines/chat/types.ts +++ b/packages/core/src/engines/chat/types.ts @@ -1,10 +1,10 @@ -import { ChatHistory } from "../../ChatHistory.js"; -import { BaseNode, NodeWithScore } from "../../Node.js"; -import { Response } from "../../Response.js"; -import { Event } from "../../callbacks/CallbackManager.js"; -import { ChatMessage } from "../../llm/index.js"; -import { MessageContent } from "../../llm/types.js"; -import { ToolOutput } from "../../tools/types.js"; +import type { ChatHistory } from "../../ChatHistory.js"; +import type { BaseNode, NodeWithScore } from "../../Node.js"; +import type { Response } from "../../Response.js"; +import type { Event } from "../../callbacks/CallbackManager.js"; +import type { ChatMessage } from "../../llm/index.js"; +import type { MessageContent } from "../../llm/types.js"; +import type { ToolOutput } from "../../tools/types.js"; /** * Represents the base parameters for ChatEngine. diff --git a/packages/core/src/engines/query/RetrieverQueryEngine.ts b/packages/core/src/engines/query/RetrieverQueryEngine.ts index cc6fa2591..a8adbe0ad 100644 --- a/packages/core/src/engines/query/RetrieverQueryEngine.ts +++ b/packages/core/src/engines/query/RetrieverQueryEngine.ts @@ -1,16 +1,14 @@ import { randomUUID } from "@llamaindex/env"; -import { NodeWithScore } from "../../Node.js"; -import { Response } from "../../Response.js"; -import { BaseRetriever } from "../../Retriever.js"; -import { ServiceContext } from "../../ServiceContext.js"; -import { Event } from "../../callbacks/CallbackManager.js"; -import { BaseNodePostprocessor } from "../../postprocessors/index.js"; +import type { NodeWithScore } from "../../Node.js"; +import type { Response } from "../../Response.js"; +import type { BaseRetriever } from "../../Retriever.js"; +import type { ServiceContext } from "../../ServiceContext.js"; +import type { Event } from "../../callbacks/CallbackManager.js"; +import type { BaseNodePostprocessor } from "../../postprocessors/index.js"; import { PromptMixin } from "../../prompts/Mixin.js"; -import { - BaseSynthesizer, - ResponseSynthesizer, -} from "../../synthesizers/index.js"; -import { +import type { BaseSynthesizer } from "../../synthesizers/index.js"; +import { ResponseSynthesizer } from "../../synthesizers/index.js"; +import type { BaseQueryEngine, QueryEngineParamsNonStreaming, QueryEngineParamsStreaming, diff --git a/packages/core/src/engines/query/RouterQueryEngine.ts b/packages/core/src/engines/query/RouterQueryEngine.ts index 7fa54accd..bfe24362b 100644 --- a/packages/core/src/engines/query/RouterQueryEngine.ts +++ b/packages/core/src/engines/query/RouterQueryEngine.ts @@ -1,13 +1,12 @@ -import { BaseNode } from "../../Node.js"; +import type { BaseNode } from "../../Node.js"; import { Response } from "../../Response.js"; -import { - ServiceContext, - serviceContextFromDefaults, -} from "../../ServiceContext.js"; +import type { ServiceContext } from "../../ServiceContext.js"; +import { serviceContextFromDefaults } from "../../ServiceContext.js"; import { PromptMixin } from "../../prompts/index.js"; -import { BaseSelector, LLMSingleSelector } from "../../selectors/index.js"; +import type { BaseSelector } from "../../selectors/index.js"; +import { LLMSingleSelector } from "../../selectors/index.js"; import { TreeSummarize } from "../../synthesizers/index.js"; -import { +import type { BaseQueryEngine, QueryBundle, QueryEngineParamsNonStreaming, diff --git a/packages/core/src/engines/query/SubQuestionQueryEngine.ts b/packages/core/src/engines/query/SubQuestionQueryEngine.ts index 6e60a1dbf..5d0333fe2 100644 --- a/packages/core/src/engines/query/SubQuestionQueryEngine.ts +++ b/packages/core/src/engines/query/SubQuestionQueryEngine.ts @@ -1,20 +1,19 @@ import { randomUUID } from "@llamaindex/env"; -import { NodeWithScore, TextNode } from "../../Node.js"; +import type { NodeWithScore } from "../../Node.js"; +import { TextNode } from "../../Node.js"; import { LLMQuestionGenerator } from "../../QuestionGenerator.js"; -import { Response } from "../../Response.js"; -import { - ServiceContext, - serviceContextFromDefaults, -} from "../../ServiceContext.js"; -import { Event } from "../../callbacks/CallbackManager.js"; +import type { Response } from "../../Response.js"; +import type { ServiceContext } from "../../ServiceContext.js"; +import { serviceContextFromDefaults } from "../../ServiceContext.js"; +import type { Event } from "../../callbacks/CallbackManager.js"; import { PromptMixin } from "../../prompts/Mixin.js"; +import type { BaseSynthesizer } from "../../synthesizers/index.js"; import { - BaseSynthesizer, CompactAndRefine, ResponseSynthesizer, } from "../../synthesizers/index.js"; -import { +import type { BaseQueryEngine, BaseTool, QueryEngineParamsNonStreaming, @@ -22,7 +21,7 @@ import { ToolMetadata, } from "../../types.js"; -import { BaseQuestionGenerator, SubQuestion } from "./types.js"; +import type { BaseQuestionGenerator, SubQuestion } from "./types.js"; /** * SubQuestionQueryEngine decomposes a question into subquestions and then diff --git a/packages/core/src/engines/query/types.ts b/packages/core/src/engines/query/types.ts index 0db0e3259..883846316 100644 --- a/packages/core/src/engines/query/types.ts +++ b/packages/core/src/engines/query/types.ts @@ -1,4 +1,4 @@ -import { ToolMetadata } from "../../types.js"; +import type { ToolMetadata } from "../../types.js"; /** * QuestionGenerators generate new questions for the LLM using tools and a user query. diff --git a/packages/core/src/extractors/MetadataExtractors.ts b/packages/core/src/extractors/MetadataExtractors.ts index b3db824dc..c6b9c8731 100644 --- a/packages/core/src/extractors/MetadataExtractors.ts +++ b/packages/core/src/extractors/MetadataExtractors.ts @@ -1,5 +1,7 @@ -import { BaseNode, MetadataMode, TextNode } from "../Node.js"; -import { LLM, OpenAI } from "../llm/index.js"; +import type { BaseNode } from "../Node.js"; +import { MetadataMode, TextNode } from "../Node.js"; +import type { LLM } from "../llm/index.js"; +import { OpenAI } from "../llm/index.js"; import { defaultKeywordExtractorPromptTemplate, defaultQuestionAnswerPromptTemplate, diff --git a/packages/core/src/extractors/types.ts b/packages/core/src/extractors/types.ts index 58f3da987..259e574ce 100644 --- a/packages/core/src/extractors/types.ts +++ b/packages/core/src/extractors/types.ts @@ -1,5 +1,6 @@ -import { BaseNode, MetadataMode, TextNode } from "../Node.js"; -import { TransformComponent } from "../ingestion/types.js"; +import type { BaseNode } from "../Node.js"; +import { MetadataMode, TextNode } from "../Node.js"; +import type { TransformComponent } from "../ingestion/types.js"; import { defaultNodeTextTemplate } from "./prompts.js"; /* diff --git a/packages/core/src/indices/BaseIndex.ts b/packages/core/src/indices/BaseIndex.ts index cf0083e06..028b3bfaa 100644 --- a/packages/core/src/indices/BaseIndex.ts +++ b/packages/core/src/indices/BaseIndex.ts @@ -1,13 +1,13 @@ -import { BaseNode, Document } from "../Node.js"; -import { BaseRetriever } from "../Retriever.js"; -import { ServiceContext } from "../ServiceContext.js"; +import type { BaseNode, Document } from "../Node.js"; +import type { BaseRetriever } from "../Retriever.js"; +import type { ServiceContext } from "../ServiceContext.js"; import { runTransformations } from "../ingestion/IngestionPipeline.js"; -import { StorageContext } from "../storage/StorageContext.js"; -import { BaseDocumentStore } from "../storage/docStore/types.js"; -import { BaseIndexStore } from "../storage/indexStore/types.js"; -import { VectorStore } from "../storage/vectorStore/types.js"; -import { BaseSynthesizer } from "../synthesizers/types.js"; -import { BaseQueryEngine } from "../types.js"; +import type { StorageContext } from "../storage/StorageContext.js"; +import type { BaseDocumentStore } from "../storage/docStore/types.js"; +import type { BaseIndexStore } from "../storage/indexStore/types.js"; +import type { VectorStore } from "../storage/vectorStore/types.js"; +import type { BaseSynthesizer } from "../synthesizers/types.js"; +import type { BaseQueryEngine } from "../types.js"; import { IndexStruct } from "./IndexStruct.js"; import { IndexStructType } from "./json-to-index-struct.js"; diff --git a/packages/core/src/indices/json-to-index-struct.ts b/packages/core/src/indices/json-to-index-struct.ts index ebe72174e..b62ec851b 100644 --- a/packages/core/src/indices/json-to-index-struct.ts +++ b/packages/core/src/indices/json-to-index-struct.ts @@ -1,4 +1,5 @@ -import { BaseNode, jsonToNode } from "../Node.js"; +import type { BaseNode } from "../Node.js"; +import { jsonToNode } from "../Node.js"; import { IndexStruct } from "./IndexStruct.js"; export enum IndexStructType { diff --git a/packages/core/src/indices/keyword/index.ts b/packages/core/src/indices/keyword/index.ts index 3fee6040a..56019c0c7 100644 --- a/packages/core/src/indices/keyword/index.ts +++ b/packages/core/src/indices/keyword/index.ts @@ -1,25 +1,24 @@ -import { BaseNode, Document, MetadataMode, NodeWithScore } from "../../Node.js"; -import { +import type { BaseNode, Document, NodeWithScore } from "../../Node.js"; +import { MetadataMode } from "../../Node.js"; +import type { KeywordExtractPrompt, QueryKeywordExtractPrompt, +} from "../../Prompt.js"; +import { defaultKeywordExtractPrompt, defaultQueryKeywordExtractPrompt, } from "../../Prompt.js"; -import { BaseRetriever } from "../../Retriever.js"; -import { - ServiceContext, - serviceContextFromDefaults, -} from "../../ServiceContext.js"; +import type { BaseRetriever } from "../../Retriever.js"; +import type { ServiceContext } from "../../ServiceContext.js"; +import { serviceContextFromDefaults } from "../../ServiceContext.js"; import { RetrieverQueryEngine } from "../../engines/query/index.js"; -import { BaseNodePostprocessor } from "../../postprocessors/index.js"; -import { - BaseDocumentStore, - StorageContext, - storageContextFromDefaults, -} from "../../storage/index.js"; -import { BaseSynthesizer } from "../../synthesizers/index.js"; -import { BaseQueryEngine } from "../../types.js"; -import { BaseIndex, BaseIndexInit, KeywordTable } from "../BaseIndex.js"; +import type { BaseNodePostprocessor } from "../../postprocessors/index.js"; +import type { BaseDocumentStore, StorageContext } from "../../storage/index.js"; +import { storageContextFromDefaults } from "../../storage/index.js"; +import type { BaseSynthesizer } from "../../synthesizers/index.js"; +import type { BaseQueryEngine } from "../../types.js"; +import type { BaseIndexInit } from "../BaseIndex.js"; +import { BaseIndex, KeywordTable } from "../BaseIndex.js"; import { IndexStructType } from "../json-to-index-struct.js"; import { extractKeywordsGivenResponse, diff --git a/packages/core/src/indices/summary/index.ts b/packages/core/src/indices/summary/index.ts index cafa1a2c6..59d10ae4c 100644 --- a/packages/core/src/indices/summary/index.ts +++ b/packages/core/src/indices/summary/index.ts @@ -1,32 +1,34 @@ import _ from "lodash"; import { globalsHelper } from "../../GlobalsHelper.js"; -import { BaseNode, Document, NodeWithScore } from "../../Node.js"; -import { ChoiceSelectPrompt, defaultChoiceSelectPrompt } from "../../Prompt.js"; -import { BaseRetriever } from "../../Retriever.js"; -import { - ServiceContext, - serviceContextFromDefaults, -} from "../../ServiceContext.js"; -import { Event } from "../../callbacks/CallbackManager.js"; +import type { BaseNode, Document, NodeWithScore } from "../../Node.js"; +import type { ChoiceSelectPrompt } from "../../Prompt.js"; +import { defaultChoiceSelectPrompt } from "../../Prompt.js"; +import type { BaseRetriever } from "../../Retriever.js"; +import type { ServiceContext } from "../../ServiceContext.js"; +import { serviceContextFromDefaults } from "../../ServiceContext.js"; +import type { Event } from "../../callbacks/CallbackManager.js"; import { RetrieverQueryEngine } from "../../engines/query/index.js"; -import { BaseNodePostprocessor } from "../../postprocessors/index.js"; -import { +import type { BaseNodePostprocessor } from "../../postprocessors/index.js"; +import type { BaseDocumentStore, RefDocInfo, StorageContext, - storageContextFromDefaults, } from "../../storage/index.js"; +import { storageContextFromDefaults } from "../../storage/index.js"; +import type { BaseSynthesizer } from "../../synthesizers/index.js"; import { - BaseSynthesizer, CompactAndRefine, ResponseSynthesizer, } from "../../synthesizers/index.js"; -import { BaseQueryEngine } from "../../types.js"; -import { BaseIndex, BaseIndexInit } from "../BaseIndex.js"; +import type { BaseQueryEngine } from "../../types.js"; +import type { BaseIndexInit } from "../BaseIndex.js"; +import { BaseIndex } from "../BaseIndex.js"; import { IndexList, IndexStructType } from "../json-to-index-struct.js"; -import { +import type { ChoiceSelectParserFunction, NodeFormatterFunction, +} from "./utils.js"; +import { defaultFormatNodeBatchFn, defaultParseChoiceSelectAnswerFn, } from "./utils.js"; diff --git a/packages/core/src/indices/summary/utils.ts b/packages/core/src/indices/summary/utils.ts index 7805b991f..bb995cc6c 100644 --- a/packages/core/src/indices/summary/utils.ts +++ b/packages/core/src/indices/summary/utils.ts @@ -1,5 +1,6 @@ import _ from "lodash"; -import { BaseNode, MetadataMode } from "../../Node.js"; +import type { BaseNode } from "../../Node.js"; +import { MetadataMode } from "../../Node.js"; export type NodeFormatterFunction = (summaryNodes: BaseNode[]) => string; export const defaultFormatNodeBatchFn: NodeFormatterFunction = ( diff --git a/packages/core/src/indices/vectorStore/index.ts b/packages/core/src/indices/vectorStore/index.ts index fd199c5f3..199b07d91 100644 --- a/packages/core/src/indices/vectorStore/index.ts +++ b/packages/core/src/indices/vectorStore/index.ts @@ -1,42 +1,45 @@ import { globalsHelper } from "../../GlobalsHelper.js"; -import { +import type { BaseNode, Document, - ImageNode, Metadata, - MetadataMode, NodeWithScore, +} from "../../Node.js"; +import { + ImageNode, + MetadataMode, ObjectType, splitNodesByType, } from "../../Node.js"; -import { BaseRetriever } from "../../Retriever.js"; -import { - ServiceContext, - serviceContextFromDefaults, -} from "../../ServiceContext.js"; -import { Event } from "../../callbacks/CallbackManager.js"; +import type { BaseRetriever } from "../../Retriever.js"; +import type { ServiceContext } from "../../ServiceContext.js"; +import { serviceContextFromDefaults } from "../../ServiceContext.js"; +import type { Event } from "../../callbacks/CallbackManager.js"; import { DEFAULT_SIMILARITY_TOP_K } from "../../constants.js"; -import { +import type { BaseEmbedding, - ClipEmbedding, MultiModalEmbedding, } from "../../embeddings/index.js"; +import { ClipEmbedding } from "../../embeddings/index.js"; import { RetrieverQueryEngine } from "../../engines/query/RetrieverQueryEngine.js"; import { runTransformations } from "../../ingestion/index.js"; -import { BaseNodePostprocessor } from "../../postprocessors/types.js"; -import { +import type { BaseNodePostprocessor } from "../../postprocessors/types.js"; +import type { BaseIndexStore, MetadataFilters, StorageContext, VectorStore, VectorStoreQuery, - VectorStoreQueryMode, VectorStoreQueryResult, +} from "../../storage/index.js"; +import { + VectorStoreQueryMode, storageContextFromDefaults, } from "../../storage/index.js"; -import { BaseSynthesizer } from "../../synthesizers/types.js"; -import { BaseQueryEngine } from "../../types.js"; -import { BaseIndex, BaseIndexInit } from "../BaseIndex.js"; +import type { BaseSynthesizer } from "../../synthesizers/types.js"; +import type { BaseQueryEngine } from "../../types.js"; +import type { BaseIndexInit } from "../BaseIndex.js"; +import { BaseIndex } from "../BaseIndex.js"; import { IndexDict, IndexStructType } from "../json-to-index-struct.js"; interface IndexStructOptions { @@ -189,15 +192,12 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> { ) { // Check if the index already has nodes with the same hash const newNodes = nodes.filter((node) => - Object.entries(this.indexStruct!.nodesDict).reduce( - (acc, [key, value]) => { - if (value.hash === node.hash) { - acc = false; - } - return acc; - }, - true, - ), + Object.entries(this.indexStruct.nodesDict).reduce((acc, [key, value]) => { + if (value.hash === node.hash) { + acc = false; + } + return acc; + }, true), ); await this.insertNodes(newNodes, options); diff --git a/packages/core/src/ingestion/IngestionCache.ts b/packages/core/src/ingestion/IngestionCache.ts index e60d4bdff..115ba3902 100644 --- a/packages/core/src/ingestion/IngestionCache.ts +++ b/packages/core/src/ingestion/IngestionCache.ts @@ -1,9 +1,10 @@ import { createSHA256 } from "@llamaindex/env"; -import { BaseNode, MetadataMode } from "../Node.js"; +import type { BaseNode } from "../Node.js"; +import { MetadataMode } from "../Node.js"; import { docToJson, jsonToDoc } from "../storage/docStore/utils.js"; import { SimpleKVStore } from "../storage/kvStore/SimpleKVStore.js"; -import { BaseKVStore } from "../storage/kvStore/types.js"; -import { TransformComponent } from "./types.js"; +import type { BaseKVStore } from "../storage/kvStore/types.js"; +import type { TransformComponent } from "./types.js"; const transformToJSON = (obj: TransformComponent) => { const seen: any[] = []; diff --git a/packages/core/src/ingestion/IngestionPipeline.ts b/packages/core/src/ingestion/IngestionPipeline.ts index 4f846cdb3..eceeef63b 100644 --- a/packages/core/src/ingestion/IngestionPipeline.ts +++ b/packages/core/src/ingestion/IngestionPipeline.ts @@ -1,13 +1,13 @@ -import { BaseNode, Document } from "../Node.js"; -import { BaseReader } from "../readers/type.js"; -import { BaseDocumentStore } from "../storage/docStore/types.js"; -import { VectorStore } from "../storage/vectorStore/types.js"; +import type { BaseNode, Document } from "../Node.js"; +import type { BaseReader } from "../readers/type.js"; +import type { BaseDocumentStore } from "../storage/docStore/types.js"; +import type { VectorStore } from "../storage/vectorStore/types.js"; import { IngestionCache, getTransformationHash } from "./IngestionCache.js"; import { DocStoreStrategy, createDocStoreStrategy, } from "./strategies/index.js"; -import { TransformComponent } from "./types.js"; +import type { TransformComponent } from "./types.js"; type IngestionRunArgs = { documents?: Document[]; diff --git a/packages/core/src/ingestion/strategies/DuplicatesStrategy.ts b/packages/core/src/ingestion/strategies/DuplicatesStrategy.ts index 301d7f371..096b27c19 100644 --- a/packages/core/src/ingestion/strategies/DuplicatesStrategy.ts +++ b/packages/core/src/ingestion/strategies/DuplicatesStrategy.ts @@ -1,6 +1,6 @@ -import { BaseNode } from "../../Node.js"; -import { BaseDocumentStore } from "../../storage/docStore/types.js"; -import { TransformComponent } from "../types.js"; +import type { BaseNode } from "../../Node.js"; +import type { BaseDocumentStore } from "../../storage/docStore/types.js"; +import type { TransformComponent } from "../types.js"; /** * Handle doc store duplicates by checking all hashes. diff --git a/packages/core/src/ingestion/strategies/UpsertsAndDeleteStrategy.ts b/packages/core/src/ingestion/strategies/UpsertsAndDeleteStrategy.ts index d17b32e14..2b615a35e 100644 --- a/packages/core/src/ingestion/strategies/UpsertsAndDeleteStrategy.ts +++ b/packages/core/src/ingestion/strategies/UpsertsAndDeleteStrategy.ts @@ -1,5 +1,5 @@ -import { BaseNode } from "../../Node.js"; -import { BaseDocumentStore, VectorStore } from "../../storage/index.js"; +import type { BaseNode } from "../../Node.js"; +import type { BaseDocumentStore, VectorStore } from "../../storage/index.js"; import { classify } from "./classify.js"; /** diff --git a/packages/core/src/ingestion/strategies/UpsertsStrategy.ts b/packages/core/src/ingestion/strategies/UpsertsStrategy.ts index a89ee63b9..1a4eeca7f 100644 --- a/packages/core/src/ingestion/strategies/UpsertsStrategy.ts +++ b/packages/core/src/ingestion/strategies/UpsertsStrategy.ts @@ -1,7 +1,7 @@ -import { BaseNode } from "../../Node.js"; -import { BaseDocumentStore } from "../../storage/docStore/types.js"; -import { VectorStore } from "../../storage/vectorStore/types.js"; -import { TransformComponent } from "../types.js"; +import type { BaseNode } from "../../Node.js"; +import type { BaseDocumentStore } from "../../storage/docStore/types.js"; +import type { VectorStore } from "../../storage/vectorStore/types.js"; +import type { TransformComponent } from "../types.js"; import { classify } from "./classify.js"; /** diff --git a/packages/core/src/ingestion/strategies/classify.ts b/packages/core/src/ingestion/strategies/classify.ts index 7ed5d260e..13fa24a04 100644 --- a/packages/core/src/ingestion/strategies/classify.ts +++ b/packages/core/src/ingestion/strategies/classify.ts @@ -1,5 +1,5 @@ -import { BaseNode } from "../../Node.js"; -import { BaseDocumentStore } from "../../storage/docStore/types.js"; +import type { BaseNode } from "../../Node.js"; +import type { BaseDocumentStore } from "../../storage/docStore/types.js"; export async function classify(docStore: BaseDocumentStore, nodes: BaseNode[]) { const existingDocIds = Object.values(await docStore.getAllDocumentHashes()); diff --git a/packages/core/src/ingestion/strategies/index.ts b/packages/core/src/ingestion/strategies/index.ts index 3c2f01a5a..0248169fd 100644 --- a/packages/core/src/ingestion/strategies/index.ts +++ b/packages/core/src/ingestion/strategies/index.ts @@ -1,6 +1,6 @@ -import { BaseDocumentStore } from "../../storage/docStore/types.js"; -import { VectorStore } from "../../storage/vectorStore/types.js"; -import { TransformComponent } from "../types.js"; +import type { BaseDocumentStore } from "../../storage/docStore/types.js"; +import type { VectorStore } from "../../storage/vectorStore/types.js"; +import type { TransformComponent } from "../types.js"; import { DuplicatesStrategy } from "./DuplicatesStrategy.js"; import { UpsertsStrategy } from "./UpsertsStrategy.js"; diff --git a/packages/core/src/ingestion/types.ts b/packages/core/src/ingestion/types.ts index 6c6f40f5c..138e111b1 100644 --- a/packages/core/src/ingestion/types.ts +++ b/packages/core/src/ingestion/types.ts @@ -1,4 +1,4 @@ -import { BaseNode } from "../Node.js"; +import type { BaseNode } from "../Node.js"; export interface TransformComponent { transform(nodes: BaseNode[], options?: any): Promise<BaseNode[]>; diff --git a/packages/core/src/llm/LLM.ts b/packages/core/src/llm/LLM.ts index 0b3f06a99..317fcc1a3 100644 --- a/packages/core/src/llm/LLM.ts +++ b/packages/core/src/llm/LLM.ts @@ -1,5 +1,6 @@ -import OpenAILLM, { ClientOptions as OpenAIClientOptions } from "openai"; -import { +import type OpenAILLM from "openai"; +import type { ClientOptions as OpenAIClientOptions } from "openai"; +import type { AnthropicStreamToken, CallbackManager, Event, @@ -8,27 +9,29 @@ import { StreamCallbackResponse, } from "../callbacks/CallbackManager.js"; -import { ChatCompletionMessageParam } from "openai/resources/index.js"; -import { LLMOptions } from "portkey-ai"; +import type { ChatCompletionMessageParam } from "openai/resources/index.js"; +import type { LLMOptions } from "portkey-ai"; import { Tokenizers, globalsHelper } from "../GlobalsHelper.js"; +import type { AnthropicSession } from "./anthropic.js"; import { ANTHROPIC_AI_PROMPT, ANTHROPIC_HUMAN_PROMPT, - AnthropicSession, getAnthropicSession, } from "./anthropic.js"; +import type { AzureOpenAIConfig } from "./azure.js"; import { - AzureOpenAIConfig, getAzureBaseUrl, getAzureConfigFromEnv, getAzureModel, shouldUseAzure, } from "./azure.js"; import { BaseLLM } from "./base.js"; -import { OpenAISession, getOpenAISession } from "./open_ai.js"; -import { PortkeySession, getPortkeySession } from "./portkey.js"; +import type { OpenAISession } from "./open_ai.js"; +import { getOpenAISession } from "./open_ai.js"; +import type { PortkeySession } from "./portkey.js"; +import { getPortkeySession } from "./portkey.js"; import { ReplicateSession } from "./replicate_ai.js"; -import { +import type { ChatMessage, ChatResponse, ChatResponseChunk, @@ -313,7 +316,7 @@ export class OpenAI extends BaseLLM { // TODO: add callback to streamConverter and use streamConverter here //Indices - var idx_counter: number = 0; + let idx_counter: number = 0; for await (const part of chunk_stream) { if (!part.choices.length) continue; @@ -732,7 +735,7 @@ export class Anthropic extends BaseLLM { stream: true, }); - var idx_counter: number = 0; + let idx_counter: number = 0; for await (const part of stream) { //TODO: LLM Stream Callback, pending re-work. @@ -821,7 +824,7 @@ export class Portkey extends BaseLLM { }; //Indices - var idx_counter: number = 0; + let idx_counter: number = 0; for await (const part of chunkStream) { //Increment part.choices[0].index = idx_counter; diff --git a/packages/core/src/llm/anthropic.ts b/packages/core/src/llm/anthropic.ts index 1a3dd0b48..a8dd6c114 100644 --- a/packages/core/src/llm/anthropic.ts +++ b/packages/core/src/llm/anthropic.ts @@ -1,8 +1,5 @@ -import Anthropic, { - AI_PROMPT, - ClientOptions, - HUMAN_PROMPT, -} from "@anthropic-ai/sdk"; +import type { ClientOptions } from "@anthropic-ai/sdk"; +import Anthropic, { AI_PROMPT, HUMAN_PROMPT } from "@anthropic-ai/sdk"; import _ from "lodash"; export class AnthropicSession { diff --git a/packages/core/src/llm/base.ts b/packages/core/src/llm/base.ts index 088b6ae82..36b62b6c7 100644 --- a/packages/core/src/llm/base.ts +++ b/packages/core/src/llm/base.ts @@ -1,4 +1,4 @@ -import { +import type { ChatMessage, ChatResponse, ChatResponseChunk, diff --git a/packages/core/src/llm/mistral.ts b/packages/core/src/llm/mistral.ts index c4aa37368..47478ca5b 100644 --- a/packages/core/src/llm/mistral.ts +++ b/packages/core/src/llm/mistral.ts @@ -1,11 +1,11 @@ -import { +import type { CallbackManager, Event, EventType, StreamCallbackResponse, } from "../callbacks/CallbackManager.js"; import { BaseLLM } from "./base.js"; -import { +import type { ChatMessage, ChatResponse, ChatResponseChunk, @@ -141,7 +141,7 @@ export class MistralAI extends BaseLLM { }; //Indices - var idx_counter: number = 0; + let idx_counter: number = 0; for await (const part of chunkStream) { if (!part.choices.length) continue; diff --git a/packages/core/src/llm/ollama.ts b/packages/core/src/llm/ollama.ts index 070320932..4ddcdf911 100644 --- a/packages/core/src/llm/ollama.ts +++ b/packages/core/src/llm/ollama.ts @@ -1,7 +1,7 @@ import { ok } from "@llamaindex/env"; -import { CallbackManager, Event } from "../callbacks/CallbackManager.js"; +import type { CallbackManager, Event } from "../callbacks/CallbackManager.js"; import { BaseEmbedding } from "../embeddings/types.js"; -import { +import type { ChatMessage, ChatResponse, ChatResponseChunk, diff --git a/packages/core/src/llm/open_ai.ts b/packages/core/src/llm/open_ai.ts index e36f05f3a..9deaffbde 100644 --- a/packages/core/src/llm/open_ai.ts +++ b/packages/core/src/llm/open_ai.ts @@ -1,5 +1,6 @@ import _ from "lodash"; -import OpenAI, { ClientOptions } from "openai"; +import type { ClientOptions } from "openai"; +import OpenAI from "openai"; export class AzureOpenAI extends OpenAI { protected override authHeaders() { diff --git a/packages/core/src/llm/portkey.ts b/packages/core/src/llm/portkey.ts index 11eb401b3..9d47e979e 100644 --- a/packages/core/src/llm/portkey.ts +++ b/packages/core/src/llm/portkey.ts @@ -1,5 +1,6 @@ import _ from "lodash"; -import { LLMOptions, Portkey } from "portkey-ai"; +import type { LLMOptions } from "portkey-ai"; +import { Portkey } from "portkey-ai"; export const readEnv = ( env: string, diff --git a/packages/core/src/llm/types.ts b/packages/core/src/llm/types.ts index f5bfa5669..ffcc7713f 100644 --- a/packages/core/src/llm/types.ts +++ b/packages/core/src/llm/types.ts @@ -1,5 +1,5 @@ -import { Tokenizers } from "../GlobalsHelper.js"; -import { Event } from "../callbacks/CallbackManager.js"; +import type { Tokenizers } from "../GlobalsHelper.js"; +import type { Event } from "../callbacks/CallbackManager.js"; /** * Unified language model interface diff --git a/packages/core/src/llm/utils.ts b/packages/core/src/llm/utils.ts index b6c986990..6e559c59c 100644 --- a/packages/core/src/llm/utils.ts +++ b/packages/core/src/llm/utils.ts @@ -1,4 +1,4 @@ -import { MessageContent, MessageContentDetail } from "./types.js"; +import type { MessageContent } from "./types.js"; export async function* streamConverter<S, D>( stream: AsyncIterable<S>, @@ -35,7 +35,7 @@ export function extractText(message: MessageContent): string { if (Array.isArray(message)) { // message is of type MessageContentDetail[] - retrieve just the text parts and concatenate them // so we can pass them to the context generator - return (message as MessageContentDetail[]) + return message .filter((c) => c.type === "text") .map((c) => c.text) .join("\n\n"); diff --git a/packages/core/src/memory/ChatMemoryBuffer.ts b/packages/core/src/memory/ChatMemoryBuffer.ts index 32cae371e..43c216116 100644 --- a/packages/core/src/memory/ChatMemoryBuffer.ts +++ b/packages/core/src/memory/ChatMemoryBuffer.ts @@ -1,7 +1,7 @@ -import { ChatMessage } from "../llm/index.js"; +import type { ChatMessage } from "../llm/index.js"; import { SimpleChatStore } from "../storage/chatStore/SimpleChatStore.js"; -import { BaseChatStore } from "../storage/chatStore/types.js"; -import { BaseMemory } from "./types.js"; +import type { BaseChatStore } from "../storage/chatStore/types.js"; +import type { BaseMemory } from "./types.js"; type ChatMemoryBufferParams = { tokenLimit?: number; diff --git a/packages/core/src/memory/types.ts b/packages/core/src/memory/types.ts index 93d38496d..c000e734d 100644 --- a/packages/core/src/memory/types.ts +++ b/packages/core/src/memory/types.ts @@ -1,4 +1,4 @@ -import { ChatMessage } from "../llm/index.js"; +import type { ChatMessage } from "../llm/index.js"; export interface BaseMemory { /* diff --git a/packages/core/src/nodeParsers/MarkdownNodeParser.ts b/packages/core/src/nodeParsers/MarkdownNodeParser.ts index a6fbb2f77..2c769c982 100644 --- a/packages/core/src/nodeParsers/MarkdownNodeParser.ts +++ b/packages/core/src/nodeParsers/MarkdownNodeParser.ts @@ -1,5 +1,6 @@ -import { BaseNode, Metadata, MetadataMode, TextNode } from "../Node.js"; -import { NodeParser } from "./types.js"; +import type { BaseNode, Metadata } from "../Node.js"; +import { MetadataMode, TextNode } from "../Node.js"; +import type { NodeParser } from "./types.js"; export class MarkdownNodeParser implements NodeParser { includeMetadata: boolean; diff --git a/packages/core/src/nodeParsers/SentenceWindowNodeParser.ts b/packages/core/src/nodeParsers/SentenceWindowNodeParser.ts index ac7009a19..1a6ef820f 100644 --- a/packages/core/src/nodeParsers/SentenceWindowNodeParser.ts +++ b/packages/core/src/nodeParsers/SentenceWindowNodeParser.ts @@ -1,6 +1,6 @@ -import { BaseNode } from "../Node.js"; +import type { BaseNode } from "../Node.js"; import { SentenceSplitter } from "../TextSplitter.js"; -import { NodeParser } from "./types.js"; +import type { NodeParser } from "./types.js"; import { getNodesFromDocument } from "./utils.js"; export const DEFAULT_WINDOW_SIZE = 3; diff --git a/packages/core/src/nodeParsers/SimpleNodeParser.ts b/packages/core/src/nodeParsers/SimpleNodeParser.ts index 8418c4e87..4fd7240e5 100644 --- a/packages/core/src/nodeParsers/SimpleNodeParser.ts +++ b/packages/core/src/nodeParsers/SimpleNodeParser.ts @@ -1,7 +1,7 @@ -import { BaseNode } from "../Node.js"; +import type { BaseNode } from "../Node.js"; import { SentenceSplitter } from "../TextSplitter.js"; import { DEFAULT_CHUNK_OVERLAP, DEFAULT_CHUNK_SIZE } from "../constants.js"; -import { NodeParser } from "./types.js"; +import type { NodeParser } from "./types.js"; import { getNodesFromDocument } from "./utils.js"; /** diff --git a/packages/core/src/nodeParsers/types.ts b/packages/core/src/nodeParsers/types.ts index ef894f563..7673c3379 100644 --- a/packages/core/src/nodeParsers/types.ts +++ b/packages/core/src/nodeParsers/types.ts @@ -1,5 +1,5 @@ -import { BaseNode } from "../Node.js"; -import { TransformComponent } from "../ingestion/types.js"; +import type { BaseNode } from "../Node.js"; +import type { TransformComponent } from "../ingestion/types.js"; /** * A NodeParser generates Nodes from Documents diff --git a/packages/core/src/nodeParsers/utils.ts b/packages/core/src/nodeParsers/utils.ts index 235401ea4..5f0bcf6ca 100644 --- a/packages/core/src/nodeParsers/utils.ts +++ b/packages/core/src/nodeParsers/utils.ts @@ -1,6 +1,6 @@ import _ from "lodash"; +import type { BaseNode } from "../Node.js"; import { - BaseNode, Document, ImageDocument, NodeRelationship, diff --git a/packages/core/src/objects/base.ts b/packages/core/src/objects/base.ts index 44088ca62..f03d85843 100644 --- a/packages/core/src/objects/base.ts +++ b/packages/core/src/objects/base.ts @@ -1,7 +1,8 @@ -import { BaseNode, Metadata, TextNode } from "../Node.js"; -import { BaseRetriever } from "../Retriever.js"; -import { VectorStoreIndex } from "../indices/index.js"; -import { BaseTool } from "../types.js"; +import type { BaseNode, Metadata } from "../Node.js"; +import { TextNode } from "../Node.js"; +import type { BaseRetriever } from "../Retriever.js"; +import type { VectorStoreIndex } from "../indices/index.js"; +import type { BaseTool } from "../types.js"; // Assuming that necessary interfaces and classes (like OT, TextNode, BaseNode, etc.) are defined elsewhere // Import statements (e.g., for TextNode, BaseNode) should be added based on your project's structure diff --git a/packages/core/src/outputParsers/selectors.ts b/packages/core/src/outputParsers/selectors.ts index 2d89882ae..491f2e617 100644 --- a/packages/core/src/outputParsers/selectors.ts +++ b/packages/core/src/outputParsers/selectors.ts @@ -1,5 +1,5 @@ import { parseJsonMarkdown } from "../OutputParser.js"; -import { BaseOutputParser, StructuredOutput } from "../types.js"; +import type { BaseOutputParser, StructuredOutput } from "../types.js"; export type Answer = { choice: number; diff --git a/packages/core/src/postprocessors/MetadataReplacementPostProcessor.ts b/packages/core/src/postprocessors/MetadataReplacementPostProcessor.ts index 134408075..f569043f3 100644 --- a/packages/core/src/postprocessors/MetadataReplacementPostProcessor.ts +++ b/packages/core/src/postprocessors/MetadataReplacementPostProcessor.ts @@ -1,5 +1,6 @@ -import { MetadataMode, NodeWithScore } from "../Node.js"; -import { BaseNodePostprocessor } from "./types.js"; +import type { NodeWithScore } from "../Node.js"; +import { MetadataMode } from "../Node.js"; +import type { BaseNodePostprocessor } from "./types.js"; export class MetadataReplacementPostProcessor implements BaseNodePostprocessor { targetMetadataKey: string; diff --git a/packages/core/src/postprocessors/SimilarityPostprocessor.ts b/packages/core/src/postprocessors/SimilarityPostprocessor.ts index 60db9501e..69d5aef6f 100644 --- a/packages/core/src/postprocessors/SimilarityPostprocessor.ts +++ b/packages/core/src/postprocessors/SimilarityPostprocessor.ts @@ -1,5 +1,5 @@ -import { NodeWithScore } from "../Node.js"; -import { BaseNodePostprocessor } from "./types.js"; +import type { NodeWithScore } from "../Node.js"; +import type { BaseNodePostprocessor } from "./types.js"; export class SimilarityPostprocessor implements BaseNodePostprocessor { similarityCutoff?: number; diff --git a/packages/core/src/postprocessors/rerankers/CohereRerank.ts b/packages/core/src/postprocessors/rerankers/CohereRerank.ts index b10579e16..5cd04e19a 100644 --- a/packages/core/src/postprocessors/rerankers/CohereRerank.ts +++ b/packages/core/src/postprocessors/rerankers/CohereRerank.ts @@ -1,7 +1,8 @@ import { CohereClient } from "cohere-ai"; -import { MetadataMode, NodeWithScore } from "../../Node.js"; -import { BaseNodePostprocessor } from "../types.js"; +import type { NodeWithScore } from "../../Node.js"; +import { MetadataMode } from "../../Node.js"; +import type { BaseNodePostprocessor } from "../types.js"; type CohereRerankOptions = { topN?: number; diff --git a/packages/core/src/postprocessors/types.ts b/packages/core/src/postprocessors/types.ts index 7a0c0617b..a45ccabf7 100644 --- a/packages/core/src/postprocessors/types.ts +++ b/packages/core/src/postprocessors/types.ts @@ -1,4 +1,4 @@ -import { NodeWithScore } from "../Node.js"; +import type { NodeWithScore } from "../Node.js"; export interface BaseNodePostprocessor { /** diff --git a/packages/core/src/readers/AssemblyAIReader.ts b/packages/core/src/readers/AssemblyAIReader.ts index 8418d82df..b038ce220 100644 --- a/packages/core/src/readers/AssemblyAIReader.ts +++ b/packages/core/src/readers/AssemblyAIReader.ts @@ -1,13 +1,13 @@ -import { - AssemblyAI, +import type { BaseServiceParams, SubtitleFormat, TranscribeParams, TranscriptParagraph, TranscriptSentence, } from "assemblyai"; +import { AssemblyAI } from "assemblyai"; import { Document } from "../Node.js"; -import { BaseReader } from "./type.js"; +import type { BaseReader } from "./type.js"; type AssemblyAIOptions = Partial<BaseServiceParams>; diff --git a/packages/core/src/readers/CSVReader.ts b/packages/core/src/readers/CSVReader.ts index 949de974f..17d321a83 100644 --- a/packages/core/src/readers/CSVReader.ts +++ b/packages/core/src/readers/CSVReader.ts @@ -1,8 +1,9 @@ import { defaultFS } from "@llamaindex/env"; -import { GenericFileSystem } from "@llamaindex/env/type"; -import Papa, { ParseConfig } from "papaparse"; +import type { GenericFileSystem } from "@llamaindex/env/type"; +import type { ParseConfig } from "papaparse"; +import Papa from "papaparse"; import { Document } from "../Node.js"; -import { FileReader } from "./type.js"; +import type { FileReader } from "./type.js"; /** * papaparse-based csv parser diff --git a/packages/core/src/readers/DocxReader.ts b/packages/core/src/readers/DocxReader.ts index 0af3e33e6..896c49be1 100644 --- a/packages/core/src/readers/DocxReader.ts +++ b/packages/core/src/readers/DocxReader.ts @@ -1,8 +1,8 @@ import { defaultFS } from "@llamaindex/env"; -import { GenericFileSystem } from "@llamaindex/env/type"; +import type { GenericFileSystem } from "@llamaindex/env/type"; import mammoth from "mammoth"; import { Document } from "../Node.js"; -import { FileReader } from "./type.js"; +import type { FileReader } from "./type.js"; export class DocxReader implements FileReader { /** DocxParser */ diff --git a/packages/core/src/readers/HTMLReader.ts b/packages/core/src/readers/HTMLReader.ts index ce53287f3..17f765cf4 100644 --- a/packages/core/src/readers/HTMLReader.ts +++ b/packages/core/src/readers/HTMLReader.ts @@ -1,7 +1,7 @@ import { defaultFS } from "@llamaindex/env"; -import { GenericFileSystem } from "@llamaindex/env/type"; +import type { GenericFileSystem } from "@llamaindex/env/type"; import { Document } from "../Node.js"; -import { FileReader } from "./type.js"; +import type { FileReader } from "./type.js"; /** * Extract the significant text from an arbitrary HTML document. diff --git a/packages/core/src/readers/ImageReader.ts b/packages/core/src/readers/ImageReader.ts index ea653697d..f3ea96809 100644 --- a/packages/core/src/readers/ImageReader.ts +++ b/packages/core/src/readers/ImageReader.ts @@ -1,7 +1,8 @@ import { defaultFS } from "@llamaindex/env"; -import { GenericFileSystem } from "@llamaindex/env/type"; -import { Document, ImageDocument } from "../Node.js"; -import { FileReader } from "./type.js"; +import type { GenericFileSystem } from "@llamaindex/env/type"; +import type { Document } from "../Node.js"; +import { ImageDocument } from "../Node.js"; +import type { FileReader } from "./type.js"; /** * Reads the content of an image file into a Document object (which stores the image file as a Blob). diff --git a/packages/core/src/readers/LlamaParseReader.ts b/packages/core/src/readers/LlamaParseReader.ts index 3f671e710..39aeca7ef 100644 --- a/packages/core/src/readers/LlamaParseReader.ts +++ b/packages/core/src/readers/LlamaParseReader.ts @@ -1,7 +1,7 @@ import { defaultFS } from "@llamaindex/env"; -import { GenericFileSystem } from "@llamaindex/env/type"; +import type { GenericFileSystem } from "@llamaindex/env/type"; import { Document } from "../Node.js"; -import { FileReader } from "./type.js"; +import type { FileReader } from "./type.js"; type ResultType = "text" | "markdown"; diff --git a/packages/core/src/readers/MarkdownReader.ts b/packages/core/src/readers/MarkdownReader.ts index 7b0ffdbaf..333d20dd5 100644 --- a/packages/core/src/readers/MarkdownReader.ts +++ b/packages/core/src/readers/MarkdownReader.ts @@ -1,7 +1,7 @@ import { defaultFS } from "@llamaindex/env"; -import { GenericFileSystem } from "@llamaindex/env/type"; +import type { GenericFileSystem } from "@llamaindex/env/type"; import { Document } from "../Node.js"; -import { FileReader } from "./type.js"; +import type { FileReader } from "./type.js"; type MarkdownTuple = [string | null, string]; diff --git a/packages/core/src/readers/NotionReader.ts b/packages/core/src/readers/NotionReader.ts index 7422e42b1..bbac5d08f 100644 --- a/packages/core/src/readers/NotionReader.ts +++ b/packages/core/src/readers/NotionReader.ts @@ -1,7 +1,8 @@ -import { Client } from "@notionhq/client"; -import { crawler, Crawler, Pages, pageToString } from "notion-md-crawler"; +import type { Client } from "@notionhq/client"; +import type { Crawler, Pages } from "notion-md-crawler"; +import { crawler, pageToString } from "notion-md-crawler"; import { Document } from "../Node.js"; -import { BaseReader } from "./type.js"; +import type { BaseReader } from "./type.js"; type OptionalSerializers = Parameters<Crawler>[number]["serializers"]; diff --git a/packages/core/src/readers/PDFReader.ts b/packages/core/src/readers/PDFReader.ts index 0df5ebf7e..990dc0010 100644 --- a/packages/core/src/readers/PDFReader.ts +++ b/packages/core/src/readers/PDFReader.ts @@ -1,7 +1,7 @@ import { createSHA256, defaultFS } from "@llamaindex/env"; -import { GenericFileSystem } from "@llamaindex/env/type"; +import type { GenericFileSystem } from "@llamaindex/env/type"; import { Document } from "../Node.js"; -import { BaseReader } from "./type.js"; +import type { BaseReader } from "./type.js"; /** * Read the text of a PDF diff --git a/packages/core/src/readers/SimpleDirectoryReader.ts b/packages/core/src/readers/SimpleDirectoryReader.ts index 6518c211a..d3e91415d 100644 --- a/packages/core/src/readers/SimpleDirectoryReader.ts +++ b/packages/core/src/readers/SimpleDirectoryReader.ts @@ -1,5 +1,5 @@ import { defaultFS, path } from "@llamaindex/env"; -import { CompleteFileSystem } from "@llamaindex/env/type"; +import type { CompleteFileSystem } from "@llamaindex/env/type"; import { Document } from "../Node.js"; import { walk } from "../storage/FileSystem.js"; import { PapaCSVReader } from "./CSVReader.js"; @@ -8,7 +8,7 @@ import { HTMLReader } from "./HTMLReader.js"; import { ImageReader } from "./ImageReader.js"; import { MarkdownReader } from "./MarkdownReader.js"; import { PDFReader } from "./PDFReader.js"; -import { BaseReader } from "./type.js"; +import type { BaseReader } from "./type.js"; type ReaderCallback = ( category: "file" | "directory", diff --git a/packages/core/src/readers/SimpleMongoReader.ts b/packages/core/src/readers/SimpleMongoReader.ts index f015868ac..b8c122ee4 100644 --- a/packages/core/src/readers/SimpleMongoReader.ts +++ b/packages/core/src/readers/SimpleMongoReader.ts @@ -1,6 +1,7 @@ -import { MongoClient } from "mongodb"; -import { Document, Metadata } from "../Node.js"; -import { BaseReader } from "./type.js"; +import type { MongoClient } from "mongodb"; +import type { Metadata } from "../Node.js"; +import { Document } from "../Node.js"; +import type { BaseReader } from "./type.js"; /** * Read in from MongoDB diff --git a/packages/core/src/readers/type.ts b/packages/core/src/readers/type.ts index 14ac3b2f4..428f79d64 100644 --- a/packages/core/src/readers/type.ts +++ b/packages/core/src/readers/type.ts @@ -1,5 +1,5 @@ -import { CompleteFileSystem } from "@llamaindex/env/type"; -import { Document } from "../Node.js"; +import type { CompleteFileSystem } from "@llamaindex/env/type"; +import type { Document } from "../Node.js"; /** * A reader takes imports data into Document objects. diff --git a/packages/core/src/selectors/base.ts b/packages/core/src/selectors/base.ts index f6992533e..a5ef61b41 100644 --- a/packages/core/src/selectors/base.ts +++ b/packages/core/src/selectors/base.ts @@ -1,5 +1,5 @@ import { PromptMixin } from "../prompts/Mixin.js"; -import { QueryBundle, ToolMetadataOnlyDescription } from "../types.js"; +import type { QueryBundle, ToolMetadataOnlyDescription } from "../types.js"; export interface SingleSelection { index: number; diff --git a/packages/core/src/selectors/llmSelectors.ts b/packages/core/src/selectors/llmSelectors.ts index bdc689941..654740fb0 100644 --- a/packages/core/src/selectors/llmSelectors.ts +++ b/packages/core/src/selectors/llmSelectors.ts @@ -1,15 +1,16 @@ -import { LLM } from "../llm/index.js"; -import { Answer, SelectionOutputParser } from "../outputParsers/selectors.js"; -import { +import type { LLM } from "../llm/index.js"; +import type { Answer } from "../outputParsers/selectors.js"; +import { SelectionOutputParser } from "../outputParsers/selectors.js"; +import type { BaseOutputParser, QueryBundle, StructuredOutput, ToolMetadataOnlyDescription, } from "../types.js"; -import { BaseSelector, SelectorResult } from "./base.js"; +import type { SelectorResult } from "./base.js"; +import { BaseSelector } from "./base.js"; +import type { MultiSelectPrompt, SingleSelectPrompt } from "./prompts.js"; import { - MultiSelectPrompt, - SingleSelectPrompt, defaultMultiSelectPrompt, defaultSingleSelectPrompt, } from "./prompts.js"; diff --git a/packages/core/src/selectors/utils.ts b/packages/core/src/selectors/utils.ts index 2b6f8bde9..084ec0267 100644 --- a/packages/core/src/selectors/utils.ts +++ b/packages/core/src/selectors/utils.ts @@ -1,5 +1,5 @@ -import { ServiceContext } from "../ServiceContext.js"; -import { BaseSelector } from "./base.js"; +import type { ServiceContext } from "../ServiceContext.js"; +import type { BaseSelector } from "./base.js"; import { LLMMultiSelector, LLMSingleSelector } from "./llmSelectors.js"; export const getSelectorFromContext = ( diff --git a/packages/core/src/storage/FileSystem.ts b/packages/core/src/storage/FileSystem.ts index cdafd3147..746dee472 100644 --- a/packages/core/src/storage/FileSystem.ts +++ b/packages/core/src/storage/FileSystem.ts @@ -1,4 +1,7 @@ -import { GenericFileSystem, WalkableFileSystem } from "@llamaindex/env/type"; +import type { + GenericFileSystem, + WalkableFileSystem, +} from "@llamaindex/env/type"; // FS utility functions /** diff --git a/packages/core/src/storage/StorageContext.ts b/packages/core/src/storage/StorageContext.ts index f178d3e3b..26d5f8139 100644 --- a/packages/core/src/storage/StorageContext.ts +++ b/packages/core/src/storage/StorageContext.ts @@ -1,15 +1,15 @@ import { defaultFS, path } from "@llamaindex/env"; -import { GenericFileSystem } from "@llamaindex/env/type"; +import type { GenericFileSystem } from "@llamaindex/env/type"; import { DEFAULT_IMAGE_VECTOR_NAMESPACE, DEFAULT_NAMESPACE, } from "./constants.js"; import { SimpleDocumentStore } from "./docStore/SimpleDocumentStore.js"; -import { BaseDocumentStore } from "./docStore/types.js"; +import type { BaseDocumentStore } from "./docStore/types.js"; import { SimpleIndexStore } from "./indexStore/SimpleIndexStore.js"; -import { BaseIndexStore } from "./indexStore/types.js"; +import type { BaseIndexStore } from "./indexStore/types.js"; import { SimpleVectorStore } from "./vectorStore/SimpleVectorStore.js"; -import { VectorStore } from "./vectorStore/types.js"; +import type { VectorStore } from "./vectorStore/types.js"; export interface StorageContext { docStore: BaseDocumentStore; diff --git a/packages/core/src/storage/chatStore/SimpleChatStore.ts b/packages/core/src/storage/chatStore/SimpleChatStore.ts index 22e06b4c6..43567abaf 100644 --- a/packages/core/src/storage/chatStore/SimpleChatStore.ts +++ b/packages/core/src/storage/chatStore/SimpleChatStore.ts @@ -1,5 +1,5 @@ -import { ChatMessage } from "../../llm/index.js"; -import { BaseChatStore } from "./types.js"; +import type { ChatMessage } from "../../llm/index.js"; +import type { BaseChatStore } from "./types.js"; /** * Simple chat store. diff --git a/packages/core/src/storage/chatStore/types.ts b/packages/core/src/storage/chatStore/types.ts index 87c7f892c..6607ebac8 100644 --- a/packages/core/src/storage/chatStore/types.ts +++ b/packages/core/src/storage/chatStore/types.ts @@ -1,4 +1,4 @@ -import { ChatMessage } from "../../llm/index.js"; +import type { ChatMessage } from "../../llm/index.js"; export interface BaseChatStore { setMessages(key: string, messages: ChatMessage[]): void; diff --git a/packages/core/src/storage/docStore/KVDocumentStore.ts b/packages/core/src/storage/docStore/KVDocumentStore.ts index e2d56bd4a..a14c1c5cd 100644 --- a/packages/core/src/storage/docStore/KVDocumentStore.ts +++ b/packages/core/src/storage/docStore/KVDocumentStore.ts @@ -1,8 +1,10 @@ import _, * as lodash from "lodash"; -import { BaseNode, ObjectType } from "../../Node.js"; +import type { BaseNode } from "../../Node.js"; +import { ObjectType } from "../../Node.js"; import { DEFAULT_NAMESPACE } from "../constants.js"; -import { BaseKVStore } from "../kvStore/types.js"; -import { BaseDocumentStore, RefDocInfo } from "./types.js"; +import type { BaseKVStore } from "../kvStore/types.js"; +import type { RefDocInfo } from "./types.js"; +import { BaseDocumentStore } from "./types.js"; import { docToJson, jsonToDoc } from "./utils.js"; type DocMetaData = { docHash: string; refDocId?: string }; @@ -34,7 +36,7 @@ export class KVDocumentStore extends BaseDocumentStore { docs: BaseNode[], allowUpdate: boolean = true, ): Promise<void> { - for (var idx = 0; idx < docs.length; idx++) { + for (let idx = 0; idx < docs.length; idx++) { const doc = docs[idx]; if (doc.id_ === null) { throw new Error("doc_id not set"); diff --git a/packages/core/src/storage/docStore/SimpleDocumentStore.ts b/packages/core/src/storage/docStore/SimpleDocumentStore.ts index ccce62a80..c1d300e73 100644 --- a/packages/core/src/storage/docStore/SimpleDocumentStore.ts +++ b/packages/core/src/storage/docStore/SimpleDocumentStore.ts @@ -1,5 +1,5 @@ import { defaultFS, path } from "@llamaindex/env"; -import { GenericFileSystem } from "@llamaindex/env/type"; +import type { GenericFileSystem } from "@llamaindex/env/type"; import _ from "lodash"; import { DEFAULT_DOC_STORE_PERSIST_FILENAME, diff --git a/packages/core/src/storage/docStore/types.ts b/packages/core/src/storage/docStore/types.ts index 228999bd0..f6205b639 100644 --- a/packages/core/src/storage/docStore/types.ts +++ b/packages/core/src/storage/docStore/types.ts @@ -1,4 +1,4 @@ -import { GenericFileSystem } from "@llamaindex/env/type"; +import type { GenericFileSystem } from "@llamaindex/env/type"; import { BaseNode } from "../../Node.js"; import { DEFAULT_DOC_STORE_PERSIST_FILENAME, diff --git a/packages/core/src/storage/docStore/utils.ts b/packages/core/src/storage/docStore/utils.ts index f84c1a8be..6eccaaebf 100644 --- a/packages/core/src/storage/docStore/utils.ts +++ b/packages/core/src/storage/docStore/utils.ts @@ -1,4 +1,5 @@ -import { BaseNode, Document, ObjectType, TextNode } from "../../Node.js"; +import type { BaseNode } from "../../Node.js"; +import { Document, ObjectType, TextNode } from "../../Node.js"; const TYPE_KEY = "__type__"; const DATA_KEY = "__data__"; diff --git a/packages/core/src/storage/indexStore/KVIndexStore.ts b/packages/core/src/storage/indexStore/KVIndexStore.ts index 3d15ce9d1..87ce07fa2 100644 --- a/packages/core/src/storage/indexStore/KVIndexStore.ts +++ b/packages/core/src/storage/indexStore/KVIndexStore.ts @@ -1,8 +1,8 @@ import _ from "lodash"; -import { IndexStruct } from "../../indices/IndexStruct.js"; +import type { IndexStruct } from "../../indices/IndexStruct.js"; import { jsonToIndexStruct } from "../../indices/json-to-index-struct.js"; import { DEFAULT_NAMESPACE } from "../constants.js"; -import { BaseKVStore } from "../kvStore/types.js"; +import type { BaseKVStore } from "../kvStore/types.js"; import { BaseIndexStore } from "./types.js"; export class KVIndexStore extends BaseIndexStore { diff --git a/packages/core/src/storage/indexStore/SimpleIndexStore.ts b/packages/core/src/storage/indexStore/SimpleIndexStore.ts index e31263404..ce79c6ed3 100644 --- a/packages/core/src/storage/indexStore/SimpleIndexStore.ts +++ b/packages/core/src/storage/indexStore/SimpleIndexStore.ts @@ -1,11 +1,12 @@ import { defaultFS, path } from "@llamaindex/env"; -import { GenericFileSystem } from "@llamaindex/env/type"; +import type { GenericFileSystem } from "@llamaindex/env/type"; import { DEFAULT_INDEX_STORE_PERSIST_FILENAME, DEFAULT_PERSIST_DIR, } from "../constants.js"; -import { DataType, SimpleKVStore } from "../kvStore/SimpleKVStore.js"; -import { BaseInMemoryKVStore } from "../kvStore/types.js"; +import type { DataType } from "../kvStore/SimpleKVStore.js"; +import { SimpleKVStore } from "../kvStore/SimpleKVStore.js"; +import type { BaseInMemoryKVStore } from "../kvStore/types.js"; import { KVIndexStore } from "./KVIndexStore.js"; export class SimpleIndexStore extends KVIndexStore { diff --git a/packages/core/src/storage/indexStore/types.ts b/packages/core/src/storage/indexStore/types.ts index 378166f8e..a844c0000 100644 --- a/packages/core/src/storage/indexStore/types.ts +++ b/packages/core/src/storage/indexStore/types.ts @@ -1,5 +1,5 @@ -import { GenericFileSystem } from "@llamaindex/env/type"; -import { IndexStruct } from "../../indices/IndexStruct.js"; +import type { GenericFileSystem } from "@llamaindex/env/type"; +import type { IndexStruct } from "../../indices/IndexStruct.js"; import { DEFAULT_INDEX_STORE_PERSIST_FILENAME, DEFAULT_PERSIST_DIR, diff --git a/packages/core/src/storage/kvStore/SimpleKVStore.ts b/packages/core/src/storage/kvStore/SimpleKVStore.ts index fe7c2211c..e6be2a98d 100644 --- a/packages/core/src/storage/kvStore/SimpleKVStore.ts +++ b/packages/core/src/storage/kvStore/SimpleKVStore.ts @@ -1,5 +1,5 @@ import { defaultFS, path } from "@llamaindex/env"; -import { GenericFileSystem } from "@llamaindex/env/type"; +import type { GenericFileSystem } from "@llamaindex/env/type"; import _ from "lodash"; import { exists } from "../FileSystem.js"; import { DEFAULT_COLLECTION } from "../constants.js"; diff --git a/packages/core/src/storage/kvStore/types.ts b/packages/core/src/storage/kvStore/types.ts index 6005c023a..0bd5a3d5b 100644 --- a/packages/core/src/storage/kvStore/types.ts +++ b/packages/core/src/storage/kvStore/types.ts @@ -1,4 +1,4 @@ -import { GenericFileSystem } from "@llamaindex/env/type"; +import type { GenericFileSystem } from "@llamaindex/env/type"; const defaultCollection = "data"; type StoredValue = Record<string, any> | null; diff --git a/packages/core/src/storage/vectorStore/AstraDBVectorStore.ts b/packages/core/src/storage/vectorStore/AstraDBVectorStore.ts index 72ab14fd7..17c0170c3 100644 --- a/packages/core/src/storage/vectorStore/AstraDBVectorStore.ts +++ b/packages/core/src/storage/vectorStore/AstraDBVectorStore.ts @@ -1,7 +1,8 @@ import { AstraDB } from "@datastax/astra-db-ts"; -import { Collection } from "@datastax/astra-db-ts/dist/collections"; -import { BaseNode, MetadataMode } from "../../Node.js"; -import { +import type { Collection } from "@datastax/astra-db-ts/dist/collections"; +import type { BaseNode } from "../../Node.js"; +import { MetadataMode } from "../../Node.js"; +import type { VectorStore, VectorStoreQuery, VectorStoreQueryResult, diff --git a/packages/core/src/storage/vectorStore/ChromaVectorStore.ts b/packages/core/src/storage/vectorStore/ChromaVectorStore.ts index f5ace2dab..ae5ac4294 100644 --- a/packages/core/src/storage/vectorStore/ChromaVectorStore.ts +++ b/packages/core/src/storage/vectorStore/ChromaVectorStore.ts @@ -1,20 +1,20 @@ -import { +import type { AddParams, - ChromaClient, ChromaClientParams, Collection, - IncludeEnum, QueryResponse, Where, WhereDocument, } from "chromadb"; -import { BaseNode, MetadataMode } from "../../Node.js"; -import { +import { ChromaClient, IncludeEnum } from "chromadb"; +import type { BaseNode } from "../../Node.js"; +import { MetadataMode } from "../../Node.js"; +import type { VectorStore, VectorStoreQuery, - VectorStoreQueryMode, VectorStoreQueryResult, } from "./types.js"; +import { VectorStoreQueryMode } from "./types.js"; import { metadataDictToNode, nodeToMetadata } from "./utils.js"; type ChromaDeleteOptions = { diff --git a/packages/core/src/storage/vectorStore/MongoDBAtlasVectorStore.ts b/packages/core/src/storage/vectorStore/MongoDBAtlasVectorStore.ts index 919b32052..491d5fd10 100644 --- a/packages/core/src/storage/vectorStore/MongoDBAtlasVectorStore.ts +++ b/packages/core/src/storage/vectorStore/MongoDBAtlasVectorStore.ts @@ -1,6 +1,8 @@ -import { BulkWriteOptions, Collection, MongoClient } from "mongodb"; -import { BaseNode, MetadataMode } from "../../Node.js"; -import { +import type { BulkWriteOptions, Collection } from "mongodb"; +import { MongoClient } from "mongodb"; +import type { BaseNode } from "../../Node.js"; +import { MetadataMode } from "../../Node.js"; +import type { MetadataFilters, VectorStore, VectorStoreQuery, diff --git a/packages/core/src/storage/vectorStore/PGVectorStore.ts b/packages/core/src/storage/vectorStore/PGVectorStore.ts index 7b20916d9..08f71f5f8 100644 --- a/packages/core/src/storage/vectorStore/PGVectorStore.ts +++ b/packages/core/src/storage/vectorStore/PGVectorStore.ts @@ -1,14 +1,15 @@ import pg from "pg"; import pgvector from "pgvector/pg"; -import { +import type { VectorStore, VectorStoreQuery, VectorStoreQueryResult, } from "./types.js"; -import { GenericFileSystem } from "@llamaindex/env/type"; -import { BaseNode, Document, Metadata, MetadataMode } from "../../Node.js"; +import type { GenericFileSystem } from "@llamaindex/env/type"; +import type { BaseNode, Metadata } from "../../Node.js"; +import { Document, MetadataMode } from "../../Node.js"; export const PGVECTOR_SCHEMA = "public"; export const PGVECTOR_TABLE = "llamaindex_embedding"; @@ -147,7 +148,7 @@ export class PGVectorStore implements VectorStore { const sql: string = `DELETE FROM ${this.schemaName}.${this.tableName} WHERE collection = $1`; - const db = (await this.getDb()) as pg.Client; + const db = await this.getDb(); const ret = await db.query(sql, [this.collection]); return ret; @@ -192,7 +193,7 @@ export class PGVectorStore implements VectorStore { (id, external_id, collection, document, metadata, embeddings) VALUES ($1, $2, $3, $4, $5, $6)`; - const db = (await this.getDb()) as pg.Client; + const db = await this.getDb(); const data = this.getDataToInsert(embeddingResults); const ret: string[] = []; @@ -227,7 +228,7 @@ export class PGVectorStore implements VectorStore { const sql: string = `DELETE FROM ${this.schemaName}.${this.tableName} WHERE id = $1 ${collectionCriteria}`; - const db = (await this.getDb()) as pg.Client; + const db = await this.getDb(); const params = this.collection.length ? [refDocId, this.collection] : [refDocId]; @@ -276,7 +277,7 @@ export class PGVectorStore implements VectorStore { LIMIT ${max} `; - const db = (await this.getDb()) as pg.Client; + const db = await this.getDb(); const results = await db.query(sql, params); const nodes = results.rows.map((row) => { diff --git a/packages/core/src/storage/vectorStore/PineconeVectorStore.ts b/packages/core/src/storage/vectorStore/PineconeVectorStore.ts index 8d3dec3ba..9c965bfae 100644 --- a/packages/core/src/storage/vectorStore/PineconeVectorStore.ts +++ b/packages/core/src/storage/vectorStore/PineconeVectorStore.ts @@ -1,4 +1,4 @@ -import { +import type { ExactMatchFilter, MetadataFilters, VectorStore, @@ -6,14 +6,14 @@ import { VectorStoreQueryResult, } from "./types.js"; -import { GenericFileSystem } from "@llamaindex/env/type"; -import { +import type { GenericFileSystem } from "@llamaindex/env/type"; +import type { FetchResponse, Index, - Pinecone, ScoredPineconeRecord, } from "@pinecone-database/pinecone"; -import { BaseNode, Metadata } from "../../Node.js"; +import { Pinecone } from "@pinecone-database/pinecone"; +import type { BaseNode, Metadata } from "../../Node.js"; import { metadataDictToNode, nodeToMetadata } from "./utils.js"; type PineconeParams = { diff --git a/packages/core/src/storage/vectorStore/QdrantVectorStore.ts b/packages/core/src/storage/vectorStore/QdrantVectorStore.ts index 0d656d15f..44b1ed7f2 100644 --- a/packages/core/src/storage/vectorStore/QdrantVectorStore.ts +++ b/packages/core/src/storage/vectorStore/QdrantVectorStore.ts @@ -1,5 +1,5 @@ -import { BaseNode } from "../../Node.js"; -import { +import type { BaseNode } from "../../Node.js"; +import type { VectorStore, VectorStoreQuery, VectorStoreQueryResult, diff --git a/packages/core/src/storage/vectorStore/SimpleVectorStore.ts b/packages/core/src/storage/vectorStore/SimpleVectorStore.ts index 85b286c32..e0478918d 100644 --- a/packages/core/src/storage/vectorStore/SimpleVectorStore.ts +++ b/packages/core/src/storage/vectorStore/SimpleVectorStore.ts @@ -1,7 +1,7 @@ import { defaultFS, path } from "@llamaindex/env"; -import { GenericFileSystem } from "@llamaindex/env/type"; +import type { GenericFileSystem } from "@llamaindex/env/type"; import _ from "lodash"; -import { BaseNode } from "../../Node.js"; +import type { BaseNode } from "../../Node.js"; import { getTopKEmbeddings, getTopKEmbeddingsLearner, @@ -9,12 +9,12 @@ import { } from "../../embeddings/utils.js"; import { exists } from "../FileSystem.js"; import { DEFAULT_PERSIST_DIR } from "../constants.js"; -import { +import type { VectorStore, VectorStoreQuery, - VectorStoreQueryMode, VectorStoreQueryResult, } from "./types.js"; +import { VectorStoreQueryMode } from "./types.js"; const LEARNER_MODES = new Set<VectorStoreQueryMode>([ VectorStoreQueryMode.SVM, diff --git a/packages/core/src/storage/vectorStore/types.ts b/packages/core/src/storage/vectorStore/types.ts index d3451143b..c14ec6077 100644 --- a/packages/core/src/storage/vectorStore/types.ts +++ b/packages/core/src/storage/vectorStore/types.ts @@ -1,4 +1,4 @@ -import { BaseNode } from "../../Node.js"; +import type { BaseNode } from "../../Node.js"; export interface VectorStoreQueryResult { nodes?: BaseNode[]; diff --git a/packages/core/src/storage/vectorStore/utils.ts b/packages/core/src/storage/vectorStore/utils.ts index 34af36316..3556d58bf 100644 --- a/packages/core/src/storage/vectorStore/utils.ts +++ b/packages/core/src/storage/vectorStore/utils.ts @@ -1,4 +1,5 @@ -import { BaseNode, jsonToNode, Metadata, ObjectType } from "../../Node.js"; +import type { BaseNode, Metadata } from "../../Node.js"; +import { ObjectType, jsonToNode } from "../../Node.js"; const DEFAULT_TEXT_KEY = "text"; diff --git a/packages/core/src/synthesizers/MultiModalResponseSynthesizer.ts b/packages/core/src/synthesizers/MultiModalResponseSynthesizer.ts index 591668958..a6454c134 100644 --- a/packages/core/src/synthesizers/MultiModalResponseSynthesizer.ts +++ b/packages/core/src/synthesizers/MultiModalResponseSynthesizer.ts @@ -1,14 +1,14 @@ -import { ImageNode, MetadataMode, splitNodesByType } from "../Node.js"; +import type { ImageNode } from "../Node.js"; +import { MetadataMode, splitNodesByType } from "../Node.js"; import { Response } from "../Response.js"; -import { - ServiceContext, - serviceContextFromDefaults, -} from "../ServiceContext.js"; +import type { ServiceContext } from "../ServiceContext.js"; +import { serviceContextFromDefaults } from "../ServiceContext.js"; import { imageToDataUrl } from "../embeddings/index.js"; -import { MessageContentDetail } from "../llm/types.js"; +import type { MessageContentDetail } from "../llm/types.js"; import { PromptMixin } from "../prompts/Mixin.js"; -import { TextQaPrompt, defaultTextQaPrompt } from "./../Prompt.js"; -import { +import type { TextQaPrompt } from "./../Prompt.js"; +import { defaultTextQaPrompt } from "./../Prompt.js"; +import type { BaseSynthesizer, SynthesizeParamsNonStreaming, SynthesizeParamsStreaming, diff --git a/packages/core/src/synthesizers/ResponseSynthesizer.ts b/packages/core/src/synthesizers/ResponseSynthesizer.ts index f2a8daf9c..6f5663295 100644 --- a/packages/core/src/synthesizers/ResponseSynthesizer.ts +++ b/packages/core/src/synthesizers/ResponseSynthesizer.ts @@ -1,13 +1,12 @@ import { MetadataMode } from "../Node.js"; import { Response } from "../Response.js"; -import { - ServiceContext, - serviceContextFromDefaults, -} from "../ServiceContext.js"; +import type { ServiceContext } from "../ServiceContext.js"; +import { serviceContextFromDefaults } from "../ServiceContext.js"; import { streamConverter } from "../llm/utils.js"; import { PromptMixin } from "../prompts/Mixin.js"; -import { ResponseBuilderPrompts, getResponseBuilder } from "./builders.js"; -import { +import type { ResponseBuilderPrompts } from "./builders.js"; +import { getResponseBuilder } from "./builders.js"; +import type { BaseSynthesizer, ResponseBuilder, SynthesizeParamsNonStreaming, diff --git a/packages/core/src/synthesizers/builders.ts b/packages/core/src/synthesizers/builders.ts index 0c232b962..49e1105ad 100644 --- a/packages/core/src/synthesizers/builders.ts +++ b/packages/core/src/synthesizers/builders.ts @@ -1,19 +1,22 @@ -import { Event } from "../callbacks/CallbackManager.js"; -import { LLM } from "../llm/index.js"; +import type { Event } from "../callbacks/CallbackManager.js"; +import type { LLM } from "../llm/index.js"; import { streamConverter } from "../llm/utils.js"; -import { - defaultRefinePrompt, - defaultTextQaPrompt, - defaultTreeSummarizePrompt, +import type { RefinePrompt, SimplePrompt, TextQaPrompt, TreeSummarizePrompt, } from "../Prompt.js"; -import { getBiggestPrompt, PromptHelper } from "../PromptHelper.js"; -import { PromptMixin } from "../prompts/Mixin.js"; -import { ServiceContext } from "../ServiceContext.js"; import { + defaultRefinePrompt, + defaultTextQaPrompt, + defaultTreeSummarizePrompt, +} from "../Prompt.js"; +import type { PromptHelper } from "../PromptHelper.js"; +import { getBiggestPrompt } from "../PromptHelper.js"; +import { PromptMixin } from "../prompts/Mixin.js"; +import type { ServiceContext } from "../ServiceContext.js"; +import type { ResponseBuilder, ResponseBuilderParamsNonStreaming, ResponseBuilderParamsStreaming, diff --git a/packages/core/src/synthesizers/types.ts b/packages/core/src/synthesizers/types.ts index 333a3bdc4..8b8a46972 100644 --- a/packages/core/src/synthesizers/types.ts +++ b/packages/core/src/synthesizers/types.ts @@ -1,7 +1,7 @@ -import { Event } from "../callbacks/CallbackManager.js"; -import { NodeWithScore } from "../Node.js"; -import { PromptMixin } from "../prompts/Mixin.js"; -import { Response } from "../Response.js"; +import type { Event } from "../callbacks/CallbackManager.js"; +import type { NodeWithScore } from "../Node.js"; +import type { PromptMixin } from "../prompts/Mixin.js"; +import type { Response } from "../Response.js"; export interface SynthesizeParamsBase { query: string; diff --git a/packages/core/src/tools/QueryEngineTool.ts b/packages/core/src/tools/QueryEngineTool.ts index fa3505f6c..60fa03755 100644 --- a/packages/core/src/tools/QueryEngineTool.ts +++ b/packages/core/src/tools/QueryEngineTool.ts @@ -1,4 +1,4 @@ -import { BaseQueryEngine, BaseTool, ToolMetadata } from "../types.js"; +import type { BaseQueryEngine, BaseTool, ToolMetadata } from "../types.js"; export type QueryEngineToolParams = { queryEngine: BaseQueryEngine; diff --git a/packages/core/src/tools/functionTool.ts b/packages/core/src/tools/functionTool.ts index af3f50ca3..d59b07589 100644 --- a/packages/core/src/tools/functionTool.ts +++ b/packages/core/src/tools/functionTool.ts @@ -1,4 +1,4 @@ -import { BaseTool, ToolMetadata } from "../types.js"; +import type { BaseTool, ToolMetadata } from "../types.js"; type Metadata = { name: string; diff --git a/packages/core/src/tools/utils.ts b/packages/core/src/tools/utils.ts index 65bc25ab0..aaba6b01a 100644 --- a/packages/core/src/tools/utils.ts +++ b/packages/core/src/tools/utils.ts @@ -1,4 +1,4 @@ -import { BaseTool } from "../types.js"; +import type { BaseTool } from "../types.js"; import { ToolOutput } from "./types.js"; /** diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index d3d454524..827e51420 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -1,8 +1,8 @@ /** * Top level types to avoid circular dependencies */ -import { Event } from "./callbacks/CallbackManager.js"; -import { Response } from "./Response.js"; +import type { Event } from "./callbacks/CallbackManager.js"; +import type { Response } from "./Response.js"; /** * Parameters for sending a query. diff --git a/packages/core/tests/CallbackManager.test.ts b/packages/core/tests/CallbackManager.test.ts index ea4729741..293553788 100644 --- a/packages/core/tests/CallbackManager.test.ts +++ b/packages/core/tests/CallbackManager.test.ts @@ -9,15 +9,13 @@ import { } from "vitest"; import { Document } from "llamaindex/Node"; -import { - ServiceContext, - serviceContextFromDefaults, -} from "llamaindex/ServiceContext"; -import { - CallbackManager, +import type { ServiceContext } from "llamaindex/ServiceContext"; +import { serviceContextFromDefaults } from "llamaindex/ServiceContext"; +import type { RetrievalCallbackResponse, StreamCallbackResponse, } from "llamaindex/callbacks/CallbackManager"; +import { CallbackManager } from "llamaindex/callbacks/CallbackManager"; import { OpenAIEmbedding } from "llamaindex/embeddings/index"; import { SummaryIndex } from "llamaindex/indices/summary/index"; import { VectorStoreIndex } from "llamaindex/indices/vectorStore/index"; diff --git a/packages/core/tests/MetadataExtractors.test.ts b/packages/core/tests/MetadataExtractors.test.ts index af848c068..edab6b0d9 100644 --- a/packages/core/tests/MetadataExtractors.test.ts +++ b/packages/core/tests/MetadataExtractors.test.ts @@ -1,13 +1,11 @@ import { Document } from "llamaindex/Node"; -import { - ServiceContext, - serviceContextFromDefaults, -} from "llamaindex/ServiceContext"; -import { - CallbackManager, +import type { ServiceContext } from "llamaindex/ServiceContext"; +import { serviceContextFromDefaults } from "llamaindex/ServiceContext"; +import type { RetrievalCallbackResponse, StreamCallbackResponse, } from "llamaindex/callbacks/CallbackManager"; +import { CallbackManager } from "llamaindex/callbacks/CallbackManager"; import { OpenAIEmbedding } from "llamaindex/embeddings/index"; import { KeywordExtractor, diff --git a/packages/core/tests/ingestion/IngestionCache.test.ts b/packages/core/tests/ingestion/IngestionCache.test.ts index 278ef53cf..a8406d07b 100644 --- a/packages/core/tests/ingestion/IngestionCache.test.ts +++ b/packages/core/tests/ingestion/IngestionCache.test.ts @@ -1,9 +1,10 @@ -import { BaseNode, TextNode } from "llamaindex/Node"; +import type { BaseNode } from "llamaindex/Node"; +import { TextNode } from "llamaindex/Node"; import { IngestionCache, getTransformationHash, } from "llamaindex/ingestion/IngestionCache"; -import { TransformComponent } from "llamaindex/ingestion/index"; +import type { TransformComponent } from "llamaindex/ingestion/index"; import { SimpleNodeParser } from "llamaindex/nodeParsers/index"; import { beforeAll, describe, expect, test } from "vitest"; diff --git a/packages/core/tests/mocks/TestableQdrantVectorStore.ts b/packages/core/tests/mocks/TestableQdrantVectorStore.ts index 306d04846..dff820705 100644 --- a/packages/core/tests/mocks/TestableQdrantVectorStore.ts +++ b/packages/core/tests/mocks/TestableQdrantVectorStore.ts @@ -1,4 +1,4 @@ -import { BaseNode } from "llamaindex/Node"; +import type { BaseNode } from "llamaindex/Node"; import { QdrantVectorStore } from "llamaindex/storage/index"; export class TestableQdrantVectorStore extends QdrantVectorStore { diff --git a/packages/core/tests/objects/ObjectIndex.test.ts b/packages/core/tests/objects/ObjectIndex.test.ts index 10a46e771..b65e76765 100644 --- a/packages/core/tests/objects/ObjectIndex.test.ts +++ b/packages/core/tests/objects/ObjectIndex.test.ts @@ -1,9 +1,9 @@ +import type { ServiceContext } from "llamaindex"; import { FunctionTool, ObjectIndex, OpenAI, OpenAIEmbedding, - ServiceContext, SimpleToolNodeMapping, VectorStoreIndex, serviceContextFromDefaults, diff --git a/packages/core/tests/postprocessors/MetadataReplacementPostProcessor.test.ts b/packages/core/tests/postprocessors/MetadataReplacementPostProcessor.test.ts index 360b242c6..7412f8d23 100644 --- a/packages/core/tests/postprocessors/MetadataReplacementPostProcessor.test.ts +++ b/packages/core/tests/postprocessors/MetadataReplacementPostProcessor.test.ts @@ -1,4 +1,5 @@ -import { MetadataMode, NodeWithScore, TextNode } from "llamaindex/Node"; +import type { NodeWithScore } from "llamaindex/Node"; +import { MetadataMode, TextNode } from "llamaindex/Node"; import { MetadataReplacementPostProcessor } from "llamaindex/postprocessors/index"; import { beforeEach, describe, expect, test } from "vitest"; diff --git a/packages/core/tests/utility/mockOpenAI.ts b/packages/core/tests/utility/mockOpenAI.ts index b2d684686..b0dbcb03f 100644 --- a/packages/core/tests/utility/mockOpenAI.ts +++ b/packages/core/tests/utility/mockOpenAI.ts @@ -1,8 +1,8 @@ import { globalsHelper } from "llamaindex/GlobalsHelper"; -import { CallbackManager } from "llamaindex/callbacks/CallbackManager"; -import { OpenAIEmbedding } from "llamaindex/embeddings/index"; -import { OpenAI } from "llamaindex/llm/LLM"; -import { LLMChatParamsBase } from "llamaindex/llm/types"; +import type { CallbackManager } from "llamaindex/callbacks/CallbackManager"; +import type { OpenAIEmbedding } from "llamaindex/embeddings/index"; +import type { OpenAI } from "llamaindex/llm/LLM"; +import type { LLMChatParamsBase } from "llamaindex/llm/types"; import { vi } from "vitest"; export const DEFAULT_LLM_TEXT_OUTPUT = "MOCK_TOKEN_1-MOCK_TOKEN_2"; diff --git a/packages/core/tests/vectorStores/QdrantVectorStore.test.ts b/packages/core/tests/vectorStores/QdrantVectorStore.test.ts index 67cda1b46..a3f242c38 100644 --- a/packages/core/tests/vectorStores/QdrantVectorStore.test.ts +++ b/packages/core/tests/vectorStores/QdrantVectorStore.test.ts @@ -1,5 +1,7 @@ -import { BaseNode, TextNode } from "llamaindex/Node"; -import { Mocked, beforeEach, describe, expect, it, vi } from "vitest"; +import type { BaseNode } from "llamaindex/Node"; +import { TextNode } from "llamaindex/Node"; +import type { Mocked } from "vitest"; +import { beforeEach, describe, expect, it, vi } from "vitest"; import { QdrantClient } from "@qdrant/js-client-rest"; import { VectorStoreQueryMode } from "llamaindex/storage/index"; diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index 535cfc3a8..6367996de 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -1,16 +1,13 @@ { + "extends": "../../tsconfig.json", "compilerOptions": { "rootDir": "./src", "outDir": "./dist/type", - "declaration": true, - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, + "emitDeclarationOnly": true, "module": "node16", "moduleResolution": "node16", "skipLibCheck": true, - "strict": true, - "lib": ["ESNext", "dom"], - "target": "ESNext" + "strict": true }, "include": ["./src"], "exclude": ["node_modules"] diff --git a/packages/env/src/index.polyfill.ts b/packages/env/src/index.polyfill.ts index db2520820..89b5b6421 100644 --- a/packages/env/src/index.polyfill.ts +++ b/packages/env/src/index.polyfill.ts @@ -1,6 +1,6 @@ import { Sha256 } from "@aws-crypto/sha256-js"; import pathe from "pathe"; -import { CompleteFileSystem, InMemoryFileSystem } from "./type.js"; +import { InMemoryFileSystem, type CompleteFileSystem } from "./type.js"; export { pathe as path }; diff --git a/packages/env/tsconfig.json b/packages/env/tsconfig.json index 419912df4..373c74079 100644 --- a/packages/env/tsconfig.json +++ b/packages/env/tsconfig.json @@ -1,17 +1,12 @@ { + "extends": "../../tsconfig.json", "compilerOptions": { "rootDir": "./src", "outDir": "./dist/type", - "declaration": true, - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, + "emitDeclarationOnly": true, "module": "node16", "moduleResolution": "node16", - "skipLibCheck": true, - "strict": true, - "lib": ["ESNext", "dom"], - "types": ["node"], - "target": "ESNext" + "types": ["node"] }, "include": ["./src"], "exclude": ["node_modules"] diff --git a/tsconfig.json b/tsconfig.json index a4123d728..561b01dd2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,6 +3,7 @@ "target": "es2016", "module": "esnext", "moduleResolution": "bundler", + "verbatimModuleSyntax": true, "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, -- GitLab