code: import os
  from llama_index import (
      VectorStoreIndex,
      SimpleDirectoryReader,
      StorageContext,
      load_index_from_storage,
  )
  
  BOT_NAME = os.environ["BOT_NAME"]
  
  
  def construct_index(directory_data, directory_index, force_reload=False):
      # check if storage already exists
      if not os.path.exists(directory_index) or force_reload:
          print(f'Creating new index using {directory_data}')
          # load the documents and create the index
          documents = SimpleDirectoryReader(directory_data).load_data()
          index = VectorStoreIndex.from_documents(documents)
          # store it for later
          index.storage_context.persist(persist_dir=directory_index)
          print(f'Storing new index to {directory_index}')
      else:
          # load the existing index
          print(f'Loading existing index from {directory_index}')
          storage_context = StorageContext.from_defaults(persist_dir=directory_index)
          index = load_index_from_storage(storage_context)
      
      return index
  
  def query(question, index):
      query_engine = index.as_query_engine()
      response = query_engine.query(question)
      return response
  
  def ask(bot_name):
      index = construct_index(directory_data=f'data/{bot_name}', directory_index=f'storage/{bot_name}')
      while True:
          question = input("What do you want to know?")
          response = query(question=question, index=index)
          print(f"{bot_name} says: {response}")
  
  if __name__ == '__main__':
      ask(BOT_NAME)
apis: llama_index.VectorStoreIndex.from_documents llama_index.StorageContext.from_defaults llama_index.load_index_from_storage llama_index.SimpleDirectoryReader
extract_api: [((541, 583), 'llama_index.VectorStoreIndex.from_documents', 'VectorStoreIndex.from_documents', (['documents'], {}), '(documents)\n', (572, 583), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader, StorageContext, load_index_from_storage\n'), ((871, 928), 'llama_index.StorageContext.from_defaults', 'StorageContext.from_defaults', ([], {'persist_dir': 'directory_index'}), '(persist_dir=directory_index)\n', (899, 928), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader, StorageContext, load_index_from_storage\n'), ((945, 985), 'llama_index.load_index_from_storage', 'load_index_from_storage', (['storage_context'], {}), '(storage_context)\n', (968, 985), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader, StorageContext, load_index_from_storage\n'), ((296, 327), 'os.path.exists', 'os.path.exists', (['directory_index'], {}), '(directory_index)\n', (310, 327), False, 'import os\n'), ((475, 512), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', (['directory_data'], {}), '(directory_data)\n', (496, 512), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader, StorageContext, load_index_from_storage\n')]