code: import os, sqlite3, lancedb, tiktoken, bcrypt
  from pinecone import Pinecone, ServerlessSpec
  from enum import Enum
  from langchain_community.vectorstores import LanceDB, Chroma
  from langchain_community.vectorstores import Pinecone as LangPinecone
  import streamlit as st
  
  def SetHeader(page_title: str):
      st.set_page_config(page_title=page_title, page_icon="https://indico.bnl.gov/event/19560/logo-410523303.png", layout="wide")
      st.warning("This project is being continuously developed. Please write to ai4eic@gmail.com for any feedback.")
      col_l, col1, col2, col_r = st.columns([1, 3, 3, 1])
      with col1:
          st.image("https://indico.bnl.gov/event/19560/logo-410523303.png")
      with col2:
          st.title("""AI4EIC - RAG QA-ChatBot""", anchor = "AI4EIC-RAG-QA-Bot", help = "Will Link to arxiv proceeding here.")
  
  class UserNotFoundError(Exception):
      pass
  
  class DBNotFoundError(Exception):
      pass
  def hash_password(password: str):
      bytes = password.encode('utf-8')
      salt = bcrypt.gensalt()
      return bcrypt.hashpw(bytes, salt)
  def get_user_info(db_name, username):
      if not os.path.exists(db_name):
          raise FileNotFoundError(f"Database {db_name} does not exist.")
      conn = sqlite3.connect(db_name)
      cursor = conn.cursor()
      cursor.execute('''
          SELECT username, first_name, last_name, password FROM users WHERE username = ?
      ''', (username,))
      user = cursor.fetchone()
      conn.close()
      if user:
          return user
      else:
          return None
  
  
  
  def SetOpenAIModel(model_name: str):
      if model_name == "4":
          return False
          
  class VectorDB(Enum):
      LANCE = 1
      CHROMA = 2
      PINECONE = 3
      
  
  def GetRetriever(TYPE: str, vector_config: dict, search_config = {}):
      if TYPE == VectorDB.LANCE.name:
          db = lancedb.connect(vector_config["db_name"])
          table = db.open_table(vector_config["table_name"])
          return LanceDB(connection = table, 
                         embedding = vector_config["embedding_function"]
                         ).as_retriever(search_type = search_config.get("metric", "similarity"), 
                                        search_kwargs=search_config.get("search_kwargs", {"k" : 100}) 
                                        )
      elif TYPE == VectorDB.CHROMA.name:
          return Chroma(persist_directory = vector_config["db_name"], 
                        embedding_function = vector_config["embedding_function"], 
                        collection_name=vector_config["collection_name"]
                        ).as_retriever(search_type = search_config.get("metric", "similarity"), 
                                       search_kwargs=search_config.get("search_kwargs", {"k" : 100})
                                       )
      elif TYPE == VectorDB.PINECONE.name:
          pc = Pinecone(api_key = vector_config["db_api_key"])
          if vector_config["index_name"] not in pc.list_indexes().names():
              raise DBNotFoundError(f"Database {vector_config['index_name']} does not exist.")
          return LangPinecone.from_existing_index(vector_config["index_name"], 
                                                      vector_config["embedding_function"]
                                                      ).as_retriever(search_type = search_config.get("metric", "similarity"), 
                                                                     search_kwargs=search_config.get("search_kwargs", {"k" : 100})
                                                                     )
      else:
          raise NotImplementedError("Invalid VectorDB type")
  
  def num_tokens_from_prompt(prompt: str, model: str) -> int:
          """Return the number of tokens used by a prompt."""
          encoding = tiktoken.encoding_for_model(model)
          return len(encoding.encode(prompt))
  def num_tokens_from_messages(messages, model) -> int:
          """Return the number of tokens used by a list of messages."""
          encoding = tiktoken.encoding_for_model(model)
          tokens_per_message = 4  # every message follows <|start|>{role/name}\n{content}<|end|>\n
          tokens_per_name = 1
          num_tokens = 0
          for message in messages:
              num_tokens += tokens_per_message
              for key, value in message.items():
                  num_tokens += len(encoding.encode(value))
                  if key == "name":
                      num_tokens += tokens_per_name
          num_tokens += 4  # every reply is primed with <|start|>assistant<|message|>
          return num_tokens
