code: import time
  import os
  import streamlit as st
  import openai
  import logging
  import sys
  import llama_index
  from qdrant_client import QdrantClient
  from llama_index import VectorStoreIndex, ServiceContext
  from llama_index.llms import OpenAI
  from llama_index import SimpleDirectoryReader
  from llama_index.storage.storage_context import StorageContext
  from llama_index.vector_stores.qdrant import QdrantVectorStore
  from llama_index import set_global_service_context
  from llama_index.embeddings import VoyageEmbedding
  from qdrant_client.models import Distance, VectorParams
  
  version = "1.0.2"
  st.set_page_config(page_title=f"Courier v{version}", page_icon="🌎", layout="centered", initial_sidebar_state="auto", menu_items=None)
  st.title(f"Courier v{version}")
  
  # Set up logging and tracing via Arize Phoenix
  logging.basicConfig(stream=sys.stdout, level=logging.INFO)
  logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
  
  # Use Voyager Lite Embeddings
  model_name = "voyage-lite-01-instruct"
  
  voyage_api_key = os.environ.get("VOYAGE_API_KEY", "")
  
  embed_model = VoyageEmbedding(
      model_name=model_name, voyage_api_key=voyage_api_key
  )
  
  
  # Update Custom QA Template with Gaia Information
  if "messages" not in st.session_state.keys(): # Initialize the chat messages history
      st.session_state.messages = [
          {"role": "assistant", "content": "Hello, my name is Courier. I'm an Generative AI Assistant designed to help Proctor Academy students. Ask me anything about the Proctor Handbook or any current Proctor Academy staff."}
      ]
  
  openai.api_key = ""
  
  @st.cache_resource(show_spinner=False)
  def load_data():
      with st.spinner(text=f"Loading Courier v{version} ..."):
          docs = SimpleDirectoryReader(input_dir="./data", recursive=True).load_data()
          qdrant_client = QdrantClient(
              url="https://02aec354-4932-4062-9e00-422eacb506fc.us-east4-0.gcp.cloud.qdrant.io",
              api_key="",
          )
          qdrant_client.create_collection(collection_name="courierv52",vectors_config=VectorParams(size=1024, distance=Distance.EUCLID),)
          service_context = ServiceContext.from_defaults(embed_model=embed_model,llm=OpenAI(model="gpt-4", max_tokens=1500, temperature=0.5, system_prompt="Keep your answers technical and based on facts and do not hallucinate in responses. In addition, make sure all responses look natural, no Answer: or Query: in the response. Always attempt to query database."))
          set_global_service_context(service_context)
          vector_store = QdrantVectorStore(client=qdrant_client, collection_name="courierv52")
          storage_context = StorageContext.from_defaults(vector_store=vector_store)
          index = VectorStoreIndex.from_documents(
              docs, storage_context=storage_context, service_context=service_context,
          )
          return index
  
  index = load_data()
  
  if "chat_engine" not in st.session_state.keys(): # Initialize the chat engine
      st.session_state.chat_engine = index.as_chat_engine(streaming=True,chat_mode="condense_question",max_tokens=1500,verbose=True)
  
  if prompt := st.chat_input("Your question"): # Prompt for user input and save to chat history
      st.session_state.messages.append({"role": "user", "content": prompt})
  
  for message in st.session_state.messages: # Display the prior chat messages
      with st.chat_message(message["role"]):
          st.write(message["content"])
  
  # If last message is not from assistant, generate a new response
  if st.session_state.messages[-1]["role"] != "assistant":
          with st.chat_message("assistant"):
              res_box = st.empty()  # Placeholder for the response text
              with st.spinner("Thinking..."):
                  response = st.session_state.chat_engine.stream_chat(prompt)
                  full_response = ""
                  for token in response.response_gen:
                      full_response += "".join(token)
                      res_box.write(full_response)
                  message = {"role": "assistant", "content": response.response}
                  st.session_state.messages.append(message)
  
