code: from pathlib import Path
  from llama_index import GPTSimpleVectorIndex, download_loader
  import sys
  
  def load_document(file):
      RDFReader = download_loader("RDFReader")
      loader = RDFReader()
      return loader.load_data(file=Path(file))
  
  def query(index, prompt):
      print("PROMPT:", prompt)
      result = index.query(prompt)
      print("RESPONSE:")
      print(result.response)
  
  if __name__ == '__main__':
      RDF_FILE = 'docs.ttl'
      INDEX_FILE = 'docs.json'
  
      # live query - more expensive
      if sys.argv[1] == 'live':
          print("ENV: text-davinci")
          document = load_document(RDF_FILE)
          index = GPTSimpleVectorIndex(document)
          prompt = " ".join(sys.argv[2:])
          query(index, prompt)
  
      elif sys.argv[1] == 'save-index':
          print("Saving index to docs.json...")
          document = load_document(RDF_FILE)
          index = GPTSimpleVectorIndex(document)
          index.save_to_disk(INDEX_FILE)
      # query from ada embeddings - cheaper
      else:
          print("ENV: text-embedding-ada-002-v2")
          index = GPTSimpleVectorIndex.load_from_disk(INDEX_FILE)
          prompt = " ".join(sys.argv[1:])
          query(index, prompt)
  
apis: llama_index.GPTSimpleVectorIndex.load_from_disk llama_index.GPTSimpleVectorIndex llama_index.download_loader
extract_api: [((140, 168), 'llama_index.download_loader', 'download_loader', (['"""RDFReader"""'], {}), "('RDFReader')\n", (155, 168), False, 'from llama_index import GPTSimpleVectorIndex, download_loader\n'), ((620, 650), 'llama_index.GPTSimpleVectorIndex', 'GPTSimpleVectorIndex', (['document'], {}), '(document)\n', (640, 650), False, 'from llama_index import GPTSimpleVectorIndex, download_loader\n'), ((227, 237), 'pathlib.Path', 'Path', (['file'], {}), '(file)\n', (231, 237), False, 'from pathlib import Path\n'), ((864, 894), 'llama_index.GPTSimpleVectorIndex', 'GPTSimpleVectorIndex', (['document'], {}), '(document)\n', (884, 894), False, 'from llama_index import GPTSimpleVectorIndex, download_loader\n'), ((1050, 1097), 'llama_index.GPTSimpleVectorIndex.load_from_disk', 'GPTSimpleVectorIndex.load_from_disk', (['INDEX_FILE'], {}), '(INDEX_FILE)\n', (1085, 1097), False, 'from llama_index import GPTSimpleVectorIndex, download_loader\n')]