code: import gradio as gr
  from dotenv import load_dotenv
  from prompts import context
  #from note_engine import note_engine
  import llama_index
  from llama_index.core.tools import QueryEngineTool, ToolMetadata
  from llama_index.core.agent import ReActAgent
  from llama_index.llms.openai import OpenAI
  from llama_index.core import (
      SimpleDirectoryReader,
      VectorStoreIndex,
      Settings,
      StorageContext,
      load_index_from_storage,
  )
  from pymilvus import connections
  from llama_index.vector_stores.milvus import MilvusVectorStore
  from llama_index.embeddings.huggingface import HuggingFaceEmbedding
  
  embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
  Settings.embed_model = embed_model
  
  load_dotenv()
  
  import logging
  import sys
  
  logging.basicConfig(stream=sys.stderr)
  llama_index.core.set_global_handler("simple")
  
  try:
      vector_store_books = MilvusVectorStore(dim=384, collection_name="books")
      storage_context = StorageContext.from_defaults(
          persist_dir="./storage/books",
          vector_store=vector_store_books,
      )
      books_index = load_index_from_storage(storage_context)
  except Exception as error:
      print(f'Unable to load index from storage: {error}')
      print('Indexing book dataset')
      vector_store_books = MilvusVectorStore(dim=384, collection_name="books", overwrite=True)
      book_docs = SimpleDirectoryReader(input_dir="./data").load_data()
      storage_context = StorageContext.from_defaults(
          vector_store=vector_store_books,
      )
      books_index = VectorStoreIndex.from_documents(book_docs, storage_context=storage_context)
      books_index.storage_context.persist(persist_dir="./storage/books")
  
  books_query_engine = books_index.as_query_engine(similarity_top_k=3)
  
  tools = [
      QueryEngineTool(
          query_engine=books_query_engine,
          metadata=ToolMetadata(
              name="books_data",
              description="Provides information about known books; ONLY books known to this tool should be considered when answering questions about books",
          ),
      ),
  ]
  
  # # This is the main agent
  llm = OpenAI(model="gpt-3.5-turbo-0613")
  agent = ReActAgent.from_tools(tools, llm=llm, verbose=True, context=context)
  
  
  # UI for demo
  def chat_interface(prompt):
      # Send the prompt to the agent and get the response
      response = agent.query(prompt)
      print(response)
      return response
  
  iface = gr.Interface(fn=chat_interface, 
                       inputs="text", 
                       outputs="text",
                       allow_flagging="never")
  
  iface.launch(share=True)
  
apis: llama_index.core.StorageContext.from_defaults llama_index.core.agent.ReActAgent.from_tools llama_index.embeddings.huggingface.HuggingFaceEmbedding llama_index.core.set_global_handler llama_index.vector_stores.milvus.MilvusVectorStore llama_index.core.VectorStoreIndex.from_documents llama_index.core.SimpleDirectoryReader llama_index.llms.openai.OpenAI llama_index.core.tools.ToolMetadata llama_index.core.load_index_from_storage
extract_api: [((613, 670), 'llama_index.embeddings.huggingface.HuggingFaceEmbedding', 'HuggingFaceEmbedding', ([], {'model_name': '"""BAAI/bge-small-en-v1.5"""'}), "(model_name='BAAI/bge-small-en-v1.5')\n", (633, 670), False, 'from llama_index.embeddings.huggingface import HuggingFaceEmbedding\n'), ((707, 720), 'dotenv.load_dotenv', 'load_dotenv', ([], {}), '()\n', (718, 720), False, 'from dotenv import load_dotenv\n'), ((749, 787), 'logging.basicConfig', 'logging.basicConfig', ([], {'stream': 'sys.stderr'}), '(stream=sys.stderr)\n', (768, 787), False, 'import logging\n'), ((788, 833), 'llama_index.core.set_global_handler', 'llama_index.core.set_global_handler', (['"""simple"""'], {}), "('simple')\n", (823, 833), False, 'import llama_index\n'), ((2074, 2108), 'llama_index.llms.openai.OpenAI', 'OpenAI', ([], {'model': '"""gpt-3.5-turbo-0613"""'}), "(model='gpt-3.5-turbo-0613')\n", (2080, 2108), False, 'from llama_index.llms.openai import OpenAI\n'), ((2117, 2185), 'llama_index.core.agent.ReActAgent.from_tools', 'ReActAgent.from_tools', (['tools'], {'llm': 'llm', 'verbose': '(True)', 'context': 'context'}), '(tools, llm=llm, verbose=True, context=context)\n', (2138, 2185), False, 'from llama_index.core.agent import ReActAgent\n'), ((2370, 2460), 'gradio.Interface', 'gr.Interface', ([], {'fn': 'chat_interface', 'inputs': '"""text"""', 'outputs': '"""text"""', 'allow_flagging': '"""never"""'}), "(fn=chat_interface, inputs='text', outputs='text',\n    allow_flagging='never')\n", (2382, 2460), True, 'import gradio as gr\n'), ((865, 916), 'llama_index.vector_stores.milvus.MilvusVectorStore', 'MilvusVectorStore', ([], {'dim': '(384)', 'collection_name': '"""books"""'}), "(dim=384, collection_name='books')\n", (882, 916), False, 'from llama_index.vector_stores.milvus import MilvusVectorStore\n'), ((939, 1036), 'llama_index.core.StorageContext.from_defaults', 'StorageContext.from_defaults', ([], {'persist_dir': '"""./storage/books"""', 'vector_store': 'vector_store_books'}), "(persist_dir='./storage/books', vector_store=\n    vector_store_books)\n", (967, 1036), False, 'from llama_index.core import SimpleDirectoryReader, VectorStoreIndex, Settings, StorageContext, load_index_from_storage\n'), ((1073, 1113), 'llama_index.core.load_index_from_storage', 'load_index_from_storage', (['storage_context'], {}), '(storage_context)\n', (1096, 1113), False, 'from llama_index.core import SimpleDirectoryReader, VectorStoreIndex, Settings, StorageContext, load_index_from_storage\n'), ((1258, 1325), 'llama_index.vector_stores.milvus.MilvusVectorStore', 'MilvusVectorStore', ([], {'dim': '(384)', 'collection_name': '"""books"""', 'overwrite': '(True)'}), "(dim=384, collection_name='books', overwrite=True)\n", (1275, 1325), False, 'from llama_index.vector_stores.milvus import MilvusVectorStore\n'), ((1418, 1479), 'llama_index.core.StorageContext.from_defaults', 'StorageContext.from_defaults', ([], {'vector_store': 'vector_store_books'}), '(vector_store=vector_store_books)\n', (1446, 1479), False, 'from llama_index.core import SimpleDirectoryReader, VectorStoreIndex, Settings, StorageContext, load_index_from_storage\n'), ((1513, 1588), 'llama_index.core.VectorStoreIndex.from_documents', 'VectorStoreIndex.from_documents', (['book_docs'], {'storage_context': 'storage_context'}), '(book_docs, storage_context=storage_context)\n', (1544, 1588), False, 'from llama_index.core import SimpleDirectoryReader, VectorStoreIndex, Settings, StorageContext, load_index_from_storage\n'), ((1820, 2004), 'llama_index.core.tools.ToolMetadata', 'ToolMetadata', ([], {'name': '"""books_data"""', 'description': '"""Provides information about known books; ONLY books known to this tool should be considered when answering questions about books"""'}), "(name='books_data', description=\n    'Provides information about known books; ONLY books known to this tool should be considered when answering questions about books'\n    )\n", (1832, 2004), False, 'from llama_index.core.tools import QueryEngineTool, ToolMetadata\n'), ((1342, 1383), 'llama_index.core.SimpleDirectoryReader', 'SimpleDirectoryReader', ([], {'input_dir': '"""./data"""'}), "(input_dir='./data')\n", (1363, 1383), False, 'from llama_index.core import SimpleDirectoryReader, VectorStoreIndex, Settings, StorageContext, load_index_from_storage\n')]