code: import streamlit as st
  from llama_index import VectorStoreIndex, ServiceContext, Document
  from llama_index.llms import OpenAI
  import openai
  from llama_index import SimpleDirectoryReader
  
  st.set_page_config(page_title="Converse com Resoluções do Bacen, powered by LlamaIndex", page_icon="🦙", layout="centered", initial_sidebar_state="auto", menu_items=None)
  
  ############### reduce top margin ################
  st.markdown(
          """
  <style>
      .css-1y4p8pa {
          padding-top: 0px;
      }
  </style>
  """,
          unsafe_allow_html=True,
      )
  
  ############### hidde hamburguer menu ################
  st.markdown(""" <style>
  #MainMenu {visibility: hidden;}
  footer {visibility: hidden;}
  </style> """, unsafe_allow_html=True)
  
  openai.api_key = st.secrets.openai_key
  st.header("Converse 💬 com as Resoluções 4.966 e 352 do Banco Central e outras relacionadas, powered by LlamaIndex 🦙")
  st.info("Código disponível neste [repositório Github](https://github.com/mvpalheta/4966_LLM)", icon="💡")
           
  if "messages" not in st.session_state.keys(): # Initialize the chat messages history
      st.session_state.messages = [
          {"role": "assistant", "content": "Me pergunte algo relacionado às Resoluções 4.966 e 352 do Banco Central!"}
      ]
  
  @st.cache_resource(show_spinner=False, ttl="30min")
  def load_data():
      with st.spinner(text="Loading and indexing the docs – hang tight! This should take 1-2 minutes."):
          reader = SimpleDirectoryReader(input_dir="./data", recursive=True)
          docs = reader.load_data()
          service_context = ServiceContext.from_defaults(llm=OpenAI(model="gpt-3.5-turbo", temperature=0.5))
          index = VectorStoreIndex.from_documents(docs, service_context=service_context)
          return index
  
  index = load_data()
  chat_engine = index.as_chat_engine(chat_mode="condense_question", verbose=True)
  
  if prompt := st.chat_input("Sua pergunta"): # 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"):
          with st.spinner("Pensando..."):
              response = chat_engine.chat(prompt)
              st.write(response.response)
              message = {"role": "assistant", "content": response.response}
              st.session_state.messages.append(message) # Add response to message history
  
  
  
