code: import os
  import openai
  import logging
  import sys
  import llama_index
  from llama_index import (
      VectorStoreIndex,
      SimpleDirectoryReader,
      load_index_from_storage,
      StorageContext,
      LLMPredictor,
      PromptHelper,
      ServiceContext,
  )
  from llama_index.llms import OpenAI
  import chromadb
  from llama_index.vector_stores import ChromaVectorStore
  from llama_index.embeddings import OpenAIEmbedding
  from trulens_eval import Tru
  from llama_index.query_engine import CitationQueryEngine
  import json
  
  openai.api_key = os.environ["OPENAI_API_KEY"]
  
  
  CUSTOM_QUERY = "First greet yourself and Send me a summary of the file. In your summary, make sure  to mention the file location and the data name, also to have 10 bullet points. Each bullet point should be on a new row. Try to incorporate few key points from all the text. Do it step by step:"
  list_of_indices = []
  tru = Tru()
  tru.reset_database()
  
  logging.basicConfig(stream=sys.stdout, level=logging.INFO)
  logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
  
  
  def create_index(directory, unique_folder_id):
      llm = OpenAI(temperature=0.1, model="gpt-4-vision-preview", max_tokens=512)
      prompt_helper = PromptHelper(
          context_window=4096,
          num_output=256,
          chunk_overlap_ratio=0.1,
          chunk_size_limit=None,
      )
  
      service_context = ServiceContext.from_defaults(llm=llm, prompt_helper=prompt_helper)
  
      documents = SimpleDirectoryReader(input_dir=directory).load_data()
  
      index = VectorStoreIndex.from_documents(documents, service_context=service_context)
      index.set_index_id(create_dynamic_vector_ids(unique_folder_id))
      index.storage_context.persist(create_dynamic_storage_contexts(unique_folder_id))
      a = index.index_struct_cls
      # Chroma vector store for easy indexing and retrieval
  
      db = chromadb.PersistentClient(path="./chroma_db")
  
      chroma_collection = db.get_or_create_collection("investment_ai")
      chroma_vector_store = ChromaVectorStore(chroma_collection=chroma_collection)
  
      chroma_storage_context = StorageContext.from_defaults(
          vector_store=chroma_vector_store
      )
  
      chroma_index = VectorStoreIndex.from_documents(
          documents,
          storage_context=chroma_storage_context,
          service_context=service_context,
      )
      print(chroma_index.storage_context.graph_store.get)
      return index
  
  
  def auto_summarization(unique_folder_id):
      dynamic_storage_context = create_dynamic_storage_contexts(unique_folder_id)
      dynamic_vector_id = create_dynamic_vector_ids(unique_folder_id)
      storage_context = StorageContext.from_defaults(persist_dir=dynamic_storage_context)
      # load index
      index = load_index_from_storage(storage_context, index_id=dynamic_vector_id)
      query_engine = index.as_query_engine(response_mode="compact", verbose=True)
      response = query_engine.query(CUSTOM_QUERY)
      return str(response.response)
  
      return str(response.response)
  
  
  def ask_question(query, unique_folder_id):
      dynamic_storage_context = create_dynamic_storage_contexts(unique_folder_id)
      dynamic_vector_id = create_dynamic_vector_ids(unique_folder_id)
      # rebuild storage context
      storage_context = StorageContext.from_defaults(persist_dir=dynamic_storage_context)
      # load index
      index = llama_index.indices.loading.load_index_from_storage(
          storage_context, index_id=dynamic_vector_id
      )
      query_engine = CitationQueryEngine.from_args(
          index, similarity_top_k=3, citation_chunk_size=512, streaming=True
      )
      response_stream = query_engine.query(
          "When a question is asked always and if it is a greeting please answer accordingly.If question is not about given data, say you only answer about given data. If the question is about the given data please eloborate more on details and answer human-like according to this question: "
          + query
      )
      return response_stream
  
  
  def create_dynamic_storage_contexts(unique_folder_id):
      return "./storage_" + str(unique_folder_id)
  
  
  def create_dynamic_vector_ids(unique_folder_id):
      return "vector_index_" + str(unique_folder_id)
  
