llama-index
171 строка · 4.4 Кб
1"""Init file of LlamaIndex."""
2
3from pathlib import Path4
5with open(Path(__file__).absolute().parents[0] / "VERSION") as _f:6__version__ = _f.read().strip()7
8
9import logging10from logging import NullHandler11from typing import Callable, Optional12
13# import global eval handler
14from llama_index.legacy.callbacks.global_handlers import set_global_handler15
16# response
17from llama_index.legacy.core.response.schema import Response18from llama_index.legacy.data_structs.struct_type import IndexStructType19
20# embeddings
21from llama_index.legacy.embeddings import OpenAIEmbedding22
23# indices
24# loading
25from llama_index.legacy.indices import (26ComposableGraph,27DocumentSummaryIndex,28GPTDocumentSummaryIndex,29GPTKeywordTableIndex,30GPTKnowledgeGraphIndex,31GPTListIndex,32GPTRAKEKeywordTableIndex,33GPTSimpleKeywordTableIndex,34GPTTreeIndex,35GPTVectorStoreIndex,36KeywordTableIndex,37KnowledgeGraphIndex,38ListIndex,39RAKEKeywordTableIndex,40SimpleKeywordTableIndex,41SummaryIndex,42TreeIndex,43VectorStoreIndex,44load_graph_from_storage,45load_index_from_storage,46load_indices_from_storage,47)
48
49# structured
50from llama_index.legacy.indices.common.struct_store.base import (51SQLDocumentContextBuilder,52)
53
54# prompt helper
55from llama_index.legacy.indices.prompt_helper import PromptHelper56from llama_index.legacy.llm_predictor import LLMPredictor57
58# token predictor
59from llama_index.legacy.llm_predictor.mock import MockLLMPredictor60
61# prompts
62from llama_index.legacy.prompts import (63BasePromptTemplate,64ChatPromptTemplate,65# backwards compatibility66Prompt,67PromptTemplate,68SelectorPromptTemplate,69)
70from llama_index.legacy.readers import (71SimpleDirectoryReader,72download_loader,73)
74
75# Response Synthesizer
76from llama_index.legacy.response_synthesizers.factory import get_response_synthesizer77from llama_index.legacy.schema import Document, QueryBundle78from llama_index.legacy.service_context import (79ServiceContext,80set_global_service_context,81)
82
83# storage
84from llama_index.legacy.storage.storage_context import StorageContext85from llama_index.legacy.token_counter.mock_embed_model import MockEmbedding86
87# sql wrapper
88from llama_index.legacy.utilities.sql_wrapper import SQLDatabase89
90# global tokenizer
91from llama_index.legacy.utils import get_tokenizer, set_global_tokenizer92
93# best practices for library logging:
94# https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library
95logging.getLogger(__name__).addHandler(NullHandler())96
97__all__ = [98"StorageContext",99"ServiceContext",100"ComposableGraph",101# indices102"SummaryIndex",103"VectorStoreIndex",104"SimpleKeywordTableIndex",105"KeywordTableIndex",106"RAKEKeywordTableIndex",107"TreeIndex",108"DocumentSummaryIndex",109"KnowledgeGraphIndex",110# indices - legacy names111"GPTKeywordTableIndex",112"GPTKnowledgeGraphIndex",113"GPTSimpleKeywordTableIndex",114"GPTRAKEKeywordTableIndex",115"GPTListIndex",116"ListIndex",117"GPTTreeIndex",118"GPTVectorStoreIndex",119"GPTDocumentSummaryIndex",120"Prompt",121"PromptTemplate",122"BasePromptTemplate",123"ChatPromptTemplate",124"SelectorPromptTemplate",125"OpenAIEmbedding",126"SummaryPrompt",127"TreeInsertPrompt",128"TreeSelectPrompt",129"TreeSelectMultiplePrompt",130"RefinePrompt",131"QuestionAnswerPrompt",132"KeywordExtractPrompt",133"QueryKeywordExtractPrompt",134"Response",135"Document",136"SimpleDirectoryReader",137"LLMPredictor",138"MockLLMPredictor",139"VellumPredictor",140"VellumPromptRegistry",141"MockEmbedding",142"SQLDatabase",143"SQLDocumentContextBuilder",144"SQLContextBuilder",145"PromptHelper",146"IndexStructType",147"download_loader",148"load_graph_from_storage",149"load_index_from_storage",150"load_indices_from_storage",151"QueryBundle",152"get_response_synthesizer",153"set_global_service_context",154"set_global_handler",155"set_global_tokenizer",156"get_tokenizer",157]
158
159# eval global toggle
160from llama_index.legacy.callbacks.base_handler import BaseCallbackHandler161
162global_handler: Optional[BaseCallbackHandler] = None163
164# NOTE: keep for backwards compatibility
165SQLContextBuilder = SQLDocumentContextBuilder166
167# global service context for ServiceContext.from_defaults()
168global_service_context: Optional[ServiceContext] = None169
170# global tokenizer
171global_tokenizer: Optional[Callable[[str], list]] = None172