code: import streamlit as st
  import sqlite3
  import streamlit_antd_components as sac
  import pandas as pd
  import os
  
  from langchain.embeddings.openai import OpenAIEmbeddings
  from langchain.document_loaders import UnstructuredFileLoader
  from langchain.text_splitter import CharacterTextSplitter
  from langchain.vectorstores import LanceDB
  from basecode.authenticate import return_api_key
  from langchain.docstore.document import Document
  import lancedb
  import configparser
  import ast
  import json
  
  from services.aws import SecretsManager
  from openai import OpenAI
  
  
  class ConfigHandler:
      def __init__(self):
          self.config = configparser.ConfigParser()
          self.config.read("config.ini")
  
      def get_config_values(self, section, key):
          value = self.config.get(section, key)
          try:
              # Try converting the string value to a Python data structure
              return ast.literal_eval(value)
          except (SyntaxError, ValueError):
              # If not a data structure, return the plain string
              return value
  
  
  config_handler = ConfigHandler()
  TCH = config_handler.get_config_values("constants", "TCH")
  STU = config_handler.get_config_values("constants", "STU")
  SA = config_handler.get_config_values("constants", "SA")
  AD = config_handler.get_config_values("constants", "AD")
  
  
  # Create or check for the 'database' directory in the current working directory
  cwd = os.getcwd()
  WORKING_DIRECTORY = os.path.join(cwd, "database")
  
  if not os.path.exists(WORKING_DIRECTORY):
      os.makedirs(WORKING_DIRECTORY)
  
  # Check application environment => GCC or Streamlit
  ENV = config_handler.get_config_values("constants", "prototype_env")
  
  if ENV == "GCC":
      if SecretsManager.get_secret("sql_ext_path") == "None":
          WORKING_DATABASE = os.path.join(
              WORKING_DIRECTORY, SecretsManager.get_secret("default_db")
          )
      else:
          WORKING_DATABASE = SecretsManager.get_secret("sql_ext_path")
  else:
      if st.secrets["sql_ext_path"] == "None":
          WORKING_DATABASE = os.path.join(WORKING_DIRECTORY, st.secrets["default_db"])
      else:
          WORKING_DATABASE = st.secrets["sql_ext_path"]
  
  # os.environ["OPENAI_API_KEY"] = return_api_key()
  lancedb_path = os.path.join(WORKING_DIRECTORY, "lancedb")
  db = lancedb.connect(lancedb_path)
  
  
  def fetch_vectorstores_with_usernames():
      conn = sqlite3.connect(WORKING_DATABASE)
      cursor = conn.cursor()
  
      query = """
      SELECT 
          Vector_Stores.vs_id, 
          Subject.subject_name,
          Topic.topic_name, 
          Vector_Stores.vectorstore_name, 
          Users.username, 
          Vector_Stores.sharing_enabled
      FROM Vector_Stores
      JOIN Users ON Vector_Stores.user_id = Users.user_id
      LEFT JOIN Subject ON Vector_Stores.subject = Subject.id
      LEFT JOIN Topic ON Vector_Stores.topic = Topic.id;
      """
  
      cursor.execute(query)
      data = cursor.fetchall()
      conn.close()
      return data
  
  
  def display_vectorstores():
      data = fetch_vectorstores_with_usernames()
      df = pd.DataFrame(
          data,
          columns=[
              "vs_id",
              "subject_name",
              "topic_name",
              "vectorstore_name",
              "username",
              "sharing_enabled",
          ],
      )
  
      # Convert the 'sharing_enabled' values
      df["sharing_enabled"] = df["sharing_enabled"].apply(lambda x: "✔" if x == 1 else "")
  
      st.dataframe(
          df,
          use_container_width=True,
          column_order=[
              "vs_id",
              "subject_name",
              "topic_name",
              "vectorstore_name",
              "username",
              "sharing_enabled",
          ],
      )
  
  
  def fetch_all_files():
      """
      Fetch all files either shared or based on user type
      """
      conn = sqlite3.connect(WORKING_DATABASE)
      cursor = conn.cursor()
  
      # Construct the SQL query with JOINs for Subject, Topic, and Users tables
      if st.session_state.user["profile_id"] == "SA":
          cursor.execute(
              """
              SELECT Files.file_id, Files.file_name, Subject.subject_name, Topic.topic_name, Users.username 
              FROM Files 
              JOIN Subject ON Files.subject = Subject.id 
              JOIN Topic ON Files.topic = Topic.id 
              JOIN Users ON Files.user_id = Users.user_id
          """
          )
      else:
          cursor.execute(
              """
              SELECT Files.file_id, Files.file_name, Subject.subject_name, Topic.topic_name, Users.username 
              FROM Files 
              JOIN Subject ON Files.subject = Subject.id 
              JOIN Topic ON Files.topic = Topic.id 
              JOIN Users ON Files.user_id = Users.user_id 
              WHERE Files.sharing_enabled = 1
          """
          )
  
      files = cursor.fetchall()
      formatted_files = [f"({file[0]}) {file[1]} ({file[4]})" for file in files]
  
      conn.close()
      return formatted_files
  
  
  def fetch_file_data(file_id):
      """
      Fetch file data given a file id
      """
      conn = sqlite3.connect(WORKING_DATABASE)
      cursor = conn.cursor()
  
      cursor.execute("SELECT data, metadata FROM Files WHERE file_id = ?", (file_id,))
      data = cursor.fetchone()
  
      conn.close()
      if data:
          return data[0], data[1]
      else:
          return None, None
  
  
  def insert_topic(org_id, topic_name):
      conn = sqlite3.connect(WORKING_DATABASE)
      cursor = conn.cursor()
  
      try:
          cursor.execute(
              "INSERT INTO Topic (org_id, topic_name) VALUES (?, ?);",
              (org_id, topic_name),
          )
          conn.commit()
          return True  # Indicates successful insertion
      except sqlite3.IntegrityError:
          # IntegrityError occurs if topic_name is not unique within the org
          return False  # Indicates topic_name is not unique within the org
      finally:
          conn.close()
  
  
  def insert_subject(org_id, subject_name):
      conn = sqlite3.connect(WORKING_DATABASE)
      cursor = conn.cursor()
  
      try:
          cursor.execute(
              "INSERT INTO Subject (org_id, subject_name) VALUES (?, ?);",
              (org_id, subject_name),
          )
          conn.commit()
          return True  # Indicates successful insertion
      except sqlite3.IntegrityError:
          # IntegrityError occurs if subject_name is not unique within the org
          return False  # Indicates subject_name is not unique within the org
      finally:
          conn.close()
  
  
  def select_organization():
      with sqlite3.connect(WORKING_DATABASE) as conn:
          cursor = conn.cursor()
  
          # Org selection
          org_query = "SELECT org_name FROM Organizations"
          cursor.execute(org_query)
          orgs = cursor.fetchall()
          org_names = [org[0] for org in orgs]
  
          # Use a Streamlit selectbox to choose an organization
          selected_org_name = st.selectbox("Select an organization:", org_names)
  
          # Retrieve the org_id for the selected organization
          cursor.execute(
              "SELECT org_id FROM Organizations WHERE org_name = ?;", (selected_org_name,)
          )
          result = cursor.fetchone()
  
          if result:
              org_id = result[0]
              st.write(f"The org_id for {selected_org_name} is {org_id}.")
              return org_id
          else:
              st.write(f"Organization '{selected_org_name}' not found in the database.")
              return None
  
  
  def fetch_subjects_by_org(org_id):
      conn = sqlite3.connect(WORKING_DATABASE)
      cursor = conn.cursor()
  
      # Check if the user is a super_admin (org_id is 0)
      if org_id == 0:
          cursor.execute("SELECT * FROM Subject;")
      else:
          cursor.execute("SELECT * FROM Subject WHERE org_id = ?;", (org_id,))
  
      subjects = cursor.fetchall()
      conn.close()
      return subjects
  
  
  def fetch_topics_by_org(org_id):
      conn = sqlite3.connect(WORKING_DATABASE)
      cursor = conn.cursor()
  
      # Check if the user is a super_admin (org_id is 0)
      if org_id == 0:
          cursor.execute("SELECT * FROM Topic;")
      else:
          cursor.execute("SELECT * FROM Topic WHERE org_id = ?;", (org_id,))
  
      topics = cursor.fetchall()
      conn.close()
      return topics
  
  
  def split_docs(file_path, meta):
      # def split_meta_docs(file, source, tch_code):
      loader = UnstructuredFileLoader(file_path)
      documents = loader.load()
      text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
      docs = text_splitter.split_documents(documents)
      metadata = {"source": meta}
      for doc in docs:
          doc.metadata.update(metadata)
      return docs
  
  
  def create_lancedb_table(embeddings, meta, table_name):
      lancedb_path = os.path.join(WORKING_DIRECTORY, "lancedb")
      # LanceDB connection
      db = lancedb.connect(lancedb_path)
  
      client = OpenAI()
      response = client.embeddings.create(
          input="Query Unsuccessful", model="text-embedding-3-small"
      )
  
      table = db.create_table(
          f"{table_name}",
          data=[
              {
                  "vector": response.data[0].embedding,
                  "text": "Query Unsuccessful",
                  "id": "1",
                  "source": f"{meta}",
              }
          ],
          mode="overwrite",
      )
      return table
  
  
  def save_to_vectorstores(
      vs, vstore_input_name, subject, topic, username, share_resource=False
  ):
      conn = sqlite3.connect(WORKING_DATABASE)
      cursor = conn.cursor()
  
      # Fetch the user's details
      cursor.execute("SELECT user_id FROM Users WHERE username = ?", (username,))
      user_details = cursor.fetchone()
  
      if not user_details:
          st.error("Error: User not found.")
          return
  
      user_id = user_details[0]
  
      # If Vector_Store instance exists in session state, then serialize and save
      # vs is the documents in json format and vstore_input_name is the name of the table and vectorstore
      if vs:
          try:
              cursor.execute(
                  "SELECT 1 FROM Vector_Stores WHERE vectorstore_name LIKE ? AND user_id = ?",
                  (f"%{vstore_input_name}%", user_id),
              )
              exists = cursor.fetchone()
  
              if exists:
                  st.error(
                      "Error: An entry with the same vectorstore_name and user_id already exists."
                  )
                  return
  
              if subject is None:
                  st.error("Error: Subject is missing.")
                  return
  
              if topic is None:
                  st.error("Error: Topic is missing.")
                  return
  
              # Get the subject and topic IDs
              cursor.execute("SELECT id FROM Subject WHERE subject_name = ?", (subject,))
              subject_id = cursor.fetchone()[0]
  
              cursor.execute("SELECT id FROM Topic WHERE topic_name = ?", (topic,))
              topic_id = cursor.fetchone()[0]
  
              # Insert the new row
              cursor.execute(
                  """
              INSERT INTO Vector_Stores (vectorstore_name, documents, user_id, subject, topic, sharing_enabled)
              VALUES (?, ?, ?, ?, ?, ?)
              """,
                  (vstore_input_name, vs, user_id, subject_id, topic_id, share_resource),
              )
  
              conn.commit()
              conn.close()
  
          except Exception as e:
              st.error(f"Error in storing documents and vectorstore: {e}")
              return
  
  
  def document_to_dict(doc):
      # Assuming 'doc' has 'page_content' and 'metadata' attributes
      return {"page_content": doc.page_content, "metadata": doc.metadata}
  
  
  def dict_to_document(doc_dict):
      # Create a Document object from the dictionary
      # Adjust this according to how your Document class is defined
      return Document(
          page_content=doc_dict["page_content"], metadata=doc_dict["metadata"]
      )
  
  
  def create_vectorstore():
      os.environ["OPENAI_API_KEY"] = return_api_key()
      full_docs = []
      st.subheader("Enter the topic and subject for your knowledge base")
      embeddings = OpenAIEmbeddings()
      if st.session_state.user["profile_id"] == SA:
          org_id = select_organization()
          if org_id is None:
              return
      else:
          org_id = st.session_state.user["org_id"]
  
      # Fetch all available subjects
      subjects = fetch_subjects_by_org(st.session_state.user["org_id"])
      subject_names = [
          sub[2] for sub in subjects
      ]  # Assuming index 2 holds the subject_name
      selected_subject = st.selectbox(
          "Select an existing subject or type a new one:",
          options=subject_names + ["New Subject"],
      )
  
      if selected_subject == "New Subject":
          subject = st.text_input("Please enter the new subject name:", max_chars=30)
          if subject:
              insert_subject(org_id, subject)
  
      else:
          subject = selected_subject
  
      # Fetch all available topics
      topics = fetch_topics_by_org(st.session_state.user["org_id"])
      topic_names = [
          topic[2] for topic in topics
      ]  # Assuming index 2 holds the topic_name
      selected_topic = st.selectbox(
          "Select an existing topic or type a new one:",
          options=topic_names + ["New Topic"],
      )
  
      if selected_topic == "New Topic":
          topic = st.text_input("Please enter the new topic name:", max_chars=30)
          if topic:
              insert_topic(org_id, topic)
      else:
          topic = selected_topic
  
      vectorstore_input = st.text_input(
          "Please type in a name for your knowledge base:", max_chars=20
      )
      vs_name = vectorstore_input + f"_({st.session_state.user['username']})"
      share_resource = st.checkbox(
          "Share this resource", value=True
      )  # <-- Added this line
  
      # Show the current build of files for the latest database
      st.subheader("Select one or more files to build your knowledge base")
      files = fetch_all_files()
      if files:
          selected_files = sac.transfer(
              items=files,
              label=None,
              index=None,
              titles=["Uploaded files", "Select files for KB"],
              format_func="title",
              width="100%",
              height=None,
              search=True,
              pagination=False,
              oneway=False,
              reload=True,
              disabled=False,
              return_index=False,
          )
  
          # Alert to confirm the creation of knowledge base
          st.warning(
              "Building your knowledge base will take some time. Please be patient."
          )
  
          build = sac.buttons(
              [
                  dict(
                      label="Build VectorStore", icon="check-circle-fill", color="green"
                  ),
                  dict(label="Cancel", icon="x-circle-fill", color="red"),
              ],
              label=None,
              index=1,
              format_func="title",
              align="center",
              position="top",
              size="default",
              direction="horizontal",
              shape="round",
              type="default",
              compact=False,
              return_index=False,
          )
  
          if build == "Build VectorStore" and selected_files:
              for s_file in selected_files:
                  file_id = int(s_file.split("(", 1)[1].split(")", 1)[0])
                  file_data, meta = fetch_file_data(file_id)
                  docs = split_docs(file_data, meta)
                  full_docs.extend(docs)
              # convert full_docs to json to store in sqlite
              full_docs_dicts = [document_to_dict(doc) for doc in full_docs]
              docs_json = json.dumps(full_docs_dicts)
  
              create_lancedb_table(embeddings, meta, vs_name)
              save_to_vectorstores(
                  docs_json,
                  vs_name,
                  subject,
                  topic,
                  st.session_state.user["username"],
                  share_resource,
              )  # Passing the share_resource to the function
              st.success("Knowledge Base loaded")
  
      else:
          st.write("No files found in the database.")
  
  
  def load_vectorstore(documents, table_name):
      retrieved_docs_dicts = json.loads(documents)
      retrieved_docs = [dict_to_document(doc_dict) for doc_dict in retrieved_docs_dicts]
      vs = LanceDB.from_documents(
          retrieved_docs,
          OpenAIEmbeddings(openai_api_key=return_api_key()),
          connection=db.open_table(f"{table_name}"),
      )
      return vs
  
  
  def delete_lancedb_table(table_name):
      lancedb_path = os.path.join(WORKING_DIRECTORY, "lancedb")
      # LanceDB connection
      db = lancedb.connect(lancedb_path)
      db.drop_table(f"{table_name}")
  
  
  def fetch_vectorstores_by_user_id(user_id):
      conn = sqlite3.connect(WORKING_DATABASE)
      cursor = conn.cursor()
  
      # Fetch vectorstores based on user_id
      cursor.execute(
          "SELECT vectorstore_name FROM Vector_Stores WHERE user_id = ?;", (user_id,)
      )
  
      vectorstores = cursor.fetchall()
      conn.close()
      return vectorstores
  
  
  def delete_vectorstores():
      st.subheader("Delete VectorStores in Database:")
      user_vectorstores = fetch_vectorstores_by_user_id(st.session_state.user["id"])
  
      if user_vectorstores:
          vectorstore_names = [vs[0] for vs in user_vectorstores]
          selected_vectorstores = st.multiselect(
              "Select vectorstores to delete:", options=vectorstore_names
          )
          confirm_delete = st.checkbox(
              "I understand that this action cannot be undone.", value=False
          )
  
          if st.button("Delete VectorStore"):
              if confirm_delete and selected_vectorstores:
                  delete_vectorstores_from_db(
                      selected_vectorstores,
                      st.session_state.user["id"],
                      st.session_state.user["profile_id"],
                  )
                  st.success(f"Deleted {len(selected_vectorstores)} vectorstores.")
              else:
                  st.warning("Please confirm the deletion action.")
      else:
          st.write("No vectorstores found in the database.")
  
  
  def delete_vectorstores_from_db(vectorstore_names, user_id, profile):
      conn = sqlite3.connect(WORKING_DATABASE)
      cursor = conn.cursor()
  
      for vectorstore_name in vectorstore_names:
          if profile in ["SA", "AD"]:
              # Delete the corresponding LanceDB table
              delete_lancedb_table(vectorstore_name)
  
              # Delete vectorstore irrespective of the user_id associated with them
              cursor.execute(
                  "DELETE FROM Vector_Stores WHERE vectorstore_name=?;",
                  (vectorstore_name,),
              )
          else:
              # Delete the corresponding LanceDB table
              delete_lancedb_table(vectorstore_name)
  
              # Delete only if the user_id matches
              cursor.execute(
                  "DELETE FROM Vector_Stores WHERE vectorstore_name=? AND user_id=?;",
                  (vectorstore_name, user_id),
              )
  
              # Check if the row was affected
              if cursor.rowcount == 0:
                  st.error(
                      f"Unable to delete vectorstore '{vectorstore_name}' that is not owned by you."
                  )
  
      conn.commit()  # Commit the changes
      conn.close()  # Close the connection
  
