code: import os
  import streamlit as st
  import openai
  
  from core.pipeline_builder import build_query_pipeline
  from core.index_builder.inquiry_index_builder import load_inquiry_index
  from core.index_builder.act_index_builder import (
      load_act_index,
      load_act_enforcement_index,
  )
  from core.utils import draw_dag
  from llama_index.embeddings.openai import OpenAIEmbedding
  from llama_index.core import Settings
  
  import llama_index.core
  
  os.environ["OPENAI_API_KEY"] = st.secrets.openai_key
  
  import phoenix as px
  
  px.launch_app()
  import llama_index.core
  
  llama_index.core.set_global_handler("arize_phoenix")
  
  embed_model = OpenAIEmbedding(
      model="text-embedding-3-small",
  )
  Settings.embed_model = embed_model
  
  st.set_page_config(
      page_title="ICT Construction Chatbot",
      page_icon="👷",
      layout="centered",
      initial_sidebar_state="auto",
      menu_items=None,
  )
  openai.api_key = st.secrets.openai_key
  st.title("ICT 건설 컨설턴트, powered by Wordbricks 👷💬")
  
  if "messages" not in st.session_state.keys():  # Initialize the chat messages history
      st.session_state.messages = [
          {
              "role": "assistant",
              "content": "궁금한 사항을 물어보세요. ICT 건설에 대한 전문가봇이 답변해드립니다.",
          }
      ]
  
  
  @st.cache_resource(show_spinner=False)
  def load_indexes():
      with st.spinner(text="데이터를 로딩중 입니다. 잠시만 기다려주세요."):
          inquiry_index = load_inquiry_index()
          act_index = load_act_index()
          act_enforcement_index = load_act_enforcement_index()
          return {
              "inquiry": inquiry_index,
              "act": act_index,
              "act_enforcement": act_enforcement_index,
          }
  
  
  indexes = load_indexes()
  qp = build_query_pipeline(indexes)
  draw_dag(qp)
  
  if "query_pipeline" not in st.session_state.keys():  # Initialize the chat engine
      st.session_state.query_pipeline = qp
  
  if prompt := st.chat_input("질문"):  # 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("생각중..."):
              response = st.session_state.query_pipeline.run(query_str=prompt)
              st.write(str(response))
              message = {"role": "assistant", "content": str(response)}
              st.session_state.messages.append(message)  # Add response to message history
  
apis: llama_index.embeddings.openai.OpenAIEmbedding
extract_api: [((510, 525), 'phoenix.launch_app', 'px.launch_app', ([], {}), '()\n', (523, 525), True, 'import phoenix as px\n'), ((619, 666), 'llama_index.embeddings.openai.OpenAIEmbedding', 'OpenAIEmbedding', ([], {'model': '"""text-embedding-3-small"""'}), "(model='text-embedding-3-small')\n", (634, 666), False, 'from llama_index.embeddings.openai import OpenAIEmbedding\n'), ((710, 852), 'streamlit.set_page_config', 'st.set_page_config', ([], {'page_title': '"""ICT Construction Chatbot"""', 'page_icon': '"""👷"""', 'layout': '"""centered"""', 'initial_sidebar_state': '"""auto"""', 'menu_items': 'None'}), "(page_title='ICT Construction Chatbot', page_icon='👷',\n    layout='centered', initial_sidebar_state='auto', menu_items=None)\n", (728, 852), True, 'import streamlit as st\n'), ((911, 960), 'streamlit.title', 'st.title', (['"""ICT 건설 컨설턴트, powered by Wordbricks 👷💬"""'], {}), "('ICT 건설 컨설턴트, powered by Wordbricks 👷💬')\n", (919, 960), True, 'import streamlit as st\n'), ((1211, 1248), 'streamlit.cache_resource', 'st.cache_resource', ([], {'show_spinner': '(False)'}), '(show_spinner=False)\n', (1228, 1248), True, 'import streamlit as st\n'), ((1648, 1677), 'core.pipeline_builder.build_query_pipeline', 'build_query_pipeline', (['indexes'], {}), '(indexes)\n', (1668, 1677), False, 'from core.pipeline_builder import build_query_pipeline\n'), ((1678, 1690), 'core.utils.draw_dag', 'draw_dag', (['qp'], {}), '(qp)\n', (1686, 1690), False, 'from core.utils import draw_dag\n'), ((983, 1006), 'streamlit.session_state.keys', 'st.session_state.keys', ([], {}), '()\n', (1004, 1006), True, 'import streamlit as st\n'), ((1719, 1742), 'streamlit.session_state.keys', 'st.session_state.keys', ([], {}), '()\n', (1740, 1742), True, 'import streamlit as st\n'), ((1829, 1848), 'streamlit.chat_input', 'st.chat_input', (['"""질문"""'], {}), "('질문')\n", (1842, 1848), True, 'import streamlit as st\n'), ((1904, 1973), 'streamlit.session_state.messages.append', 'st.session_state.messages.append', (["{'role': 'user', 'content': prompt}"], {}), "({'role': 'user', 'content': prompt})\n", (1936, 1973), True, 'import streamlit as st\n'), ((1278, 1322), 'streamlit.spinner', 'st.spinner', ([], {'text': '"""데이터를 로딩중 입니다. 잠시만 기다려주세요."""'}), "(text='데이터를 로딩중 입니다. 잠시만 기다려주세요.')\n", (1288, 1322), True, 'import streamlit as st\n'), ((1348, 1368), 'core.index_builder.inquiry_index_builder.load_inquiry_index', 'load_inquiry_index', ([], {}), '()\n', (1366, 1368), False, 'from core.index_builder.inquiry_index_builder import load_inquiry_index\n'), ((1389, 1405), 'core.index_builder.act_index_builder.load_act_index', 'load_act_index', ([], {}), '()\n', (1403, 1405), False, 'from core.index_builder.act_index_builder import load_act_index, load_act_enforcement_index\n'), ((1438, 1466), 'core.index_builder.act_index_builder.load_act_enforcement_index', 'load_act_enforcement_index', ([], {}), '()\n', (1464, 1466), False, 'from core.index_builder.act_index_builder import load_act_index, load_act_enforcement_index\n'), ((2061, 2093), 'streamlit.chat_message', 'st.chat_message', (["message['role']"], {}), "(message['role'])\n", (2076, 2093), True, 'import streamlit as st\n'), ((2103, 2131), 'streamlit.write', 'st.write', (["message['content']"], {}), "(message['content'])\n", (2111, 2131), True, 'import streamlit as st\n'), ((2264, 2292), 'streamlit.chat_message', 'st.chat_message', (['"""assistant"""'], {}), "('assistant')\n", (2279, 2292), True, 'import streamlit as st\n'), ((2307, 2327), 'streamlit.spinner', 'st.spinner', (['"""생각중..."""'], {}), "('생각중...')\n", (2317, 2327), True, 'import streamlit as st\n'), ((2352, 2405), 'streamlit.session_state.query_pipeline.run', 'st.session_state.query_pipeline.run', ([], {'query_str': 'prompt'}), '(query_str=prompt)\n', (2387, 2405), True, 'import streamlit as st\n'), ((2524, 2565), 'streamlit.session_state.messages.append', 'st.session_state.messages.append', (['message'], {}), '(message)\n', (2556, 2565), True, 'import streamlit as st\n')]