Spaces:
Sleeping
Sleeping
Create index_news.py
Browse files- index_news.py +18 -0
index_news.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os, config
|
2 |
+
|
3 |
+
# from llama_index import GPTSimpleVectorIndex, SimpleDirectoryReader
|
4 |
+
# new version replaces GPTSimpleVectorIndex with GPTVectorStoreIndex
|
5 |
+
|
6 |
+
from llama_index import GPTVectorStoreIndex, SimpleDirectoryReader
|
7 |
+
|
8 |
+
os.environ['OPENAI_API_KEY'] = config.OPENAI_API_KEY
|
9 |
+
|
10 |
+
documents = SimpleDirectoryReader('articles').load_data()
|
11 |
+
|
12 |
+
index = GPTVectorStoreIndex.from_documents(documents)
|
13 |
+
|
14 |
+
# llama index 0.6 replaces index.save_to_disk() with index.storage_context.persist()
|
15 |
+
# json files will be stored in a storage/ directory instead of index_new.json
|
16 |
+
# index.save_to_disk('index_news.json')
|
17 |
+
|
18 |
+
index.storage_context.persist()
|