-
Notifications
You must be signed in to change notification settings - Fork 0
/
poc_document_summary_index.py
63 lines (41 loc) · 1.73 KB
/
poc_document_summary_index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import argparse
import logging
import time
from llama_index import SimpleWebPageReader
import nest_asyncio
from document_summary_index import CustomDocumentSummaryIndex
from utils import time_since
import web_dataset as wds
openai_api_key = "dummy"
openai_api_base = "http://localhost:8000/v1"
def main():
start = time.time()
logging.basicConfig(level=logging.INFO)
args = get_args()
logging.debug(args)
# 非同期処理の有効化
nest_asyncio.apply()
document_summary_index = CustomDocumentSummaryIndex()
if args.build_index:
ds = wds.WebDocument("./document_list.csv", size=3)
documents = []
for doc_data in ds:
web_doc = SimpleWebPageReader(html_to_text=True).load_data([doc_data["url"]])
web_doc[0].doc_id = doc_data["doc_id"]
documents.extend(web_doc)
logging.info(f"Loaded {len(documents)} documents ...")
document_summary_index.from_documents(documents)
document_summary_index.persist()
document_summary_index.load()
document_summary_index.as_retriever()
logging.info(f"Querying document 1 ... {time_since(start)}")
logging.info(document_summary_index.query("Swarm Learning とは何ですか?"))
logging.info(f"Querying document 2 ... {time_since(start)}")
logging.info(document_summary_index.query("HPEの障害者雇用の取り組みについて教えてください。"))
logging.info(f"Done ... {time_since(start)}")
def get_args():
parser = argparse.ArgumentParser(description=""" This is great script! """)
parser.add_argument("-b", "--build-index", action="store_true", help="Use this flag to build index.")
return parser.parse_args()
if __name__ == "__main__":
main()