|
|
@ -27,7 +27,8 @@ from gpt_index import (
|
|
|
|
LLMPredictor,
|
|
|
|
LLMPredictor,
|
|
|
|
QueryConfig,
|
|
|
|
QueryConfig,
|
|
|
|
PromptHelper,
|
|
|
|
PromptHelper,
|
|
|
|
IndexStructType, OpenAIEmbedding,
|
|
|
|
IndexStructType,
|
|
|
|
|
|
|
|
OpenAIEmbedding,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
from gpt_index.readers.web import DEFAULT_WEBSITE_EXTRACTOR
|
|
|
|
from gpt_index.readers.web import DEFAULT_WEBSITE_EXTRACTOR
|
|
|
|
|
|
|
|
|
|
|
@ -38,7 +39,9 @@ from services.environment_service import EnvService, app_root_path
|
|
|
|
SHORT_TO_LONG_CACHE = {}
|
|
|
|
SHORT_TO_LONG_CACHE = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_and_query(user_id, index_storage, query, response_mode, nodes, llm_predictor, embed_model):
|
|
|
|
def get_and_query(
|
|
|
|
|
|
|
|
user_id, index_storage, query, response_mode, nodes, llm_predictor, embed_model
|
|
|
|
|
|
|
|
):
|
|
|
|
index: [GPTSimpleVectorIndex, ComposableGraph] = index_storage[
|
|
|
|
index: [GPTSimpleVectorIndex, ComposableGraph] = index_storage[
|
|
|
|
user_id
|
|
|
|
user_id
|
|
|
|
].get_index_or_throw()
|
|
|
|
].get_index_or_throw()
|
|
|
@ -334,8 +337,14 @@ class Index_handler:
|
|
|
|
]
|
|
|
|
]
|
|
|
|
llm_predictor = LLMPredictor(llm=OpenAI(model_name="text-davinci-003"))
|
|
|
|
llm_predictor = LLMPredictor(llm=OpenAI(model_name="text-davinci-003"))
|
|
|
|
embedding_model = OpenAIEmbedding()
|
|
|
|
embedding_model = OpenAIEmbedding()
|
|
|
|
tree_index = GPTTreeIndex(documents=documents, llm_predictor=llm_predictor, embed_model=embedding_model)
|
|
|
|
tree_index = GPTTreeIndex(
|
|
|
|
await self.usage_service.update_usage(llm_predictor.last_token_usage+embedding_model.last_token_usage)
|
|
|
|
documents=documents,
|
|
|
|
|
|
|
|
llm_predictor=llm_predictor,
|
|
|
|
|
|
|
|
embed_model=embedding_model,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
await self.usage_service.update_usage(
|
|
|
|
|
|
|
|
llm_predictor.last_token_usage + embedding_model.last_token_usage
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Now we have a list of tree indexes, we can compose them
|
|
|
|
# Now we have a list of tree indexes, we can compose them
|
|
|
|
if not name:
|
|
|
|
if not name:
|
|
|
@ -358,7 +367,9 @@ class Index_handler:
|
|
|
|
|
|
|
|
|
|
|
|
embedding_model = OpenAIEmbedding()
|
|
|
|
embedding_model = OpenAIEmbedding()
|
|
|
|
# Add everything into a simple vector index
|
|
|
|
# Add everything into a simple vector index
|
|
|
|
simple_index = GPTSimpleVectorIndex(documents=documents, embed_model=embedding_model)
|
|
|
|
simple_index = GPTSimpleVectorIndex(
|
|
|
|
|
|
|
|
documents=documents, embed_model=embedding_model
|
|
|
|
|
|
|
|
)
|
|
|
|
await self.usage_service.update_usage(embedding_model.last_token_usage)
|
|
|
|
await self.usage_service.update_usage(embedding_model.last_token_usage)
|
|
|
|
|
|
|
|
|
|
|
|
if not name:
|
|
|
|
if not name:
|
|
|
@ -425,7 +436,7 @@ class Index_handler:
|
|
|
|
response_mode,
|
|
|
|
response_mode,
|
|
|
|
nodes,
|
|
|
|
nodes,
|
|
|
|
llm_predictor,
|
|
|
|
llm_predictor,
|
|
|
|
embedding_model
|
|
|
|
embedding_model,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
print("The last token usage was ", llm_predictor.last_token_usage)
|
|
|
|
print("The last token usage was ", llm_predictor.last_token_usage)
|
|
|
|