BramLeo commited on
Commit
ecb0859
·
verified ·
1 Parent(s): d60f2e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -10,6 +10,7 @@ from llama_index.llms.llama_cpp import LlamaCPP
10
  from huggingface_hub import hf_hub_download
11
  from llama_index.core.llms import ChatMessage
12
  from llama_index.core.chat_engine.condense_plus_context import CondensePlusContextChatEngine
 
13
 
14
  # ===================================
15
  # 1️⃣ Fungsi untuk Membaca Google Spreadsheet
@@ -75,17 +76,18 @@ def initialize_index():
75
  # 🔹 Ambil teks dari Google Spreadsheet
76
  text_data = read_google_sheet()
77
 
78
- # 🔹 Konversi teks ke dalam format dokumen
79
- documents = [text_data]
 
80
 
81
  # 🔹 Proses data menjadi node untuk vektor embedding
82
  parser = SentenceSplitter(chunk_size=150, chunk_overlap=10)
83
- nodes = parser.get_nodes_from_documents(documents)
84
-
85
  # 🔹 Gunakan model embedding
86
  embedding = HuggingFaceEmbedding("sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2")
87
  Settings.embed_model = embedding
88
-
89
  # 🔹 Buat index vektor
90
  index = VectorStoreIndex(nodes)
91
  return index
 
10
  from huggingface_hub import hf_hub_download
11
  from llama_index.core.llms import ChatMessage
12
  from llama_index.core.chat_engine.condense_plus_context import CondensePlusContextChatEngine
13
+ from llama_index.core.schema import Document
14
 
15
  # ===================================
16
  # 1️⃣ Fungsi untuk Membaca Google Spreadsheet
 
76
  # 🔹 Ambil teks dari Google Spreadsheet
77
  text_data = read_google_sheet()
78
 
79
+ # 🔹 Konversi teks ke dalam format dokumen yang benar
80
+ document = Document(text=text_data) # 🔹 Ubah teks menjadi objek `Document`
81
+ documents = [document] # 🔹 Masukkan ke dalam list
82
 
83
  # 🔹 Proses data menjadi node untuk vektor embedding
84
  parser = SentenceSplitter(chunk_size=150, chunk_overlap=10)
85
+ nodes = parser.get_nodes_from_documents(documents) # ✅ Sekarang `documents` adalah list of `Document`
86
+
87
  # 🔹 Gunakan model embedding
88
  embedding = HuggingFaceEmbedding("sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2")
89
  Settings.embed_model = embedding
90
+
91
  # 🔹 Buat index vektor
92
  index = VectorStoreIndex(nodes)
93
  return index