apis: lancedb.connect
extract_api: [((1396, 1407), 'os.getcwd', 'os.getcwd', ([], {}), '()\n', (1405, 1407), False, 'import os\n'), ((1428, 1457), 'os.path.join', 'os.path.join', (['cwd', '"""database"""'], {}), "(cwd, 'database')\n", (1440, 1457), False, 'import os\n'), ((2203, 2245), 'os.path.join', 'os.path.join', (['WORKING_DIRECTORY', '"""lancedb"""'], {}), "(WORKING_DIRECTORY, 'lancedb')\n", (2215, 2245), False, 'import os\n'), ((2251, 2280), 'lancedb.connect', 'lancedb.connect', (['lancedb_path'], {}), '(lancedb_path)\n', (2266, 2280), False, 'import lancedb\n'), ((1466, 1499), 'os.path.exists', 'os.path.exists', (['WORKING_DIRECTORY'], {}), '(WORKING_DIRECTORY)\n', (1480, 1499), False, 'import os\n'), ((1505, 1535), 'os.makedirs', 'os.makedirs', (['WORKING_DIRECTORY'], {}), '(WORKING_DIRECTORY)\n', (1516, 1535), False, 'import os\n'), ((2335, 2368), 'sqlite3.connect', 'sqlite3.connect', (['WORKING_DATABASE'], {}), '(WORKING_DATABASE)\n', (2350, 2368), False, 'import sqlite3\n'), ((2993, 3115), 'pandas.DataFrame', 'pd.DataFrame', (['data'], {'columns': "['vs_id', 'subject_name', 'topic_name', 'vectorstore_name', 'username',\n    'sharing_enabled']"}), "(data, columns=['vs_id', 'subject_name', 'topic_name',\n    'vectorstore_name', 'username', 'sharing_enabled'])\n", (3005, 3115), True, 'import pandas as pd\n'), ((3356, 3511), 'streamlit.dataframe', 'st.dataframe', (['df'], {'use_container_width': '(True)', 'column_order': "['vs_id', 'subject_name', 'topic_name', 'vectorstore_name', 'username',\n    'sharing_enabled']"}), "(df, use_container_width=True, column_order=['vs_id',\n    'subject_name', 'topic_name', 'vectorstore_name', 'username',\n    'sharing_enabled'])\n", (3368, 3511), True, 'import streamlit as st\n'), ((3726, 3759), 'sqlite3.connect', 'sqlite3.connect', (['WORKING_DATABASE'], {}), '(WORKING_DATABASE)\n', (3741, 3759), False, 'import sqlite3\n'), ((4933, 4966), 'sqlite3.connect', 'sqlite3.connect', (['WORKING_DATABASE'], {}), '(WORKING_DATABASE)\n', (4948, 4966), False, 'import sqlite3\n'), ((5259, 5292), 'sqlite3.connect', 'sqlite3.connect', (['WORKING_DATABASE'], {}), '(WORKING_DATABASE)\n', (5274, 5292), False, 'import sqlite3\n'), ((5816, 5849), 'sqlite3.connect', 'sqlite3.connect', (['WORKING_DATABASE'], {}), '(WORKING_DATABASE)\n', (5831, 5849), False, 'import sqlite3\n'), ((7318, 7351), 'sqlite3.connect', 'sqlite3.connect', (['WORKING_DATABASE'], {}), '(WORKING_DATABASE)\n', (7333, 7351), False, 'import sqlite3\n'), ((7708, 7741), 'sqlite3.connect', 'sqlite3.connect', (['WORKING_DATABASE'], {}), '(WORKING_DATABASE)\n', (7723, 7741), False, 'import sqlite3\n'), ((8143, 8176), 'langchain.document_loaders.UnstructuredFileLoader', 'UnstructuredFileLoader', (['file_path'], {}), '(file_path)\n', (8165, 8176), False, 'from langchain.document_loaders import UnstructuredFileLoader\n'), ((8227, 8282), 'langchain.text_splitter.CharacterTextSplitter', 'CharacterTextSplitter', ([], {'chunk_size': '(1000)', 'chunk_overlap': '(0)'}), '(chunk_size=1000, chunk_overlap=0)\n', (8248, 8282), False, 'from langchain.text_splitter import CharacterTextSplitter\n'), ((8519, 8561), 'os.path.join', 'os.path.join', (['WORKING_DIRECTORY', '"""lancedb"""'], {}), "(WORKING_DIRECTORY, 'lancedb')\n", (8531, 8561), False, 'import os\n'), ((8596, 8625), 'lancedb.connect', 'lancedb.connect', (['lancedb_path'], {}), '(lancedb_path)\n', (8611, 8625), False, 'import lancedb\n'), ((8640, 8648), 'openai.OpenAI', 'OpenAI', ([], {}), '()\n', (8646, 8648), False, 'from openai import OpenAI\n'), ((9201, 9234), 'sqlite3.connect', 'sqlite3.connect', (['WORKING_DATABASE'], {}), '(WORKING_DATABASE)\n', (9216, 9234), False, 'import sqlite3\n'), ((11528, 11606), 'langchain.docstore.document.Document', 'Document', ([], {'page_content': "doc_dict['page_content']", 'metadata': "doc_dict['metadata']"}), "(page_content=doc_dict['page_content'], metadata=doc_dict['metadata'])\n", (11536, 11606), False, 'from langchain.docstore.document import Document\n'), ((11684, 11700), 'basecode.authenticate.return_api_key', 'return_api_key', ([], {}), '()\n', (11698, 11700), False, 'from basecode.authenticate import return_api_key\n'), ((11724, 11791), 'streamlit.subheader', 'st.subheader', (['"""Enter the topic and subject for your knowledge base"""'], {}), "('Enter the topic and subject for your knowledge base')\n", (11736, 11791), True, 'import streamlit as st\n'), ((11809, 11827), 'langchain.embeddings.openai.OpenAIEmbeddings', 'OpenAIEmbeddings', ([], {}), '()\n', (11825, 11827), False, 'from langchain.embeddings.openai import OpenAIEmbeddings\n'), ((12257, 12364), 'streamlit.selectbox', 'st.selectbox', (['"""Select an existing subject or type a new one:"""'], {'options': "(subject_names + ['New Subject'])"}), "('Select an existing subject or type a new one:', options=\n    subject_names + ['New Subject'])\n", (12269, 12364), True, 'import streamlit as st\n'), ((12845, 12946), 'streamlit.selectbox', 'st.selectbox', (['"""Select an existing topic or type a new one:"""'], {'options': "(topic_names + ['New Topic'])"}), "('Select an existing topic or type a new one:', options=\n    topic_names + ['New Topic'])\n", (12857, 12946), True, 'import streamlit as st\n'), ((13208, 13285), 'streamlit.text_input', 'st.text_input', (['"""Please type in a name for your knowledge base:"""'], {'max_chars': '(20)'}), "('Please type in a name for your knowledge base:', max_chars=20)\n", (13221, 13285), True, 'import streamlit as st\n'), ((13397, 13443), 'streamlit.checkbox', 'st.checkbox', (['"""Share this resource"""'], {'value': '(True)'}), "('Share this resource', value=True)\n", (13408, 13443), True, 'import streamlit as st\n'), ((13548, 13617), 'streamlit.subheader', 'st.subheader', (['"""Select one or more files to build your knowledge base"""'], {}), "('Select one or more files to build your knowledge base')\n", (13560, 13617), True, 'import streamlit as st\n'), ((15883, 15904), 'json.loads', 'json.loads', (['documents'], {}), '(documents)\n', (15893, 15904), False, 'import json\n'), ((16238, 16280), 'os.path.join', 'os.path.join', (['WORKING_DIRECTORY', '"""lancedb"""'], {}), "(WORKING_DIRECTORY, 'lancedb')\n", (16250, 16280), False, 'import os\n'), ((16315, 16344), 'lancedb.connect', 'lancedb.connect', (['lancedb_path'], {}), '(lancedb_path)\n', (16330, 16344), False, 'import lancedb\n'), ((16437, 16470), 'sqlite3.connect', 'sqlite3.connect', (['WORKING_DATABASE'], {}), '(WORKING_DATABASE)\n', (16452, 16470), False, 'import sqlite3\n'), ((16763, 16811), 'streamlit.subheader', 'st.subheader', (['"""Delete VectorStores in Database:"""'], {}), "('Delete VectorStores in Database:')\n", (16775, 16811), True, 'import streamlit as st\n'), ((17871, 17904), 'sqlite3.connect', 'sqlite3.connect', (['WORKING_DATABASE'], {}), '(WORKING_DATABASE)\n', (17886, 17904), False, 'import sqlite3\n'), ((621, 648), 'configparser.ConfigParser', 'configparser.ConfigParser', ([], {}), '()\n', (646, 648), False, 'import configparser\n'), ((1683, 1724), 'services.aws.SecretsManager.get_secret', 'SecretsManager.get_secret', (['"""sql_ext_path"""'], {}), "('sql_ext_path')\n", (1708, 1724), False, 'from services.aws import SecretsManager\n'), ((1895, 1936), 'services.aws.SecretsManager.get_secret', 'SecretsManager.get_secret', (['"""sql_ext_path"""'], {}), "('sql_ext_path')\n", (1920, 1936), False, 'from services.aws import SecretsManager\n'), ((2015, 2072), 'os.path.join', 'os.path.join', (['WORKING_DIRECTORY', "st.secrets['default_db']"], {}), "(WORKING_DIRECTORY, st.secrets['default_db'])\n", (2027, 2072), False, 'import os\n'), ((6366, 6399), 'sqlite3.connect', 'sqlite3.connect', (['WORKING_DATABASE'], {}), '(WORKING_DATABASE)\n', (6381, 6399), False, 'import sqlite3\n'), ((6725, 6775), 'streamlit.selectbox', 'st.selectbox', (['"""Select an organization:"""', 'org_names'], {}), "('Select an organization:', org_names)\n", (6737, 6775), True, 'import streamlit as st\n'), ((9445, 9479), 'streamlit.error', 'st.error', (['"""Error: User not found."""'], {}), "('Error: User not found.')\n", (9453, 9479), True, 'import streamlit as st\n'), ((12444, 12509), 'streamlit.text_input', 'st.text_input', (['"""Please enter the new subject name:"""'], {'max_chars': '(30)'}), "('Please enter the new subject name:', max_chars=30)\n", (12457, 12509), True, 'import streamlit as st\n'), ((13020, 13083), 'streamlit.text_input', 'st.text_input', (['"""Please enter the new topic name:"""'], {'max_chars': '(30)'}), "('Please enter the new topic name:', max_chars=30)\n", (13033, 13083), True, 'import streamlit as st\n'), ((13687, 13941), 'streamlit_antd_components.transfer', 'sac.transfer', ([], {'items': 'files', 'label': 'None', 'index': 'None', 'titles': "['Uploaded files', 'Select files for KB']", 'format_func': '"""title"""', 'width': '"""100%"""', 'height': 'None', 'search': '(True)', 'pagination': '(False)', 'oneway': '(False)', 'reload': '(True)', 'disabled': '(False)', 'return_index': '(False)'}), "(items=files, label=None, index=None, titles=['Uploaded files',\n    'Select files for KB'], format_func='title', width='100%', height=None,\n    search=True, pagination=False, oneway=False, reload=True, disabled=\n    False, return_index=False)\n", (13699, 13941), True, 'import streamlit_antd_components as sac\n'), ((14163, 14250), 'streamlit.warning', 'st.warning', (['"""Building your knowledge base will take some time. Please be patient."""'], {}), "(\n    'Building your knowledge base will take some time. Please be patient.')\n", (14173, 14250), True, 'import streamlit as st\n'), ((15765, 15808), 'streamlit.write', 'st.write', (['"""No files found in the database."""'], {}), "('No files found in the database.')\n", (15773, 15808), True, 'import streamlit as st\n'), ((17018, 17093), 'streamlit.multiselect', 'st.multiselect', (['"""Select vectorstores to delete:"""'], {'options': 'vectorstore_names'}), "('Select vectorstores to delete:', options=vectorstore_names)\n", (17032, 17093), True, 'import streamlit as st\n'), ((17141, 17216), 'streamlit.checkbox', 'st.checkbox', (['"""I understand that this action cannot be undone."""'], {'value': '(False)'}), "('I understand that this action cannot be undone.', value=False)\n", (17152, 17216), True, 'import streamlit as st\n'), ((17251, 17282), 'streamlit.button', 'st.button', (['"""Delete VectorStore"""'], {}), "('Delete VectorStore')\n", (17260, 17282), True, 'import streamlit as st\n'), ((17737, 17787), 'streamlit.write', 'st.write', (['"""No vectorstores found in the database."""'], {}), "('No vectorstores found in the database.')\n", (17745, 17787), True, 'import streamlit as st\n'), ((887, 910), 'ast.literal_eval', 'ast.literal_eval', (['value'], {}), '(value)\n', (903, 910), False, 'import ast\n'), ((1808, 1847), 'services.aws.SecretsManager.get_secret', 'SecretsManager.get_secret', (['"""default_db"""'], {}), "('default_db')\n", (1833, 1847), False, 'from services.aws import SecretsManager\n'), ((7058, 7118), 'streamlit.write', 'st.write', (['f"""The org_id for {selected_org_name} is {org_id}."""'], {}), "(f'The org_id for {selected_org_name} is {org_id}.')\n", (7066, 7118), True, 'import streamlit as st\n'), ((7171, 7245), 'streamlit.write', 'st.write', (['f"""Organization \'{selected_org_name}\' not found in the database."""'], {}), '(f"Organization \'{selected_org_name}\' not found in the database.")\n', (7179, 7245), True, 'import streamlit as st\n'), ((15332, 15359), 'json.dumps', 'json.dumps', (['full_docs_dicts'], {}), '(full_docs_dicts)\n', (15342, 15359), False, 'import json\n'), ((15710, 15745), 'streamlit.success', 'st.success', (['"""Knowledge Base loaded"""'], {}), "('Knowledge Base loaded')\n", (15720, 15745), True, 'import streamlit as st\n'), ((10002, 10098), 'streamlit.error', 'st.error', (['"""Error: An entry with the same vectorstore_name and user_id already exists."""'], {}), "(\n    'Error: An entry with the same vectorstore_name and user_id already exists.'\n    )\n", (10010, 10098), True, 'import streamlit as st\n'), ((10199, 10237), 'streamlit.error', 'st.error', (['"""Error: Subject is missing."""'], {}), "('Error: Subject is missing.')\n", (10207, 10237), True, 'import streamlit as st\n'), ((10308, 10344), 'streamlit.error', 'st.error', (['"""Error: Topic is missing."""'], {}), "('Error: Topic is missing.')\n", (10316, 10344), True, 'import streamlit as st\n'), ((11119, 11179), 'streamlit.error', 'st.error', (['f"""Error in storing documents and vectorstore: {e}"""'], {}), "(f'Error in storing documents and vectorstore: {e}')\n", (11127, 11179), True, 'import streamlit as st\n'), ((16089, 16105), 'basecode.authenticate.return_api_key', 'return_api_key', ([], {}), '()\n', (16103, 16105), False, 'from basecode.authenticate import return_api_key\n'), ((17669, 17718), 'streamlit.warning', 'st.warning', (['"""Please confirm the deletion action."""'], {}), "('Please confirm the deletion action.')\n", (17679, 17718), True, 'import streamlit as st\n'), ((18791, 18889), 'streamlit.error', 'st.error', (['f"""Unable to delete vectorstore \'{vectorstore_name}\' that is not owned by you."""'], {}), '(\n    f"Unable to delete vectorstore \'{vectorstore_name}\' that is not owned by you."\n    )\n', (18799, 18889), True, 'import streamlit as st\n')]