code: # Ref https://github.com/amrrs/QABot-LangChain/blob/main/Q%26A_Bot_with_Llama_Index_and_LangChain.ipynb
  
  #from gpt_index import SimpleDirectoryReader, GPTListIndex, GPTSimpleVectorIndex, LLMPredictor, PromptHelper
  from langchain import OpenAI
  from llama_index import SimpleDirectoryReader, LangchainEmbedding, GPTListIndex,GPTSimpleVectorIndex, PromptHelper
  from llama_index import LLMPredictor, ServiceContext
  import sys
  import os
  
  
  def construct_index(directory_path):
      # set maximum input size
      max_input_size = 4096
      # set number of output tokens
      num_outputs = 256
      # set maximum chunk overlap
      max_chunk_overlap = 20
      # set chunk size limit
      chunk_size_limit = 600
  
      prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
  
      # define LLM
      llm_predictor = LLMPredictor(llm=OpenAI(temperature=0, model_name="text-davinci-002", max_tokens=num_outputs))
  
      documents = SimpleDirectoryReader(directory_path).load_data()
  
      service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor)
      index_obj = GPTSimpleVectorIndex.from_documents(documents, service_context=service_context)
  
      index_obj.save_to_disk('model/index.json')
  
      return index_obj
  
  
  def ask_bot(input_index='model/index.json'):
      index_obj = GPTSimpleVectorIndex.load_from_disk(input_index)
      while True:
          query = input('What do you want to ask the bot?   \n')
          if query == "nothing":
              return
          response = index_obj.query(query, response_mode="compact")
          print("\nBot says: \n\n" + response.response + "\n\n\n")
  
  
  index = construct_index("data/")
  
  ask_bot('model/index.json')
  
apis: llama_index.GPTSimpleVectorIndex.from_documents llama_index.GPTSimpleVectorIndex.load_from_disk llama_index.ServiceContext.from_defaults llama_index.SimpleDirectoryReader llama_index.PromptHelper
extract_api: [((716, 815), 'llama_index.PromptHelper', 'PromptHelper', (['max_input_size', 'num_outputs', 'max_chunk_overlap'], {'chunk_size_limit': 'chunk_size_limit'}), '(max_input_size, num_outputs, max_chunk_overlap,\n    chunk_size_limit=chunk_size_limit)\n', (728, 815), False, 'from llama_index import SimpleDirectoryReader, LangchainEmbedding, GPTListIndex, GPTSimpleVectorIndex, PromptHelper\n'), ((1035, 1092), 'llama_index.ServiceContext.from_defaults', 'ServiceContext.from_defaults', ([], {'llm_predictor': 'llm_predictor'}), '(llm_predictor=llm_predictor)\n', (1063, 1092), False, 'from llama_index import LLMPredictor, ServiceContext\n'), ((1109, 1188), 'llama_index.GPTSimpleVectorIndex.from_documents', 'GPTSimpleVectorIndex.from_documents', (['documents'], {'service_context': 'service_context'}), '(documents, service_context=service_context)\n', (1144, 1188), False, 'from llama_index import SimpleDirectoryReader, LangchainEmbedding, GPTListIndex, GPTSimpleVectorIndex, PromptHelper\n'), ((1322, 1370), 'llama_index.GPTSimpleVectorIndex.load_from_disk', 'GPTSimpleVectorIndex.load_from_disk', (['input_index'], {}), '(input_index)\n', (1357, 1370), False, 'from llama_index import SimpleDirectoryReader, LangchainEmbedding, GPTListIndex, GPTSimpleVectorIndex, PromptHelper\n'), ((867, 943), 'langchain.OpenAI', 'OpenAI', ([], {'temperature': '(0)', 'model_name': '"""text-davinci-002"""', 'max_tokens': 'num_outputs'}), "(temperature=0, model_name='text-davinci-002', max_tokens=num_outputs)\n", (873, 943), False, 'from langchain import OpenAI\n'), ((962, 999), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', (['directory_path'], {}), '(directory_path)\n', (983, 999), False, 'from llama_index import SimpleDirectoryReader, LangchainEmbedding, GPTListIndex, GPTSimpleVectorIndex, PromptHelper\n')]