code: from llama_index import SimpleDirectoryReader, GPTListIndex, readers, GPTSimpleVectorIndex, LLMPredictor, PromptHelper
  from langchain import OpenAI
  import os
  
  def construct_index(directory_path):
      # set maximum input size
      max_input_size = 4096
      # set number of output tokens
      num_outputs = 2000
      # set maximum chunk overlap
      max_chunk_overlap = 20
      # set chunk size limit
      chunk_size_limit = 600 
  
      # define LLM
      llm_predictor = LLMPredictor(llm=OpenAI(temperature=0.5, model_name="text-davinci-003", max_tokens=num_outputs))
      prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
   
      documents = SimpleDirectoryReader(directory_path).load_data()
      
      index = GPTSimpleVectorIndex(
          documents, llm_predictor=llm_predictor, prompt_helper=prompt_helper
      )
  
      index.save_to_disk('index.json')
  
      return index
  
  def ask_ai(query):
      index = GPTSimpleVectorIndex.load_from_disk('./Talking_Buddy/index.json')
      response = index.query(query, response_mode="compact")
      return response.response
          
          
          
  os.environ["OPENAI_API_KEY"] = "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"
  construct_index("./Talking_Buddy/data")
  
apis: llama_index.PromptHelper llama_index.GPTSimpleVectorIndex llama_index.GPTSimpleVectorIndex.load_from_disk llama_index.SimpleDirectoryReader
extract_api: [((577, 676), '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', (589, 676), False, 'from llama_index import SimpleDirectoryReader, GPTListIndex, readers, GPTSimpleVectorIndex, LLMPredictor, PromptHelper\n'), ((758, 852), 'llama_index.GPTSimpleVectorIndex', 'GPTSimpleVectorIndex', (['documents'], {'llm_predictor': 'llm_predictor', 'prompt_helper': 'prompt_helper'}), '(documents, llm_predictor=llm_predictor, prompt_helper=\n    prompt_helper)\n', (778, 852), False, 'from llama_index import SimpleDirectoryReader, GPTListIndex, readers, GPTSimpleVectorIndex, LLMPredictor, PromptHelper\n'), ((950, 1015), 'llama_index.GPTSimpleVectorIndex.load_from_disk', 'GPTSimpleVectorIndex.load_from_disk', (['"""./Talking_Buddy/index.json"""'], {}), "('./Talking_Buddy/index.json')\n", (985, 1015), False, 'from llama_index import SimpleDirectoryReader, GPTListIndex, readers, GPTSimpleVectorIndex, LLMPredictor, PromptHelper\n'), ((477, 555), 'langchain.OpenAI', 'OpenAI', ([], {'temperature': '(0.5)', 'model_name': '"""text-davinci-003"""', 'max_tokens': 'num_outputs'}), "(temperature=0.5, model_name='text-davinci-003', max_tokens=num_outputs)\n", (483, 555), False, 'from langchain import OpenAI\n'), ((691, 728), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', (['directory_path'], {}), '(directory_path)\n', (712, 728), False, 'from llama_index import SimpleDirectoryReader, GPTListIndex, readers, GPTSimpleVectorIndex, LLMPredictor, PromptHelper\n')]