code: from llama_index.chat_engine.types import StreamingAgentChatResponse
  import streamlit as st
  from llama_index import SimpleDirectoryReader, VectorStoreIndex
  
  
  # TODO: this is caching the resource globally, not per-session
  # Each user session should have their own index
  @st.cache_resource(show_spinner="Indexing documents...")
  def build_index(files):
      documents = SimpleDirectoryReader(input_files=files).load_data()
      return VectorStoreIndex.from_documents(documents)
  
  
  def handle_stream(root, stream: StreamingAgentChatResponse):
      text = ""
      root.markdown("Thinking...")
      for token in stream.response_gen:
          text += token
          root.markdown(text)
      return text
  
apis: llama_index.VectorStoreIndex.from_documents llama_index.SimpleDirectoryReader
extract_api: [((270, 325), 'streamlit.cache_resource', 'st.cache_resource', ([], {'show_spinner': '"""Indexing documents..."""'}), "(show_spinner='Indexing documents...')\n", (287, 325), True, 'import streamlit as st\n'), ((430, 472), 'llama_index.VectorStoreIndex.from_documents', 'VectorStoreIndex.from_documents', (['documents'], {}), '(documents)\n', (461, 472), False, 'from llama_index import SimpleDirectoryReader, VectorStoreIndex\n'), ((366, 406), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', ([], {'input_files': 'files'}), '(input_files=files)\n', (387, 406), False, 'from llama_index import SimpleDirectoryReader, VectorStoreIndex\n')]