code: import logging
  import os
  from typing import Optional
  from typing import Type
  
  import openai
  from langchain.chat_models import ChatOpenAI
  from llama_index import VectorStoreIndex, LLMPredictor, ServiceContext
  from llama_index.vector_stores.types import ExactMatchFilter, MetadataFilters
  from pydantic import BaseModel, Field
  
  from superagi.config.config import get_config
  from superagi.llms.base_llm import BaseLlm
  from superagi.resource_manager.llama_vector_store_factory import LlamaVectorStoreFactory
  from superagi.tools.base_tool import BaseTool
  from superagi.types.vector_store_types import VectorStoreType
  from superagi.vector_store.chromadb import ChromaDB
  
  
  class QueryResource(BaseModel):
      """Input for QueryResource tool."""
      query: str = Field(..., description="the search query to search resources")
  
  
  class QueryResourceTool(BaseTool):
      """
      Read File tool
  
      Attributes:
          name : The name.
          description : The description.
          args_schema : The args schema.
      """
      name: str = "QueryResource"
      args_schema: Type[BaseModel] = QueryResource
      description: str = "Tool searches resources content and extracts relevant information to perform the given task." \
                         "Tool is given preference over other search/read file tools for relevant data." \
                         "Resources content is taken from the files: {summary}"
      agent_id: int = None
      llm: Optional[BaseLlm] = None
  
      def _execute(self, query: str):
          openai.api_key = self.llm.get_api_key()
          os.environ["OPENAI_API_KEY"] = self.llm.get_api_key()
          llm_predictor_chatgpt = LLMPredictor(llm=ChatOpenAI(temperature=0, model_name=self.llm.get_model(),
                                                              openai_api_key=get_config("OPENAI_API_KEY")))
  
          service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor_chatgpt)
          vector_store_name = VectorStoreType.get_vector_store_type(
              self.get_tool_config(key="RESOURCE_VECTOR_STORE") or "Redis")
          vector_store_index_name = self.get_tool_config(key="RESOURCE_VECTOR_STORE_INDEX_NAME") or "super-agent-index"
          logging.info(f"vector_store_name {vector_store_name}")
          logging.info(f"vector_store_index_name {vector_store_index_name}")
          vector_store = LlamaVectorStoreFactory(vector_store_name, vector_store_index_name).get_vector_store()
          logging.info(f"vector_store {vector_store}")
          as_query_engine_args = dict(
              filters=MetadataFilters(
                  filters=[
                      ExactMatchFilter(
                          key="agent_id",
                          value=str(self.agent_id)
                      )
                  ]
              )
          )
          if vector_store_name == VectorStoreType.CHROMA:
              as_query_engine_args["chroma_collection"] = ChromaDB.create_collection(
                  collection_name=vector_store_index_name)
          index = VectorStoreIndex.from_vector_store(vector_store=vector_store, service_context=service_context)
          query_engine = index.as_query_engine(
              **as_query_engine_args
          )
          try:
              response = query_engine.query(query)
          except ValueError as e:
              logging.error(f"ValueError {e}")
              response = "Document not found"
          return response
  
apis: llama_index.VectorStoreIndex.from_vector_store llama_index.ServiceContext.from_defaults
extract_api: [((754, 816), 'pydantic.Field', 'Field', (['...'], {'description': '"""the search query to search resources"""'}), "(..., description='the search query to search resources')\n", (759, 816), False, 'from pydantic import BaseModel, Field\n'), ((1840, 1905), 'llama_index.ServiceContext.from_defaults', 'ServiceContext.from_defaults', ([], {'llm_predictor': 'llm_predictor_chatgpt'}), '(llm_predictor=llm_predictor_chatgpt)\n', (1868, 1905), False, 'from llama_index import VectorStoreIndex, LLMPredictor, ServiceContext\n'), ((2173, 2227), 'logging.info', 'logging.info', (['f"""vector_store_name {vector_store_name}"""'], {}), "(f'vector_store_name {vector_store_name}')\n", (2185, 2227), False, 'import logging\n'), ((2236, 2302), 'logging.info', 'logging.info', (['f"""vector_store_index_name {vector_store_index_name}"""'], {}), "(f'vector_store_index_name {vector_store_index_name}')\n", (2248, 2302), False, 'import logging\n'), ((2421, 2465), 'logging.info', 'logging.info', (['f"""vector_store {vector_store}"""'], {}), "(f'vector_store {vector_store}')\n", (2433, 2465), False, 'import logging\n'), ((2970, 3068), 'llama_index.VectorStoreIndex.from_vector_store', 'VectorStoreIndex.from_vector_store', ([], {'vector_store': 'vector_store', 'service_context': 'service_context'}), '(vector_store=vector_store,\n    service_context=service_context)\n', (3004, 3068), False, 'from llama_index import VectorStoreIndex, LLMPredictor, ServiceContext\n'), ((2869, 2936), 'superagi.vector_store.chromadb.ChromaDB.create_collection', 'ChromaDB.create_collection', ([], {'collection_name': 'vector_store_index_name'}), '(collection_name=vector_store_index_name)\n', (2895, 2936), False, 'from superagi.vector_store.chromadb import ChromaDB\n'), ((2326, 2393), 'superagi.resource_manager.llama_vector_store_factory.LlamaVectorStoreFactory', 'LlamaVectorStoreFactory', (['vector_store_name', 'vector_store_index_name'], {}), '(vector_store_name, vector_store_index_name)\n', (2349, 2393), False, 'from superagi.resource_manager.llama_vector_store_factory import LlamaVectorStoreFactory\n'), ((3262, 3294), 'logging.error', 'logging.error', (['f"""ValueError {e}"""'], {}), "(f'ValueError {e}')\n", (3275, 3294), False, 'import logging\n'), ((1782, 1810), 'superagi.config.config.get_config', 'get_config', (['"""OPENAI_API_KEY"""'], {}), "('OPENAI_API_KEY')\n", (1792, 1810), False, 'from superagi.config.config import get_config\n')]