Spaces:
Sleeping
Sleeping
marcelo-castro-cardoso
commited on
Commit
•
a79dff1
1
Parent(s):
2df300a
deploy
Browse files- app.py +4 -4
- storage/default__vector_store.json +0 -0
- storage/docstore.json +0 -0
- storage/graph_store.json +1 -0
- storage/image__vector_store.json +1 -0
- storage/index_store.json +1 -0
app.py
CHANGED
@@ -33,15 +33,15 @@ text_splitter = SentenceSplitter(
|
|
33 |
tokenizer=tiktoken.encoding_for_model("gpt-3.5-turbo").encode
|
34 |
)
|
35 |
|
|
|
|
|
|
|
36 |
# verifica se a pasta storage existe localmente
|
37 |
PERSIST_DIR = "./storage"
|
38 |
if not os.path.exists(PERSIST_DIR):
|
39 |
# caso não exista lê os documentos da pasta e cria um índice
|
40 |
documents = SimpleDirectoryReader("./data").load_data()
|
41 |
|
42 |
-
# cria um serviço de contexto para configurar a criação do indice
|
43 |
-
service_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model, text_splitter=text_splitter)
|
44 |
-
|
45 |
# cria um indice utilizando um contexto de serviços
|
46 |
index = VectorStoreIndex.from_documents(documents, service_context=service_context)
|
47 |
|
@@ -50,7 +50,7 @@ if not os.path.exists(PERSIST_DIR):
|
|
50 |
else:
|
51 |
# caso a pasta exista, lê o índice existente
|
52 |
storage_context = StorageContext.from_defaults(persist_dir=PERSIST_DIR)
|
53 |
-
index = load_index_from_storage(storage_context)
|
54 |
|
55 |
# define um prompt
|
56 |
text_qa_template = PromptTemplate('''
|
|
|
33 |
tokenizer=tiktoken.encoding_for_model("gpt-3.5-turbo").encode
|
34 |
)
|
35 |
|
36 |
+
# cria um serviço de contexto para configurar a criação do indice
|
37 |
+
service_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model, text_splitter=text_splitter)
|
38 |
+
|
39 |
# verifica se a pasta storage existe localmente
|
40 |
PERSIST_DIR = "./storage"
|
41 |
if not os.path.exists(PERSIST_DIR):
|
42 |
# caso não exista lê os documentos da pasta e cria um índice
|
43 |
documents = SimpleDirectoryReader("./data").load_data()
|
44 |
|
|
|
|
|
|
|
45 |
# cria um indice utilizando um contexto de serviços
|
46 |
index = VectorStoreIndex.from_documents(documents, service_context=service_context)
|
47 |
|
|
|
50 |
else:
|
51 |
# caso a pasta exista, lê o índice existente
|
52 |
storage_context = StorageContext.from_defaults(persist_dir=PERSIST_DIR)
|
53 |
+
index = load_index_from_storage(storage_context, service_context=service_context)
|
54 |
|
55 |
# define um prompt
|
56 |
text_qa_template = PromptTemplate('''
|
storage/default__vector_store.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
storage/docstore.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
storage/graph_store.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"graph_dict": {}}
|
storage/image__vector_store.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"embedding_dict": {}, "text_id_to_ref_doc_id": {}, "metadata_dict": {}}
|
storage/index_store.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"index_store/data": {"a7a9eb12-e1ac-4cba-87c8-602a34181c4c": {"__type__": "vector_store", "__data__": "{\"index_id\": \"a7a9eb12-e1ac-4cba-87c8-602a34181c4c\", \"summary\": null, \"nodes_dict\": {\"4919b298-1b7c-4470-a901-36f09a02b53d\": \"4919b298-1b7c-4470-a901-36f09a02b53d\", \"019da7cd-7cf0-42d6-b613-c01ebbe6a289\": \"019da7cd-7cf0-42d6-b613-c01ebbe6a289\", \"c2708a9c-5e57-4191-a519-e801f26cd279\": \"c2708a9c-5e57-4191-a519-e801f26cd279\", \"552931d3-3811-4179-8bff-4f8c84e2162d\": \"552931d3-3811-4179-8bff-4f8c84e2162d\", \"a24d6f39-ebb2-4314-967f-bc1cb7d77daf\": \"a24d6f39-ebb2-4314-967f-bc1cb7d77daf\", \"b0c718f2-6f3e-4be6-b974-573f2e3a44f8\": \"b0c718f2-6f3e-4be6-b974-573f2e3a44f8\", \"d951070b-2a90-4b81-a8b9-df48d61d8c23\": \"d951070b-2a90-4b81-a8b9-df48d61d8c23\", \"80baf0e6-273c-43d7-8ebb-c28477f29dc0\": \"80baf0e6-273c-43d7-8ebb-c28477f29dc0\", \"cf942a4e-2832-4ccf-ba6d-ed01d49e60d2\": \"cf942a4e-2832-4ccf-ba6d-ed01d49e60d2\", \"b7c84b60-0dd9-44d4-9f9a-5ef2570bec7f\": \"b7c84b60-0dd9-44d4-9f9a-5ef2570bec7f\", \"98e11407-92c3-4702-8afb-8131c91c992c\": \"98e11407-92c3-4702-8afb-8131c91c992c\", \"66699631-c95f-4ba9-b591-06307b173430\": \"66699631-c95f-4ba9-b591-06307b173430\", \"860fcb36-0f9c-4ba6-bc1c-6faff3aff8e6\": \"860fcb36-0f9c-4ba6-bc1c-6faff3aff8e6\", \"295e9342-e854-4ed8-9605-2745645f29a8\": \"295e9342-e854-4ed8-9605-2745645f29a8\", \"d245cc2a-7aac-47fa-8cbd-6e85bba048e6\": \"d245cc2a-7aac-47fa-8cbd-6e85bba048e6\", \"21932082-06af-4fea-9a6b-34046c3917aa\": \"21932082-06af-4fea-9a6b-34046c3917aa\", \"e051bc4e-5b21-4f0b-8359-e31a361b64e4\": \"e051bc4e-5b21-4f0b-8359-e31a361b64e4\", \"07e1a0d5-6b25-4d9d-b8e3-37d1a0047a02\": \"07e1a0d5-6b25-4d9d-b8e3-37d1a0047a02\", \"0ee91c33-5180-4604-a3b4-3b24266c50cd\": \"0ee91c33-5180-4604-a3b4-3b24266c50cd\", \"fdef88a2-e496-41f8-ae17-eb7d7135493e\": \"fdef88a2-e496-41f8-ae17-eb7d7135493e\"}, \"doc_id_dict\": {}, \"embeddings_dict\": {}}"}}}
|