apis: llama_index.VectorStoreIndex.from_documents llama_index.vector_stores.qdrant.QdrantVectorStore llama_index.storage.storage_context.StorageContext.from_defaults llama_index.SimpleDirectoryReader llama_index.embeddings.VoyageEmbedding llama_index.llms.OpenAI llama_index.set_global_service_context
extract_api: [((585, 723), 'streamlit.set_page_config', 'st.set_page_config', ([], {'page_title': 'f"""Courier v{version}"""', 'page_icon': '"""🌎"""', 'layout': '"""centered"""', 'initial_sidebar_state': '"""auto"""', 'menu_items': 'None'}), "(page_title=f'Courier v{version}', page_icon='🌎', layout=\n    'centered', initial_sidebar_state='auto', menu_items=None)\n", (603, 723), True, 'import streamlit as st\n'), ((719, 750), 'streamlit.title', 'st.title', (['f"""Courier v{version}"""'], {}), "(f'Courier v{version}')\n", (727, 750), True, 'import streamlit as st\n'), ((799, 857), 'logging.basicConfig', 'logging.basicConfig', ([], {'stream': 'sys.stdout', 'level': 'logging.INFO'}), '(stream=sys.stdout, level=logging.INFO)\n', (818, 857), False, 'import logging\n'), ((1019, 1055), 'os.environ.get', 'os.environ.get', (['"""VOYAGE_API_KEY"""', '""""""'], {}), "('VOYAGE_API_KEY', '')\n", (1033, 1055), False, 'import os\n'), ((1071, 1140), 'llama_index.embeddings.VoyageEmbedding', 'VoyageEmbedding', ([], {'model_name': 'model_name', 'voyage_api_key': 'voyage_api_key'}), '(model_name=model_name, voyage_api_key=voyage_api_key)\n', (1086, 1140), False, 'from llama_index.embeddings import VoyageEmbedding\n'), ((1573, 1610), 'streamlit.cache_resource', 'st.cache_resource', ([], {'show_spinner': '(False)'}), '(show_spinner=False)\n', (1590, 1610), True, 'import streamlit as st\n'), ((889, 929), 'logging.StreamHandler', 'logging.StreamHandler', ([], {'stream': 'sys.stdout'}), '(stream=sys.stdout)\n', (910, 929), False, 'import logging\n'), ((1220, 1243), 'streamlit.session_state.keys', 'st.session_state.keys', ([], {}), '()\n', (1241, 1243), True, 'import streamlit as st\n'), ((2878, 2901), 'streamlit.session_state.keys', 'st.session_state.keys', ([], {}), '()\n', (2899, 2901), True, 'import streamlit as st\n'), ((3077, 3107), 'streamlit.chat_input', 'st.chat_input', (['"""Your question"""'], {}), "('Your question')\n", (3090, 3107), True, 'import streamlit as st\n'), ((3162, 3231), 'streamlit.session_state.messages.append', 'st.session_state.messages.append', (["{'role': 'user', 'content': prompt}"], {}), "({'role': 'user', 'content': prompt})\n", (3194, 3231), True, 'import streamlit as st\n'), ((858, 877), 'logging.getLogger', 'logging.getLogger', ([], {}), '()\n', (875, 877), False, 'import logging\n'), ((1637, 1687), 'streamlit.spinner', 'st.spinner', ([], {'text': 'f"""Loading Courier v{version} ..."""'}), "(text=f'Loading Courier v{version} ...')\n", (1647, 1687), True, 'import streamlit as st\n'), ((1798, 1915), 'qdrant_client.QdrantClient', 'QdrantClient', ([], {'url': '"""https://02aec354-4932-4062-9e00-422eacb506fc.us-east4-0.gcp.cloud.qdrant.io"""', 'api_key': '""""""'}), "(url=\n    'https://02aec354-4932-4062-9e00-422eacb506fc.us-east4-0.gcp.cloud.qdrant.io'\n    , api_key='')\n", (1810, 1915), False, 'from qdrant_client import QdrantClient\n'), ((2449, 2492), 'llama_index.set_global_service_context', 'set_global_service_context', (['service_context'], {}), '(service_context)\n', (2475, 2492), False, 'from llama_index import set_global_service_context\n'), ((2516, 2585), 'llama_index.vector_stores.qdrant.QdrantVectorStore', 'QdrantVectorStore', ([], {'client': 'qdrant_client', 'collection_name': '"""courierv52"""'}), "(client=qdrant_client, collection_name='courierv52')\n", (2533, 2585), False, 'from llama_index.vector_stores.qdrant import QdrantVectorStore\n'), ((2612, 2667), 'llama_index.storage.storage_context.StorageContext.from_defaults', 'StorageContext.from_defaults', ([], {'vector_store': 'vector_store'}), '(vector_store=vector_store)\n', (2640, 2667), False, 'from llama_index.storage.storage_context import StorageContext\n'), ((2684, 2791), 'llama_index.VectorStoreIndex.from_documents', 'VectorStoreIndex.from_documents', (['docs'], {'storage_context': 'storage_context', 'service_context': 'service_context'}), '(docs, storage_context=storage_context,\n    service_context=service_context)\n', (2715, 2791), False, 'from llama_index import VectorStoreIndex, ServiceContext\n'), ((3318, 3350), 'streamlit.chat_message', 'st.chat_message', (["message['role']"], {}), "(message['role'])\n", (3333, 3350), True, 'import streamlit as st\n'), ((3360, 3388), 'streamlit.write', 'st.write', (["message['content']"], {}), "(message['content'])\n", (3368, 3388), True, 'import streamlit as st\n'), ((3525, 3553), 'streamlit.chat_message', 'st.chat_message', (['"""assistant"""'], {}), "('assistant')\n", (3540, 3553), True, 'import streamlit as st\n'), ((3577, 3587), 'streamlit.empty', 'st.empty', ([], {}), '()\n', (3585, 3587), True, 'import streamlit as st\n'), ((3642, 3667), 'streamlit.spinner', 'st.spinner', (['"""Thinking..."""'], {}), "('Thinking...')\n", (3652, 3667), True, 'import streamlit as st\n'), ((3696, 3744), 'streamlit.session_state.chat_engine.stream_chat', 'st.session_state.chat_engine.stream_chat', (['prompt'], {}), '(prompt)\n', (3736, 3744), True, 'import streamlit as st\n'), ((4027, 4068), 'streamlit.session_state.messages.append', 'st.session_state.messages.append', (['message'], {}), '(message)\n', (4059, 4068), True, 'import streamlit as st\n'), ((1704, 1761), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', ([], {'input_dir': '"""./data"""', 'recursive': '(True)'}), "(input_dir='./data', recursive=True)\n", (1725, 1761), False, 'from llama_index import SimpleDirectoryReader\n'), ((2025, 2074), 'qdrant_client.models.VectorParams', 'VectorParams', ([], {'size': '(1024)', 'distance': 'Distance.EUCLID'}), '(size=1024, distance=Distance.EUCLID)\n', (2037, 2074), False, 'from qdrant_client.models import Distance, VectorParams\n'), ((2160, 2449), 'llama_index.llms.OpenAI', 'OpenAI', ([], {'model': '"""gpt-4"""', 'max_tokens': '(1500)', 'temperature': '(0.5)', 'system_prompt': '"""Keep your answers technical and based on facts and do not hallucinate in responses. In addition, make sure all responses look natural, no Answer: or Query: in the response. Always attempt to query database."""'}), "(model='gpt-4', max_tokens=1500, temperature=0.5, system_prompt=\n    'Keep your answers technical and based on facts and do not hallucinate in responses. In addition, make sure all responses look natural, no Answer: or Query: in the response. Always attempt to query database.'\n    )\n", (2166, 2449), False, 'from llama_index.llms import OpenAI\n')]