apis: lancedb.connect
extract_api: [((305, 433), 'streamlit.set_page_config', 'st.set_page_config', ([], {'page_title': 'page_title', 'page_icon': '"""https://indico.bnl.gov/event/19560/logo-410523303.png"""', 'layout': '"""wide"""'}), "(page_title=page_title, page_icon=\n    'https://indico.bnl.gov/event/19560/logo-410523303.png', layout='wide')\n", (323, 433), True, 'import streamlit as st\n'), ((433, 553), 'streamlit.warning', 'st.warning', (['"""This project is being continuously developed. Please write to ai4eic@gmail.com for any feedback."""'], {}), "(\n    'This project is being continuously developed. Please write to ai4eic@gmail.com for any feedback.'\n    )\n", (443, 553), True, 'import streamlit as st\n'), ((575, 599), 'streamlit.columns', 'st.columns', (['[1, 3, 3, 1]'], {}), '([1, 3, 3, 1])\n', (585, 599), True, 'import streamlit as st\n'), ((1000, 1016), 'bcrypt.gensalt', 'bcrypt.gensalt', ([], {}), '()\n', (1014, 1016), False, 'import os, sqlite3, lancedb, tiktoken, bcrypt\n'), ((1028, 1054), 'bcrypt.hashpw', 'bcrypt.hashpw', (['bytes', 'salt'], {}), '(bytes, salt)\n', (1041, 1054), False, 'import os, sqlite3, lancedb, tiktoken, bcrypt\n'), ((1211, 1235), 'sqlite3.connect', 'sqlite3.connect', (['db_name'], {}), '(db_name)\n', (1226, 1235), False, 'import os, sqlite3, lancedb, tiktoken, bcrypt\n'), ((3705, 3739), 'tiktoken.encoding_for_model', 'tiktoken.encoding_for_model', (['model'], {}), '(model)\n', (3732, 3739), False, 'import os, sqlite3, lancedb, tiktoken, bcrypt\n'), ((3927, 3961), 'tiktoken.encoding_for_model', 'tiktoken.encoding_for_model', (['model'], {}), '(model)\n', (3954, 3961), False, 'import os, sqlite3, lancedb, tiktoken, bcrypt\n'), ((623, 688), 'streamlit.image', 'st.image', (['"""https://indico.bnl.gov/event/19560/logo-410523303.png"""'], {}), "('https://indico.bnl.gov/event/19560/logo-410523303.png')\n", (631, 688), True, 'import streamlit as st\n'), ((712, 824), 'streamlit.title', 'st.title', (['"""AI4EIC - RAG QA-ChatBot"""'], {'anchor': '"""AI4EIC-RAG-QA-Bot"""', 'help': '"""Will Link to arxiv proceeding here."""'}), "('AI4EIC - RAG QA-ChatBot', anchor='AI4EIC-RAG-QA-Bot', help=\n    'Will Link to arxiv proceeding here.')\n", (720, 824), True, 'import streamlit as st\n'), ((1104, 1127), 'os.path.exists', 'os.path.exists', (['db_name'], {}), '(db_name)\n', (1118, 1127), False, 'import os, sqlite3, lancedb, tiktoken, bcrypt\n'), ((1793, 1834), 'lancedb.connect', 'lancedb.connect', (["vector_config['db_name']"], {}), "(vector_config['db_name'])\n", (1808, 1834), False, 'import os, sqlite3, lancedb, tiktoken, bcrypt\n'), ((1909, 1981), 'langchain_community.vectorstores.LanceDB', 'LanceDB', ([], {'connection': 'table', 'embedding': "vector_config['embedding_function']"}), "(connection=table, embedding=vector_config['embedding_function'])\n", (1916, 1981), False, 'from langchain_community.vectorstores import LanceDB, Chroma\n'), ((2793, 2838), 'pinecone.Pinecone', 'Pinecone', ([], {'api_key': "vector_config['db_api_key']"}), "(api_key=vector_config['db_api_key'])\n", (2801, 2838), False, 'from pinecone import Pinecone, ServerlessSpec\n'), ((2300, 2466), 'langchain_community.vectorstores.Chroma', 'Chroma', ([], {'persist_directory': "vector_config['db_name']", 'embedding_function': "vector_config['embedding_function']", 'collection_name': "vector_config['collection_name']"}), "(persist_directory=vector_config['db_name'], embedding_function=\n    vector_config['embedding_function'], collection_name=vector_config[\n    'collection_name'])\n", (2306, 2466), False, 'from langchain_community.vectorstores import LanceDB, Chroma\n'), ((3022, 3125), 'langchain_community.vectorstores.Pinecone.from_existing_index', 'LangPinecone.from_existing_index', (["vector_config['index_name']", "vector_config['embedding_function']"], {}), "(vector_config['index_name'], vector_config\n    ['embedding_function'])\n", (3054, 3125), True, 'from langchain_community.vectorstores import Pinecone as LangPinecone\n')]