apis: llama_index.VectorStoreIndex.from_documents llama_index.query_engine.CitationQueryEngine.from_args llama_index.ServiceContext.from_defaults llama_index.vector_stores.ChromaVectorStore llama_index.StorageContext.from_defaults llama_index.SimpleDirectoryReader llama_index.llms.OpenAI llama_index.indices.loading.load_index_from_storage llama_index.load_index_from_storage llama_index.PromptHelper
extract_api: [((879, 884), 'trulens_eval.Tru', 'Tru', ([], {}), '()\n', (882, 884), False, 'from trulens_eval import Tru\n'), ((907, 965), 'logging.basicConfig', 'logging.basicConfig', ([], {'stream': 'sys.stdout', 'level': 'logging.INFO'}), '(stream=sys.stdout, level=logging.INFO)\n', (926, 965), False, 'import logging\n'), ((997, 1037), 'logging.StreamHandler', 'logging.StreamHandler', ([], {'stream': 'sys.stdout'}), '(stream=sys.stdout)\n', (1018, 1037), False, 'import logging\n'), ((1098, 1167), 'llama_index.llms.OpenAI', 'OpenAI', ([], {'temperature': '(0.1)', 'model': '"""gpt-4-vision-preview"""', 'max_tokens': '(512)'}), "(temperature=0.1, model='gpt-4-vision-preview', max_tokens=512)\n", (1104, 1167), False, 'from llama_index.llms import OpenAI\n'), ((1188, 1289), 'llama_index.PromptHelper', 'PromptHelper', ([], {'context_window': '(4096)', 'num_output': '(256)', 'chunk_overlap_ratio': '(0.1)', 'chunk_size_limit': 'None'}), '(context_window=4096, num_output=256, chunk_overlap_ratio=0.1,\n    chunk_size_limit=None)\n', (1200, 1289), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader, load_index_from_storage, StorageContext, LLMPredictor, PromptHelper, ServiceContext\n'), ((1348, 1414), 'llama_index.ServiceContext.from_defaults', 'ServiceContext.from_defaults', ([], {'llm': 'llm', 'prompt_helper': 'prompt_helper'}), '(llm=llm, prompt_helper=prompt_helper)\n', (1376, 1414), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader, load_index_from_storage, StorageContext, LLMPredictor, PromptHelper, ServiceContext\n'), ((1500, 1575), 'llama_index.VectorStoreIndex.from_documents', 'VectorStoreIndex.from_documents', (['documents'], {'service_context': 'service_context'}), '(documents, service_context=service_context)\n', (1531, 1575), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader, load_index_from_storage, StorageContext, LLMPredictor, PromptHelper, ServiceContext\n'), ((1828, 1873), 'chromadb.PersistentClient', 'chromadb.PersistentClient', ([], {'path': '"""./chroma_db"""'}), "(path='./chroma_db')\n", (1853, 1873), False, 'import chromadb\n'), ((1970, 2024), 'llama_index.vector_stores.ChromaVectorStore', 'ChromaVectorStore', ([], {'chroma_collection': 'chroma_collection'}), '(chroma_collection=chroma_collection)\n', (1987, 2024), False, 'from llama_index.vector_stores import ChromaVectorStore\n'), ((2055, 2117), 'llama_index.StorageContext.from_defaults', 'StorageContext.from_defaults', ([], {'vector_store': 'chroma_vector_store'}), '(vector_store=chroma_vector_store)\n', (2083, 2117), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader, load_index_from_storage, StorageContext, LLMPredictor, PromptHelper, ServiceContext\n'), ((2152, 2272), 'llama_index.VectorStoreIndex.from_documents', 'VectorStoreIndex.from_documents', (['documents'], {'storage_context': 'chroma_storage_context', 'service_context': 'service_context'}), '(documents, storage_context=\n    chroma_storage_context, service_context=service_context)\n', (2183, 2272), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader, load_index_from_storage, StorageContext, LLMPredictor, PromptHelper, ServiceContext\n'), ((2586, 2651), 'llama_index.StorageContext.from_defaults', 'StorageContext.from_defaults', ([], {'persist_dir': 'dynamic_storage_context'}), '(persist_dir=dynamic_storage_context)\n', (2614, 2651), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader, load_index_from_storage, StorageContext, LLMPredictor, PromptHelper, ServiceContext\n'), ((2681, 2749), 'llama_index.load_index_from_storage', 'load_index_from_storage', (['storage_context'], {'index_id': 'dynamic_vector_id'}), '(storage_context, index_id=dynamic_vector_id)\n', (2704, 2749), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader, load_index_from_storage, StorageContext, LLMPredictor, PromptHelper, ServiceContext\n'), ((3192, 3257), 'llama_index.StorageContext.from_defaults', 'StorageContext.from_defaults', ([], {'persist_dir': 'dynamic_storage_context'}), '(persist_dir=dynamic_storage_context)\n', (3220, 3257), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader, load_index_from_storage, StorageContext, LLMPredictor, PromptHelper, ServiceContext\n'), ((3287, 3387), 'llama_index.indices.loading.load_index_from_storage', 'llama_index.indices.loading.load_index_from_storage', (['storage_context'], {'index_id': 'dynamic_vector_id'}), '(storage_context,\n    index_id=dynamic_vector_id)\n', (3338, 3387), False, 'import llama_index\n'), ((3417, 3518), 'llama_index.query_engine.CitationQueryEngine.from_args', 'CitationQueryEngine.from_args', (['index'], {'similarity_top_k': '(3)', 'citation_chunk_size': '(512)', 'streaming': '(True)'}), '(index, similarity_top_k=3,\n    citation_chunk_size=512, streaming=True)\n', (3446, 3518), False, 'from llama_index.query_engine import CitationQueryEngine\n'), ((966, 985), 'logging.getLogger', 'logging.getLogger', ([], {}), '()\n', (983, 985), False, 'import logging\n'), ((1432, 1474), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', ([], {'input_dir': 'directory'}), '(input_dir=directory)\n', (1453, 1474), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader, load_index_from_storage, StorageContext, LLMPredictor, PromptHelper, ServiceContext\n')]