-
Notifications
You must be signed in to change notification settings - Fork 0
/
starter.py
23 lines (17 loc) · 645 Bytes
/
starter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from pathlib import Path
from llama_index import VectorStoreIndex, download_loader
from dotenv import load_dotenv
import os
import openai
load_dotenv()
openai_api_key = os.getenv('OPENAI_API_KEY')
if openai_api_key is None:
raise ValueError("OpenAI API key not found.")
openai.api_key = openai_api_key
SimpleCSVReader = download_loader("SimpleCSVReader")
loader = SimpleCSVReader(encoding="utf-8")
documents = loader.load_data(file=Path('./restaurants.csv'))
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()
response = query_engine.query("Best Italian Restaurants In Atlanta?")
print(response)