apis: llama_index.VectorStoreIndex.from_documents llama_index.llms.OpenAI llama_index.SimpleDirectoryReader
extract_api: [((187, 366), 'streamlit.set_page_config', 'st.set_page_config', ([], {'page_title': '"""Converse com Resoluções do Bacen, powered by LlamaIndex"""', 'page_icon': '"""🦙"""', 'layout': '"""centered"""', 'initial_sidebar_state': '"""auto"""', 'menu_items': 'None'}), "(page_title=\n    'Converse com Resoluções do Bacen, powered by LlamaIndex', page_icon=\n    '🦙', layout='centered', initial_sidebar_state='auto', menu_items=None)\n", (205, 366), True, 'import streamlit as st\n'), ((409, 531), 'streamlit.markdown', 'st.markdown', (['"""\n<style>\n    .css-1y4p8pa {\n        padding-top: 0px;\n    }\n</style>\n"""'], {'unsafe_allow_html': '(True)'}), '(\n    """\n<style>\n    .css-1y4p8pa {\n        padding-top: 0px;\n    }\n</style>\n"""\n    , unsafe_allow_html=True)\n', (420, 531), True, 'import streamlit as st\n'), ((601, 733), 'streamlit.markdown', 'st.markdown', (['""" <style>\n#MainMenu {visibility: hidden;}\nfooter {visibility: hidden;}\n</style> """'], {'unsafe_allow_html': '(True)'}), '(\n    """ <style>\n#MainMenu {visibility: hidden;}\nfooter {visibility: hidden;}\n</style> """\n    , unsafe_allow_html=True)\n', (612, 733), True, 'import streamlit as st\n'), ((764, 891), 'streamlit.header', 'st.header', (['"""Converse 💬 com as Resoluções 4.966 e 352 do Banco Central e outras relacionadas, powered by LlamaIndex 🦙"""'], {}), "(\n    'Converse 💬 com as Resoluções 4.966 e 352 do Banco Central e outras relacionadas, powered by LlamaIndex 🦙'\n    )\n", (773, 891), True, 'import streamlit as st\n'), ((882, 996), 'streamlit.info', 'st.info', (['"""Código disponível neste [repositório Github](https://github.com/mvpalheta/4966_LLM)"""'], {'icon': '"""💡"""'}), "(\n    'Código disponível neste [repositório Github](https://github.com/mvpalheta/4966_LLM)'\n    , icon='💡')\n", (889, 996), True, 'import streamlit as st\n'), ((1241, 1291), 'streamlit.cache_resource', 'st.cache_resource', ([], {'show_spinner': '(False)', 'ttl': '"""30min"""'}), "(show_spinner=False, ttl='30min')\n", (1258, 1291), True, 'import streamlit as st\n'), ((1018, 1041), 'streamlit.session_state.keys', 'st.session_state.keys', ([], {}), '()\n', (1039, 1041), True, 'import streamlit as st\n'), ((1851, 1880), 'streamlit.chat_input', 'st.chat_input', (['"""Sua pergunta"""'], {}), "('Sua pergunta')\n", (1864, 1880), True, 'import streamlit as st\n'), ((1935, 2004), 'streamlit.session_state.messages.append', 'st.session_state.messages.append', (["{'role': 'user', 'content': prompt}"], {}), "({'role': 'user', 'content': prompt})\n", (1967, 2004), True, 'import streamlit as st\n'), ((1318, 1420), 'streamlit.spinner', 'st.spinner', ([], {'text': '"""Loading and indexing the docs – hang tight! This should take 1-2 minutes."""'}), "(text=\n    'Loading and indexing the docs – hang tight! This should take 1-2 minutes.'\n    )\n", (1328, 1420), True, 'import streamlit as st\n'), ((1429, 1486), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', ([], {'input_dir': '"""./data"""', 'recursive': '(True)'}), "(input_dir='./data', recursive=True)\n", (1450, 1486), False, 'from llama_index import SimpleDirectoryReader\n'), ((1644, 1714), 'llama_index.VectorStoreIndex.from_documents', 'VectorStoreIndex.from_documents', (['docs'], {'service_context': 'service_context'}), '(docs, service_context=service_context)\n', (1675, 1714), False, 'from llama_index import VectorStoreIndex, ServiceContext, Document\n'), ((2091, 2123), 'streamlit.chat_message', 'st.chat_message', (["message['role']"], {}), "(message['role'])\n", (2106, 2123), True, 'import streamlit as st\n'), ((2133, 2161), 'streamlit.write', 'st.write', (["message['content']"], {}), "(message['content'])\n", (2141, 2161), True, 'import streamlit as st\n'), ((2302, 2330), 'streamlit.chat_message', 'st.chat_message', (['"""assistant"""'], {}), "('assistant')\n", (2317, 2330), True, 'import streamlit as st\n'), ((2345, 2370), 'streamlit.spinner', 'st.spinner', (['"""Pensando..."""'], {}), "('Pensando...')\n", (2355, 2370), True, 'import streamlit as st\n'), ((2432, 2459), 'streamlit.write', 'st.write', (['response.response'], {}), '(response.response)\n', (2440, 2459), True, 'import streamlit as st\n'), ((2546, 2587), 'streamlit.session_state.messages.append', 'st.session_state.messages.append', (['message'], {}), '(message)\n', (2578, 2587), True, 'import streamlit as st\n'), ((1580, 1626), 'llama_index.llms.OpenAI', 'OpenAI', ([], {'model': '"""gpt-3.5-turbo"""', 'temperature': '(0.5)'}), "(model='gpt-3.5-turbo', temperature=0.5)\n", (1586, 1626), False, 'from llama_index.llms import OpenAI\n')]