-
-
Save mirzap/18d97d43c4ed52b4d0e7ad774ef6ac35 to your computer and use it in GitHub Desktop.
Use LlamaIndex and GPT-3 to query customer insights
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import logging | |
import sys | |
import textwrap | |
from llama_index import ( | |
GPTKeywordTableIndex, | |
SimpleDirectoryReader, | |
LLMPredictor, | |
) | |
from langchain import OpenAI | |
if __name__ == "__main__": | |
logging.basicConfig(stream=sys.stdout, level=logging.CRITICAL) | |
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout)) | |
if not os.path.exists("index.json"): | |
documents = SimpleDirectoryReader("docs").load_data() | |
llm_predictor = LLMPredictor( | |
llm=OpenAI(temperature=0, | |
model_name="text-davinci-003", | |
max_tokens=2048) | |
) | |
index = GPTKeywordTableIndex(documents, llm_predictor=llm_predictor) | |
index.save_to_disk("index.json") | |
else: | |
index = GPTKeywordTableIndex.load_from_disk("index.json") | |
while True: | |
try: | |
prompt = input("What should I figure out? ") | |
response = index.query(prompt) | |
response = str(response).strip() | |
if not response: | |
continue | |
for line in textwrap.wrap(response, width=75): | |
print(line) | |
print("-----") | |
except KeyboardInterrupt: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment