code: # https://github.com/jerryjliu/llama_index/blob/main/examples/langchain_demo/LangchainDemo.ipynb
  
  # Using LlamaIndex as a Callable Tool
  
  from langchain.agents import Tool
  from langchain.chains.conversation.memory import ConversationBufferMemory
  from langchain.chat_models import ChatOpenAI
  from langchain.agents import initialize_agent
  from langchain import HuggingFaceHub
  from llama_index import LangchainEmbedding, ServiceContext
  
  from langchain.embeddings.huggingface import HuggingFaceEmbeddings
  from llama_index.tools import QueryEngineTool, ToolMetadata
  from llama_index import VectorStoreIndex, SimpleDirectoryReader, LLMPredictor, ServiceContext
  from llama_index.query_engine import SubQuestionQueryEngine
  
  documents = SimpleDirectoryReader('data/experiment').load_data()
  repo_id = "tiiuae/falcon-7b"
  embed_model = LangchainEmbedding(HuggingFaceEmbeddings())
  
  llm = HuggingFaceHub(repo_id=repo_id, model_kwargs={"temperature": 0.1, 'truncation': 'only_first',
                                                      "max_length": 1024})
  llm_predictor = LLMPredictor(llm=llm)
  service_context = ServiceContext.from_defaults(chunk_size=512, llm_predictor=llm_predictor, embed_model=embed_model)
  
  index = VectorStoreIndex.from_documents(documents=documents, service_context=service_context)
  engine = index.as_query_engine(similarity_top_k=3)
  
  query_engine_tools = [
      QueryEngineTool(
          query_engine=engine,
          metadata=ToolMetadata(name='Paulindex', description='Provides information about Paul Graham Essay')
      )
  ]
  
  s_engine = SubQuestionQueryEngine.from_defaults(query_engine_tools=query_engine_tools)
  response = s_engine.query('Explain childhood')
  print(response)
  
  ### As a chat bot
  
  # tools = [
  #     Tool(
  #         name="LlamaIndex",
  #         func=lambda q: str(index.as_query_engine().query(q)),
  #         description="useful for when you want to answer questions about the author. The input to this tool should be a complete english sentence.",
  #         return_direct=True
  #     ),
  # ]
  
  # memory = ConversationBufferMemory(memory_key="chat_history")
  # # llm = ChatOpenAI(temperature=0)
  # agent_executor = initialize_agent(tools, llm, agent="conversational-react-description", memory=memory)
  #
  # agent_executor.run(input="hi, i am bob")
  
apis: llama_index.VectorStoreIndex.from_documents llama_index.tools.ToolMetadata llama_index.query_engine.SubQuestionQueryEngine.from_defaults llama_index.LLMPredictor llama_index.ServiceContext.from_defaults llama_index.SimpleDirectoryReader
extract_api: [((874, 992), 'langchain.HuggingFaceHub', 'HuggingFaceHub', ([], {'repo_id': 'repo_id', 'model_kwargs': "{'temperature': 0.1, 'truncation': 'only_first', 'max_length': 1024}"}), "(repo_id=repo_id, model_kwargs={'temperature': 0.1,\n    'truncation': 'only_first', 'max_length': 1024})\n", (888, 992), False, 'from langchain import HuggingFaceHub\n'), ((1057, 1078), 'llama_index.LLMPredictor', 'LLMPredictor', ([], {'llm': 'llm'}), '(llm=llm)\n', (1069, 1078), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader, LLMPredictor, ServiceContext\n'), ((1097, 1199), 'llama_index.ServiceContext.from_defaults', 'ServiceContext.from_defaults', ([], {'chunk_size': '(512)', 'llm_predictor': 'llm_predictor', 'embed_model': 'embed_model'}), '(chunk_size=512, llm_predictor=llm_predictor,\n    embed_model=embed_model)\n', (1125, 1199), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader, LLMPredictor, ServiceContext\n'), ((1205, 1295), 'llama_index.VectorStoreIndex.from_documents', 'VectorStoreIndex.from_documents', ([], {'documents': 'documents', 'service_context': 'service_context'}), '(documents=documents, service_context=\n    service_context)\n', (1236, 1295), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader, LLMPredictor, ServiceContext\n'), ((1544, 1619), 'llama_index.query_engine.SubQuestionQueryEngine.from_defaults', 'SubQuestionQueryEngine.from_defaults', ([], {'query_engine_tools': 'query_engine_tools'}), '(query_engine_tools=query_engine_tools)\n', (1580, 1619), False, 'from llama_index.query_engine import SubQuestionQueryEngine\n'), ((842, 865), 'langchain.embeddings.huggingface.HuggingFaceEmbeddings', 'HuggingFaceEmbeddings', ([], {}), '()\n', (863, 865), False, 'from langchain.embeddings.huggingface import HuggingFaceEmbeddings\n'), ((727, 767), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', (['"""data/experiment"""'], {}), "('data/experiment')\n", (748, 767), False, 'from llama_index import VectorStoreIndex, SimpleDirectoryReader, LLMPredictor, ServiceContext\n'), ((1433, 1528), 'llama_index.tools.ToolMetadata', 'ToolMetadata', ([], {'name': '"""Paulindex"""', 'description': '"""Provides information about Paul Graham Essay"""'}), "(name='Paulindex', description=\n    'Provides information about Paul Graham Essay')\n", (1445, 1528), False, 'from llama_index.tools import QueryEngineTool, ToolMetadata\n')]