code: import openai
  import os
  import lancedb
  import pickle
  import requests
  from pathlib import Path
  from bs4 import BeautifulSoup
  import re
  
  from langchain.document_loaders import UnstructuredHTMLLoader
  from langchain.embeddings import OpenAIEmbeddings
  from langchain.text_splitter import RecursiveCharacterTextSplitter
  from langchain.vectorstores import LanceDB
  from langchain.llms import OpenAI
  from langchain.chains import RetrievalQA
  
  # Function to fetch and save a page as an HTML file
  def save_page(url, save_dir):
      response = requests.get(url)
      if response.status_code == 200:
          soup = BeautifulSoup(response.content, 'html.parser')
          title = soup.find('title').text
          filename = f"{title}.html"
          with open(os.path.join(save_dir, filename), 'w', encoding='utf-8') as file:
                  file.write(str(soup))
  
  def get_document_title(document):
      m = str(document.metadata["source"])
      title = re.findall("(.*)\.html", m)
      print("PRINTING TITLES")
      print(title)
  
      if title[0] is not None:
          return(title[0])
      return ''
  
  # if "OPENAI_API_KEY" not in os.environ:
  openai.api_key = "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"
  
  assert len(openai.Model.list()["data"]) > 0
  print("fetching data")
  
  # Base URL of Wikivoyage
  base_url = "https://en.wikivoyage.org/wiki/"
  
  # List of page titles to download
  page_titles = ["London", "Paris", "New_York_City"]  # Add more as needed
  
  # Directory to save the HTML files
  save_directory = "./wikivoyage_pages"
  
  # Create the save directory if it doesn't exist
  if not os.path.exists(save_directory):
      os.makedirs(save_directory)
  
  # Loop through the page titles and download the pages
  for title in page_titles:
      url = f"{base_url}{title}"
      save_page(url, save_directory)
  
  docs_path = Path("cities.pkl")
  docs = []
  
  if not docs_path.exists():
      for p in Path("./wikivoyage_pages").rglob("*.html"):
          if p.is_dir():
              continue
          loader = UnstructuredHTMLLoader(p)
          raw_document = loader.load()
          
          m = {}
          m["title"] = get_document_title(raw_document[0])
          raw_document[0].metadata = raw_document[0].metadata | m
          raw_document[0].metadata["source"] = str(raw_document[0].metadata["source"])
          docs = docs + raw_document
  
      with docs_path.open("wb") as fh:
          pickle.dump(docs, fh)
  else:
      with docs_path.open("rb") as fh:
          docs = pickle.load(fh)
  
  #split text
  text_splitter = RecursiveCharacterTextSplitter(
      chunk_size=500,
      chunk_overlap=50,
  )
  
  documents = text_splitter.split_documents(docs)
  
  embeddings = OpenAIEmbeddings(openai_api_key="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")
  
  db = lancedb.connect('/tmp/lancedb')
  table = db.create_table("city_docs", data=[
      {"vector": embeddings.embed_query("Hello World"), "text": "Hello World"}
  ], mode="overwrite")
  
  print("generated embeddings!")
  
  docsearch = LanceDB.from_documents(documents[5:], embeddings, connection=table)
  qa = RetrievalQA.from_chain_type(llm=OpenAI(openai_api_key="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"), chain_type="stuff", retriever=docsearch.as_retriever())
  
  query_file = open('query.pkl', 'wb')
  pickle.dump(qa, query_file)
  query_file.close()
  
  print("returning query object")
apis: lancedb.connect
extract_api: [((1848, 1866), 'pathlib.Path', 'Path', (['"""cities.pkl"""'], {}), "('cities.pkl')\n", (1852, 1866), False, 'from pathlib import Path\n'), ((2545, 2609), 'langchain.text_splitter.RecursiveCharacterTextSplitter', 'RecursiveCharacterTextSplitter', ([], {'chunk_size': '(500)', 'chunk_overlap': '(50)'}), '(chunk_size=500, chunk_overlap=50)\n', (2575, 2609), False, 'from langchain.text_splitter import RecursiveCharacterTextSplitter\n'), ((2691, 2782), 'langchain.embeddings.OpenAIEmbeddings', 'OpenAIEmbeddings', ([], {'openai_api_key': '"""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"""'}), "(openai_api_key=\n    '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')\n", (2707, 2782), False, 'from langchain.embeddings import OpenAIEmbeddings\n'), ((2786, 2817), 'lancedb.connect', 'lancedb.connect', (['"""/tmp/lancedb"""'], {}), "('/tmp/lancedb')\n", (2801, 2817), False, 'import lancedb\n'), ((3012, 3079), 'langchain.vectorstores.LanceDB.from_documents', 'LanceDB.from_documents', (['documents[5:]', 'embeddings'], {'connection': 'table'}), '(documents[5:], embeddings, connection=table)\n', (3034, 3079), False, 'from langchain.vectorstores import LanceDB\n'), ((3293, 3320), 'pickle.dump', 'pickle.dump', (['qa', 'query_file'], {}), '(qa, query_file)\n', (3304, 3320), False, 'import pickle\n'), ((548, 565), 'requests.get', 'requests.get', (['url'], {}), '(url)\n', (560, 565), False, 'import requests\n'), ((959, 987), 're.findall', 're.findall', (['"""(.*)\\\\.html"""', 'm'], {}), "('(.*)\\\\.html', m)\n", (969, 987), False, 'import re\n'), ((1616, 1646), 'os.path.exists', 'os.path.exists', (['save_directory'], {}), '(save_directory)\n', (1630, 1646), False, 'import os\n'), ((1653, 1680), 'os.makedirs', 'os.makedirs', (['save_directory'], {}), '(save_directory)\n', (1664, 1680), False, 'import os\n'), ((619, 665), 'bs4.BeautifulSoup', 'BeautifulSoup', (['response.content', '"""html.parser"""'], {}), "(response.content, 'html.parser')\n", (632, 665), False, 'from bs4 import BeautifulSoup\n'), ((2030, 2055), 'langchain.document_loaders.UnstructuredHTMLLoader', 'UnstructuredHTMLLoader', (['p'], {}), '(p)\n', (2052, 2055), False, 'from langchain.document_loaders import UnstructuredHTMLLoader\n'), ((2414, 2435), 'pickle.dump', 'pickle.dump', (['docs', 'fh'], {}), '(docs, fh)\n', (2425, 2435), False, 'import pickle\n'), ((2497, 2512), 'pickle.load', 'pickle.load', (['fh'], {}), '(fh)\n', (2508, 2512), False, 'import pickle\n'), ((3118, 3194), 'langchain.llms.OpenAI', 'OpenAI', ([], {'openai_api_key': '"""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"""'}), "(openai_api_key='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')\n", (3124, 3194), False, 'from langchain.llms import OpenAI\n'), ((1238, 1257), 'openai.Model.list', 'openai.Model.list', ([], {}), '()\n', (1255, 1257), False, 'import openai\n'), ((1922, 1948), 'pathlib.Path', 'Path', (['"""./wikivoyage_pages"""'], {}), "('./wikivoyage_pages')\n", (1926, 1948), False, 'from pathlib import Path\n'), ((762, 794), 'os.path.join', 'os.path.join', (['save_dir', 'filename'], {}), '(save_dir, filename)\n', (774, 794), False, 'import os\n')]