index.py 703 B

123456789101112131415161718192021222324
  1. import os
  2. from langchain.tools import BaseTool
  3. class QAIndexedDocuments(BaseTool):
  4. name = "Question Answering Tool for Indexed Documents"
  5. description = (
  6. "use this tool when asked to search and find answers in documents. "
  7. "If explicitly asked to search in indexed documents, this tool will search in the indexed documents. "
  8. "To use the tool you must provide exactly one parameters as follows "
  9. "['question']"
  10. )
  11. return_direct = True
  12. def _run(
  13. self,
  14. question: str,
  15. ):
  16. return index.query_with_sources(question)
  17. def _arun(self, query: str):
  18. raise NotImplementedError("This tool does not support async")