code: from llama_index import (
      VectorStoreIndex,
      SimpleDirectoryReader,
      load_index_from_storage,
      StorageContext,
      Prompt,
  )
  from agenta import post, FloatParam, TextParam
  import os
  
  
  def ingest():
      if not os.path.exists("./storage"):
          documents = SimpleDirectoryReader("data").load_data()
          index = VectorStoreIndex.from_documents(documents)
          index.storage_context.persist()
      else:
          storage_context = StorageContext.from_defaults(persist_dir="./storage")
          # rebuild storage context
          index = load_index_from_storage(storage_context)
      return index
  
  
  default_prompt = (
      "We have provided context information below. \n"
      "---------------------\n"
      "{context_str}"
      "\n---------------------\n"
      "Given this information, please answer the question: {query_str}\n"
  )
  
  
  @post
  def query(question: str, prompt: TextParam = default_prompt) -> str:
      index = ingest()
  
      QA_TEMPLATE = Prompt(prompt)
      #
      query_engine = index.as_query_engine(text_qa_template=QA_TEMPLATE)
      response = query_engine.query(question)
      return str(response)
  
apis: llama_index.VectorStoreIndex.from_documents llama_index.StorageContext.from_defaults llama_index.SimpleDirectoryReader llama_index.Prompt llama_index.load_index_from_storage
extract_api: [((957, 971), 'llama_index.Prompt', 'Prompt', (['prompt'], {}), '(prompt)\n', (963, 971), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader, load_index_from_storage, StorageContext, Prompt\n'), ((222, 249), 'os.path.exists', 'os.path.exists', (['"""./storage"""'], {}), "('./storage')\n", (236, 249), False, 'import os\n'), ((329, 371), 'llama_index.VectorStoreIndex.from_documents', 'VectorStoreIndex.from_documents', (['documents'], {}), '(documents)\n', (360, 371), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader, load_index_from_storage, StorageContext, Prompt\n'), ((448, 501), 'llama_index.StorageContext.from_defaults', 'StorageContext.from_defaults', ([], {'persist_dir': '"""./storage"""'}), "(persist_dir='./storage')\n", (476, 501), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader, load_index_from_storage, StorageContext, Prompt\n'), ((552, 592), 'llama_index.load_index_from_storage', 'load_index_from_storage', (['storage_context'], {}), '(storage_context)\n', (575, 592), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader, load_index_from_storage, StorageContext, Prompt\n'), ((271, 300), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', (['"""data"""'], {}), "('data')\n", (292, 300), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader, load_index_from_storage, StorageContext, Prompt\n')]