code: """
  Chatbot for talking to Github Codespaces using Langchain, Qwen and LanceDB
  """
  
  import os
  import shutil
  import lancedb
  
  from langchain.memory import ConversationSummaryMemory
  from langchain_community.document_loaders import GitLoader
  from langchain.vectorstores import LanceDB
  from langchain.embeddings import HuggingFaceEmbeddings
  from langchain.text_splitter import CharacterTextSplitter
  from langchain.chat_models import ChatOllama
  from langchain.chains import ConversationalRetrievalChain
  
  
  def lanceDBConnection(embed):
      db = lancedb.connect("/tmp/lancedb")
      table = db.create_table(
          "github_repo",
          data=[{"vector": embed.embed_query("Hello World"), "text": "Hello World"}],
          mode="overwrite",
      )
  
      return table
  
  
  def vectorStoreSetup(query_path):
      temp_repo_dir = "./example_data/test_repo1/"
      if os.path.exists(temp_repo_dir):
          shutil.rmtree(temp_repo_dir)
      docs = GitLoader(
          clone_url=query_path,
          repo_path=temp_repo_dir,
          file_filter=lambda file_path: file_path.endswith(".py")
          or file_path.endswith(".md")
          or file_path.endswith(".js"),
      )
      docs = docs.load()
  
      # chunking
      text_splitter = CharacterTextSplitter(chunk_size=100, chunk_overlap=0)
      all_splits = text_splitter.split_documents(docs)
  
      # Huggingface embeddings
      embed = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
  
      # LanceDB as vector store
      table = lanceDBConnection(embed)
      vectorstore = LanceDB.from_documents(
          documents=all_splits,
          embedding=HuggingFaceEmbeddings(
              model_name="sentence-transformers/all-MiniLM-L6-v2"
          ),
          connection=table,
      )
  
      return vectorstore
  
  
  def retrieverSetup(text):
      vectorstore = vectorStoreSetup(text)
      # define ChatOllama: using Qwen model for LLM
      llm = ChatOllama(model="qwen")
      memory = ConversationSummaryMemory(
          llm=llm, memory_key="chat_history", return_messages=True
      )
      retriever = vectorstore.as_retriever()
  
      # define Retrieval Chain for retriver
      qa = ConversationalRetrievalChain.from_llm(llm, retriever=retriever, memory=memory)
      return qa
  
  
  def chat(qa, question):
      # chat query
      r = qa.run({"question": question})
      return r
  
apis: lancedb.connect
extract_api: [((538, 569), 'lancedb.connect', 'lancedb.connect', (['"""/tmp/lancedb"""'], {}), "('/tmp/lancedb')\n", (553, 569), False, 'import lancedb\n'), ((848, 877), 'os.path.exists', 'os.path.exists', (['temp_repo_dir'], {}), '(temp_repo_dir)\n', (862, 877), False, 'import os\n'), ((1205, 1259), 'langchain.text_splitter.CharacterTextSplitter', 'CharacterTextSplitter', ([], {'chunk_size': '(100)', 'chunk_overlap': '(0)'}), '(chunk_size=100, chunk_overlap=0)\n', (1226, 1259), False, 'from langchain.text_splitter import CharacterTextSplitter\n'), ((1355, 1429), 'langchain.embeddings.HuggingFaceEmbeddings', 'HuggingFaceEmbeddings', ([], {'model_name': '"""sentence-transformers/all-MiniLM-L6-v2"""'}), "(model_name='sentence-transformers/all-MiniLM-L6-v2')\n", (1376, 1429), False, 'from langchain.embeddings import HuggingFaceEmbeddings\n'), ((1871, 1895), 'langchain.chat_models.ChatOllama', 'ChatOllama', ([], {'model': '"""qwen"""'}), "(model='qwen')\n", (1881, 1895), False, 'from langchain.chat_models import ChatOllama\n'), ((1909, 1996), 'langchain.memory.ConversationSummaryMemory', 'ConversationSummaryMemory', ([], {'llm': 'llm', 'memory_key': '"""chat_history"""', 'return_messages': '(True)'}), "(llm=llm, memory_key='chat_history',\n    return_messages=True)\n", (1934, 1996), False, 'from langchain.memory import ConversationSummaryMemory\n'), ((2102, 2180), 'langchain.chains.ConversationalRetrievalChain.from_llm', 'ConversationalRetrievalChain.from_llm', (['llm'], {'retriever': 'retriever', 'memory': 'memory'}), '(llm, retriever=retriever, memory=memory)\n', (2139, 2180), False, 'from langchain.chains import ConversationalRetrievalChain\n'), ((887, 915), 'shutil.rmtree', 'shutil.rmtree', (['temp_repo_dir'], {}), '(temp_repo_dir)\n', (900, 915), False, 'import shutil\n'), ((1588, 1662), 'langchain.embeddings.HuggingFaceEmbeddings', 'HuggingFaceEmbeddings', ([], {'model_name': '"""sentence-transformers/all-MiniLM-L6-v2"""'}), "(model_name='sentence-transformers/all-MiniLM-L6-v2')\n", (1609, 1662), False, 'from langchain.embeddings import HuggingFaceEmbeddings\n')]