forked from hackingthemarkets/financial-news-llama-index
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_news.py
28 lines (18 loc) · 914 Bytes
/
query_news.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
import os, config
from llama_index import StorageContext, load_index_from_storage
os.environ['OPENAI_API_KEY'] = config.OPENAI_API_KEY
# new version of llama index uses StorageContext instead of load_from_disk
# index = GPTSimpleVectorIndex.load_from_disk('index_news.json')
storage_context = StorageContext.from_defaults(persist_dir="./storage")
index = load_index_from_storage(storage_context)
# new version of llama index uses query_engine.query()
query_engine = index.as_query_engine()
response = query_engine.query("What are some near-term risks to Nvidia?")
print(response)
# questions on current trends
# response = query_engine.query("What is Microsoft working on in AI?")
# print(response)
# response = query_engine.query("Tell me about Google's new supercomputer.")
# print(response)
# response = query_engine.query("Why is the price of Taiwan Semiconductor stock dropping?")
# print(response)